Skip to content

Commit

Permalink
Custom namespace when they're unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Aug 7, 2017
1 parent 904b7f8 commit 51bc82c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Objects;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import net.sourceforge.pmd.lang.ast.QualifiedName;

import apex.jorje.semantic.symbol.type.TypeInfo;
Expand Down Expand Up @@ -123,7 +125,7 @@ public static ApexQualifiedName ofString(String toParse) {
static ApexQualifiedName ofOuterClass(ASTUserClassOrInterface astUserClass) {
String ns = astUserClass.getNode().getDefiningType().getNamespace().toString();
String[] classes = {astUserClass.getImage()};
return new ApexQualifiedName(ns, classes, null);
return new ApexQualifiedName(StringUtils.isEmpty(ns) ? "c" : ns, classes, null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void testClass() {
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo {}");

ApexQualifiedName qname = ASTUserClass.class.cast(root).getQualifiedName();
assertEquals("__Foo", qname.toString());
assertEquals("c__Foo", qname.toString());
assertEquals(1, qname.getClasses().length);
assertNotNull(qname.getNameSpace());
assertNull(qname.getOperation());
Expand All @@ -37,7 +37,7 @@ public void testNestedClass() {
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { class Bar {}}");

ApexQualifiedName qname = root.getFirstDescendantOfType(ASTUserClass.class).getQualifiedName();
assertEquals("__Foo.Bar", qname.toString());
assertEquals("c__Foo.Bar", qname.toString());
assertEquals(2, qname.getClasses().length);
assertNotNull(qname.getNameSpace());
assertNull(qname.getOperation());
Expand All @@ -48,7 +48,7 @@ public void testNestedClass() {
public void testSimpleMethod() {
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { String foo() {}}");
ApexQualifiedName qname = root.getFirstDescendantOfType(ASTMethod.class).getQualifiedName();
assertEquals("__Foo#foo()", qname.toString());
assertEquals("c__Foo#foo()", qname.toString());
assertEquals(1, qname.getClasses().length);
assertNotNull(qname.getNameSpace());
assertEquals("foo()", qname.getOperation());
Expand All @@ -59,7 +59,7 @@ public void testSimpleMethod() {
public void testMethodWithArguments() {
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { String foo(String h, Foo g) {}}");
ApexQualifiedName qname = root.getFirstDescendantOfType(ASTMethod.class).getQualifiedName();
assertEquals("__Foo#foo(String,Foo)", qname.toString());
assertEquals("c__Foo#foo(String,Foo)", qname.toString());
assertEquals(1, qname.getClasses().length);
assertNotNull(qname.getNameSpace());
assertEquals("foo(String,Foo)", qname.getOperation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
public void example() {
int x = 0, y = 1, z = 2, t = 2;
boolean a = false, b = true, c = false, d = true;
for (String s : list) {
x++;
}
if (a && b || b && d) {
if (y == z) {
x = 2;
Expand Down Expand Up @@ -49,8 +54,8 @@
<description>Complicated method - Standard</description>
<expected-problems>2</expected-problems>
<expected-messages>
<message>'__Complicated#exception()' has value 4.</message>
<message>'__Complicated#example()' has value 17.</message>
<message>'c__Complicated#exception()' has value 4.</message>
<message>'c__Complicated#example()' has value 18.</message>
</expected-messages>
<code-ref id="full-example"/>
</test-code>
Expand All @@ -61,7 +66,7 @@
<rule-property name="reportClasses">false</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Foo#foo()' has value 1.</message>
<message>'c__Foo#foo()' has value 1.</message>
</expected-messages>
<code>
<![CDATA[
Expand Down Expand Up @@ -93,7 +98,7 @@
<rule-property name="reportClasses">false</rule-property>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Test#Test()' has value 4.</message>
<message>'c__Test#Test()' has value 4.</message>
</expected-messages>
<code-ref id="constructor-violation"/>
</test-code>
Expand All @@ -119,7 +124,7 @@
<expected-problems>1</expected-problems>
<rule-property name="reportClasses">false</rule-property>
<expected-messages>
<message>'__Foo#foo()' has value 8.</message>
<message>'c__Foo#foo()' has value 8.</message>
</expected-messages>
<code-ref id="manyBooleanOps"/>
</test-code>
Expand All @@ -128,7 +133,7 @@
<description>Ternary expression counts 1 + boolean complexity</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Foo#bar()' has value 3.</message>
<message>'c__Foo#bar()' has value 3.</message>
</expected-messages>
<code>
<![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<description>Complicated class</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Complicated' has value 16.</message>
<message>'c__Complicated' has value 16.</message>
</expected-messages>
<code-ref id="full-example"/>
</test-code>
Expand All @@ -51,7 +51,7 @@
<description>Empty classes count 0</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Foo' has value 0.</message>
<message>'c__Foo' has value 0.</message>
</expected-messages>
<code>
<![CDATA[
Expand All @@ -65,7 +65,7 @@
<description>Abstract classes and enums are supported</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'__Foo' has value 2.</message>
<message>'c__Foo' has value 2.</message>
</expected-messages>
<code>
<![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*
* @author Clément Fournier
*/

public final class JavaFieldSigMask extends JavaSigMask<JavaFieldSignature> {

private boolean coverFinal = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class SigMaskTest extends ParserTst {
+ "abstract void setZ(int x);"
+ "}";


/**
* Ensure any non-abstract method is covered by a newly created mask.
*/
Expand All @@ -92,7 +91,6 @@ public void testEmptyOperationMask() {
}
}


/**
* Ensure any field is covered by a newly created mask.
*/
Expand All @@ -106,7 +104,6 @@ public void testEmptyFieldMask() {
}
}


@Test
public void testFinalFields() {
List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
Expand All @@ -122,7 +119,6 @@ public void testFinalFields() {
}
}


@Test
public void testStaticFields() {
List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
Expand All @@ -138,7 +134,6 @@ public void testStaticFields() {
}
}


@Test
public void testFieldvisibility() {
List<ASTFieldDeclaration> nodes = getOrderedNodes(ASTFieldDeclaration.class, TEST_FIELDS);
Expand Down Expand Up @@ -183,7 +178,7 @@ public void testFieldvisibility() {
assertFalse(mask.covers(JavaFieldSignature.buildFor(node)));
}
}

}


Expand Down Expand Up @@ -236,7 +231,6 @@ public void testOperationVisibility() {
}
}


@Test
public void testOperationRoles() {
List<ASTMethodOrConstructorDeclaration> nodes = getOrderedNodes(ASTMethodOrConstructorDeclaration.class,
Expand Down

0 comments on commit 51bc82c

Please sign in to comment.