[apex] Fix method name for constructors

This commit is contained in:
Andreas Dangel
2019-01-17 21:32:53 +01:00
parent 6c9cfbc4a1
commit 57ece42cb9
2 changed files with 27 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ public class ASTMethod extends AbstractApexNode<Method> implements ApexQualifiab
@Override
public String getImage() {
return node.getMethodInfo().getCanonicalName();
return node.getMethodInfo().getName();
}
@Override

View File

@@ -0,0 +1,26 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import apex.jorje.semantic.ast.compilation.Compilation;
public class ASTMethodTest {
@Test
public void testConstructorName() {
ApexNode<Compilation> node = parse("public class Foo { public Foo() {} public void bar() {} }");
Assert.assertSame(ASTUserClass.class, node.getClass());
List<ASTMethod> methods = node.findChildrenOfType(ASTMethod.class);
Assert.assertEquals("Foo", methods.get(0).getImage()); // constructor
Assert.assertEquals("bar", methods.get(1).getImage()); // normal method
}
}