Skip to content

Commit

Permalink
Merge pull request #3740 from oowekyala:issue3698-symtable
Browse files Browse the repository at this point in the history
[java] Fix #3698 - Error resolving Symbol Table #3740

* pr-3740:
  [doc] Update release notes (#3698)
  Fix #3698 - Error resolving Symbol Table
  • Loading branch information
adangel committed Jan 17, 2022
2 parents d49014c + 51212fd commit 1952954
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ This is a {{ site.pmd.release_type }} release.

### Fixed Issues

* java
* [#3698](https://github.com/pmd/pmd/issues/3698): \[java] Error resolving Symbol Table
* java-bestpractices
* [#3209](https://github.com/pmd/pmd/issues/3209): \[java] UnusedPrivateMethod false positive with static method and cast expression
* [#3468](https://github.com/pmd/pmd/issues/3468): \[java] UnusedPrivateMethod false positive when outer class calls private static method on inner class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ private void checkForNameChild(JavaNode node) {
if (node instanceof ASTPrimarySuffix) {
ASTPrimarySuffix suffix = (ASTPrimarySuffix) node;
if (suffix.isArguments()) {
JavaNameOccurrence occurrence = names.get(names.size() - 1);
occurrence.setIsMethodOrConstructorInvocation();
ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).getChild(0);
occurrence.setArgumentCount(args.size());
if (!names.isEmpty()) {
JavaNameOccurrence occurrence = names.get(names.size() - 1);
occurrence.setIsMethodOrConstructorInvocation();
ASTArguments args = (ASTArguments) ((ASTPrimarySuffix) node).getChild(0);
occurrence.setArgumentCount(args.size());
}
} else if (suffix.getNumChildren() == 1 && suffix.getChild(0) instanceof ASTMemberSelector) {
ASTMemberSelector member = (ASTMemberSelector) suffix.getChild(0);
if (member.getNumChildren() == 1 && member.getChild(0) instanceof ASTMethodReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;

public class ScopeAndDeclarationFinderTest extends BaseNonParserTest {
Expand Down Expand Up @@ -72,4 +73,19 @@ public void testAnnonInnerClassScoping() {
ClassScope scope2 = methods.get(1).getScope().getEnclosingScope(ClassScope.class);
Assert.assertSame(scope1, scope2);
}



@Test
public void testSuperCtor() {
// #3698 -- test that parsing does not throw (this executes the symbol pass)
ASTCompilationUnit acu = parseCode("class Foo { Object rs; class Inner { \n"
+ " Inner(Object phase) {\n"
+ " (rs.deferredAttr).super(AttrMode.SPECULATIVE, msym, phase);\n"
+ " } } }");
ASTClassOrInterfaceDeclaration inner = acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class)
.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class);
Assert.assertEquals(5, inner.findDescendantsOfType(ASTPrimaryExpression.class).size());
}

}

0 comments on commit 1952954

Please sign in to comment.