From b09baa9a85b7c3add9563a3806c34c8a3e64da68 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Thu, 10 Oct 2024 13:32:10 -0400 Subject: [PATCH] Add 1 blame test case --- .../java/org/codetracker/FileTrackerImpl.java | 39 +- .../FileTrackerWithLocalFilesImpl.java | 39 +- .../blame/CodeTrackerBlameTest.java | 1 + .../blame/blameTestWithLocalRepo13.txt | 44 +- .../blame/blameTestWithLocalRepo16.txt | 8 +- .../blame/blameTestWithLocalRepo21.txt | 1505 +++++++++++++++++ 6 files changed, 1540 insertions(+), 96 deletions(-) create mode 100644 src/test/resources/blame/blameTestWithLocalRepo21.txt diff --git a/src/main/java/org/codetracker/FileTrackerImpl.java b/src/main/java/org/codetracker/FileTrackerImpl.java index af10e1feb88..6f90e531b17 100644 --- a/src/main/java/org/codetracker/FileTrackerImpl.java +++ b/src/main/java/org/codetracker/FileTrackerImpl.java @@ -56,7 +56,6 @@ import gr.uom.java.xmi.diff.UMLDocumentationDiffProvider; import gr.uom.java.xmi.diff.UMLEnumConstantDiff; import gr.uom.java.xmi.diff.UMLModelDiff; -import gr.uom.java.xmi.UMLClass; import gr.uom.java.xmi.UMLEnumConstant; import gr.uom.java.xmi.UMLInitializer; import gr.uom.java.xmi.UMLJavadoc; @@ -1509,25 +1508,10 @@ private Map processMethodsWithSameSignature( if (leftMethod == null) { leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersionAndAnnotation); } - //check if there is another method in leftModel with identical bodyHashCode to the rightMethod - boolean otherExactMatchFound = false; - if (leftMethod != null) { - for (UMLClass leftClass : leftModel.getClassList()) { - for (UMLOperation leftOperation : leftClass.getOperations()) { - if (leftOperation.getBodyHashCode() == rightMethod.getUmlOperation().getBodyHashCode() && !leftOperation.equals(leftMethod.getUmlOperation())) { - otherExactMatchFound = true; - break; - } - } - if(otherExactMatchFound) { - break; - } - } - } - else { + if (leftMethod == null) { notFoundMethods.put(rightMethod, startMethodChangeHistory); } - if (leftMethod != null && !otherExactMatchFound) { + else { if (!leftMethod.equalBody(rightMethod)) startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE)); if (!leftMethod.equalDocuments(rightMethod)) @@ -1581,25 +1565,10 @@ private Map processMethodsWithSameSignature( } //CHANGE BODY OR DOCUMENT leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersionAndDocumentAndBody); - //check if there is another method in leftModel with identical bodyHashCode to the rightMethod - boolean otherExactMatchFound = false; - if (leftMethod != null) { - for (UMLClass leftClass : leftModel.getClassList()) { - for (UMLOperation leftOperation : leftClass.getOperations()) { - if (leftOperation.getBodyHashCode() == rightMethod.getUmlOperation().getBodyHashCode() && !leftOperation.equals(leftMethod.getUmlOperation())) { - otherExactMatchFound = true; - break; - } - } - if(otherExactMatchFound) { - break; - } - } - } - else { + if (leftMethod == null) { notFoundMethods.put(rightMethod, startMethodChangeHistory); } - if (leftMethod != null && !otherExactMatchFound) { + else { if (!leftMethod.equalBody(rightMethod)) startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE)); if (!leftMethod.equalDocuments(rightMethod)) diff --git a/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java b/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java index c2838c8c476..f1b9b4d49ad 100644 --- a/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java +++ b/src/main/java/org/codetracker/FileTrackerWithLocalFilesImpl.java @@ -38,7 +38,6 @@ import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl; import gr.uom.java.xmi.UMLAttribute; -import gr.uom.java.xmi.UMLClass; import gr.uom.java.xmi.UMLEnumConstant; import gr.uom.java.xmi.UMLInitializer; import gr.uom.java.xmi.UMLJavadoc; @@ -1516,25 +1515,10 @@ private Map processMethodsWithSameSignature( if (leftMethod == null) { leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersionAndAnnotation); } - //check if there is another method in leftModel with identical bodyHashCode to the rightMethod - boolean otherExactMatchFound = false; - if (leftMethod != null) { - for (UMLClass leftClass : leftModel.getClassList()) { - for (UMLOperation leftOperation : leftClass.getOperations()) { - if (leftOperation.getBodyHashCode() == rightMethod.getUmlOperation().getBodyHashCode() && !leftOperation.equals(leftMethod.getUmlOperation())) { - otherExactMatchFound = true; - break; - } - } - if(otherExactMatchFound) { - break; - } - } - } - else { + if (leftMethod == null) { notFoundMethods.put(rightMethod, startMethodChangeHistory); } - if (leftMethod != null && !otherExactMatchFound) { + else { if (!leftMethod.equalBody(rightMethod)) startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE)); if (!leftMethod.equalDocuments(rightMethod)) @@ -1588,25 +1572,10 @@ private Map processMethodsWithSameSignature( } //CHANGE BODY OR DOCUMENT leftMethod = getMethod(leftModel, parentVersion, rightMethod::equalIdentifierIgnoringVersionAndDocumentAndBody); - //check if there is another method in leftModel with identical bodyHashCode to the rightMethod - boolean otherExactMatchFound = false; - if (leftMethod != null) { - for (UMLClass leftClass : leftModel.getClassList()) { - for (UMLOperation leftOperation : leftClass.getOperations()) { - if (leftOperation.getBodyHashCode() == rightMethod.getUmlOperation().getBodyHashCode() && !leftOperation.equals(leftMethod.getUmlOperation())) { - otherExactMatchFound = true; - break; - } - } - if(otherExactMatchFound) { - break; - } - } - } - else { + if (leftMethod == null) { notFoundMethods.put(rightMethod, startMethodChangeHistory); } - if (leftMethod != null && !otherExactMatchFound) { + else { if (!leftMethod.equalBody(rightMethod)) startMethodChangeHistory.get().addChange(leftMethod, rightMethod, ChangeFactory.forMethod(Change.Type.BODY_CHANGE)); if (!leftMethod.equalDocuments(rightMethod)) diff --git a/src/test/java/org/codetracker/blame/CodeTrackerBlameTest.java b/src/test/java/org/codetracker/blame/CodeTrackerBlameTest.java index b0fb93bf310..b283badd281 100644 --- a/src/test/java/org/codetracker/blame/CodeTrackerBlameTest.java +++ b/src/test/java/org/codetracker/blame/CodeTrackerBlameTest.java @@ -75,6 +75,7 @@ private static Stream testBlamerInputProvider(){ "https://github.com/mockito/mockito/commit/077562ea54f1fa87ff8dd233c3060ddbf0f1ce26, src/main/java/org/mockito/internal/invocation/MatchersBinder.java, /src/test/resources/blame/blameTestWithLocalRepo18.txt", "https://github.com/hibernate/hibernate-search/commit/5b778035965d7588ad1d1ae522c4bafebd3a0e16, engine/src/main/java/org/hibernate/search/backend/impl/StreamingOperationDispatcher.java, /src/test/resources/blame/blameTestWithLocalRepo19.txt", "https://github.com/eclipse/jetty.project/commit/fc5dd874f3deda71e6cd42af994a5af5cb6be4af, jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/HttpTransportOverHTTP2.java, /src/test/resources/blame/blameTestWithLocalRepo20.txt", + "https://github.com/pmd/pmd/commit/d528dcd5d45582229ab3410deb7c40b2143d015d, pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java, /src/test/resources/blame/blameTestWithLocalRepo21.txt", "https://github.com/eclipse/jgit/commit/bd1a82502680b5de5bf86f6c4470185fd1602386, org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java, /src/test/resources/blame/blameTestUntilCommitZero.txt", "https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/CompilerManagerImpl.java, /src/test/resources/blame/blameTestUntilCommitZero2.txt", "https://github.com/JetBrains/intellij-community/commit/ecb1bb9d4d484ae63ee77f8ad45bdce154db9356, java/compiler/impl/src/com/intellij/compiler/actions/CompileDirtyAction.java, /src/test/resources/blame/blameTestUntilCommitZero3.txt" diff --git a/src/test/resources/blame/blameTestWithLocalRepo13.txt b/src/test/resources/blame/blameTestWithLocalRepo13.txt index 0699bb621bb..180a1573dc1 100644 --- a/src/test/resources/blame/blameTestWithLocalRepo13.txt +++ b/src/test/resources/blame/blameTestWithLocalRepo13.txt @@ -328,20 +328,20 @@ bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocal 0a1a4c6e9 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 328) return returnValue; 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 329) } 330) -0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 331) /** +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 331) /** bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 332) * Gets final variable candidate for ast. bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 333) * @param ast ast. bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 334) * @return Optional of {@link FinalVariableCandidate} for ast from scopeStack. -0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 335) */ +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 335) */ bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 336) private Optional getFinalCandidate(DetailAST ast) { eb5b977a4 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-06-23 12:38:02 +0000 337) Optional result = Optional.empty(); -36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 338) final Iterator iterator = scopeStack.descendingIterator(); +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 338) final Iterator iterator = scopeStack.descendingIterator(); bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 339) while (iterator.hasNext() && !result.isPresent()) { -36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 340) final ScopeData scopeData = iterator.next(); +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 340) final ScopeData scopeData = iterator.next(); bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 341) result = scopeData.findFinalVariableCandidateForAst(ast); -0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 342) } +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 342) } bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 343) return result; -0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 344) } +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 344) } 345) 628e893f2 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Bhavik Patel 2016-01-24 14:35:35 +0000 346) /** 628e893f2 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Bhavik Patel 2016-01-24 14:35:35 +0000 347) * Store un-initialized variables in a temporary stack for future use. @@ -498,28 +498,28 @@ bb1b29851 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocal 36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 498) return ast.getPreviousSibling() == null; 36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 499) } 500) -bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 501) /** +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 501) /** bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 502) * Removes the final variable candidate from the Stack. bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 503) * @param ast variable to remove. -bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 504) */ +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 504) */ bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 505) private void removeFinalVariableCandidateFromStack(DetailAST ast) { -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 506) final Iterator iterator = scopeStack.descendingIterator(); -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 507) while (iterator.hasNext()) { -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 508) final ScopeData scopeData = iterator.next(); +36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 506) final Iterator iterator = scopeStack.descendingIterator(); +53eddca5d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Michal Kordas 2015-04-25 23:35:30 +0000 507) while (iterator.hasNext()) { +36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 508) final ScopeData scopeData = iterator.next(); 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 509) final Map scope = scopeData.scope; 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 510) final FinalVariableCandidate candidate = scope.get(ast.getText()); 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 511) DetailAST storedVariable = null; 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 512) if (candidate != null) { 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 513) storedVariable = candidate.variableIdent; 55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 514) } -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 515) if (storedVariable != null && isSameVariables(storedVariable, ast)) { +11ff590ba src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Bhavik Patel 2015-06-18 21:42:16 +0000 515) if (storedVariable != null && isSameVariables(storedVariable, ast)) { bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 516) if (shouldRemoveFinalVariableCandidate(scopeData, ast)) { -bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 517) scope.remove(ast.getText()); -bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 518) } -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 519) break; -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 520) } -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 521) } -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 522) } +36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 517) scope.remove(ast.getText()); +36b91a59d src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Vladislav Lisetskiy 2015-11-01 13:41:29 +0000 518) } +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 519) break; +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 520) } +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 521) } +0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 522) } 523) 4d214096f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (liscju 2016-12-07 21:22:51 +0000 524) /** 4d214096f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (liscju 2016-12-07 21:22:51 +0000 525) * Check if given parameter definition is a multiple type catch. @@ -712,15 +712,15 @@ bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocal bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 712) */ bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 713) public Optional findFinalVariableCandidateForAst(DetailAST ast) { eb5b977a4 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-06-23 12:38:02 +0000 714) Optional result = Optional.empty(); -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 715) DetailAST storedVariable = null; +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 715) DetailAST storedVariable = null; eb5b977a4 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-06-23 12:38:02 +0000 716) final Optional candidate = eb5b977a4 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-06-23 12:38:02 +0000 717) Optional.ofNullable(scope.get(ast.getText())); bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 718) if (candidate.isPresent()) { bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 719) storedVariable = candidate.get().variableIdent; -55aa50d8f src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:31 +0000 720) } -11ff590ba src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Bhavik Patel 2015-06-18 21:42:16 +0000 721) if (storedVariable != null && isSameVariables(storedVariable, ast)) { +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 720) } +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 721) if (storedVariable != null && isSameVariables(storedVariable, ast)) { bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 722) result = candidate; -0c717ef2a src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Rick Giles 2003-09-11 12:01:47 +0000 723) } +bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 723) } bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 724) return result; bf69cf167 src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java (Andrei Selkin 2016-03-29 22:47:32 +0000 725) } 726) diff --git a/src/test/resources/blame/blameTestWithLocalRepo16.txt b/src/test/resources/blame/blameTestWithLocalRepo16.txt index d6560cc8eaa..fa6afa2b025 100644 --- a/src/test/resources/blame/blameTestWithLocalRepo16.txt +++ b/src/test/resources/blame/blameTestWithLocalRepo16.txt @@ -388,11 +388,11 @@ af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 388) } af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 389) } 390) -abb0a7908 okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 01:17:09 +0000 391) try { +af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 391) try { af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 392) writer.ping(reply, payload1, payload2); -abb0a7908 okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 01:17:09 +0000 393) } catch (IOException e) { -abb0a7908 okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 01:17:09 +0000 394) failConnection(); -abb0a7908 okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 01:17:09 +0000 395) } +af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 393) } catch (IOException e) { +af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 394) failConnection(); +af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 395) } af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 396) } 397) af6198a1e okhttp/src/main/java/okhttp3/internal/http2/Http2Connection.java (Jesse Wilson 2018-02-22 23:37:34 +0000 398) /** For testing: sends a ping and waits for a pong. */ diff --git a/src/test/resources/blame/blameTestWithLocalRepo21.txt b/src/test/resources/blame/blameTestWithLocalRepo21.txt new file mode 100644 index 00000000000..728e069a61c --- /dev/null +++ b/src/test/resources/blame/blameTestWithLocalRepo21.txt @@ -0,0 +1,1505 @@ +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1) /** +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 2) * BSD-style license; for more info see http://pmd.sourceforge.net/license.html +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 3) */ + 4) +ca6eda7e6 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-05-23 06:32:35 +0000 5) package net.sourceforge.pmd.lang.java.typeresolution; + 6) +4728eff5d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-11 08:35:15 +0000 7) import static net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.getApplicableMethods; +4728eff5d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-11 08:35:15 +0000 8) import static net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.getBestMethodReturnType; +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 9) import static net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.getMethodExplicitTypeArugments; +4728eff5d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-11 08:35:15 +0000 10) import static net.sourceforge.pmd.lang.java.typeresolution.MethodTypeResolution.isMemberVisibleFromClass; +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 11) import static net.sourceforge.pmd.lang.java.typeresolution.typedefinition.TypeDefinitionType.LOWER_WILDCARD; +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 12) import static net.sourceforge.pmd.lang.java.typeresolution.typedefinition.TypeDefinitionType.UPPER_BOUND; +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 13) import static net.sourceforge.pmd.lang.java.typeresolution.typedefinition.TypeDefinitionType.UPPER_WILDCARD; + 14) +f4ec16338 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 15) import java.lang.reflect.Field; +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 16) import java.util.ArrayList; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 17) import java.util.Collections; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 18) import java.util.HashMap; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 19) import java.util.List; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 20) import java.util.Map; +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 21) import java.util.logging.Level; +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 22) import java.util.logging.Logger; + 23) +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 24) import net.sourceforge.pmd.lang.ast.Node; +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 25) import net.sourceforge.pmd.lang.ast.QualifiableNode; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 26) import net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 27) import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 28) import net.sourceforge.pmd.lang.java.ast.ASTAndExpression; +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 29) import net.sourceforge.pmd.lang.java.ast.ASTAnnotation; +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 30) import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 31) import net.sourceforge.pmd.lang.java.ast.ASTArgumentList; +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 32) import net.sourceforge.pmd.lang.java.ast.ASTArguments; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 33) import net.sourceforge.pmd.lang.java.ast.ASTArrayDimsAndInits; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 34) import net.sourceforge.pmd.lang.java.ast.ASTBooleanLiteral; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 35) import net.sourceforge.pmd.lang.java.ast.ASTCastExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 36) import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 37) import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 38) import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 39) import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 40) import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 41) import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 42) import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration; +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 43) import net.sourceforge.pmd.lang.java.ast.ASTEnumConstant; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 44) import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 45) import net.sourceforge.pmd.lang.java.ast.ASTExclusiveOrExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 46) import net.sourceforge.pmd.lang.java.ast.ASTExpression; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 47) import net.sourceforge.pmd.lang.java.ast.ASTExtendsList; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 48) import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration; +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 49) import net.sourceforge.pmd.lang.java.ast.ASTForStatement; +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 50) import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 51) import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 52) import net.sourceforge.pmd.lang.java.ast.ASTInclusiveOrExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 53) import net.sourceforge.pmd.lang.java.ast.ASTInstanceOfExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 54) import net.sourceforge.pmd.lang.java.ast.ASTLiteral; +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 55) import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 56) import net.sourceforge.pmd.lang.java.ast.ASTMarkerAnnotation; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 57) import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 58) import net.sourceforge.pmd.lang.java.ast.ASTMultiplicativeExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 59) import net.sourceforge.pmd.lang.java.ast.ASTName; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 60) import net.sourceforge.pmd.lang.java.ast.ASTNormalAnnotation; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 61) import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 62) import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 63) import net.sourceforge.pmd.lang.java.ast.ASTPostfixExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 64) import net.sourceforge.pmd.lang.java.ast.ASTPreDecrementExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 65) import net.sourceforge.pmd.lang.java.ast.ASTPreIncrementExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 66) import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 67) import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 68) import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 69) import net.sourceforge.pmd.lang.java.ast.ASTReferenceType; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 70) import net.sourceforge.pmd.lang.java.ast.ASTRelationalExpression; +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 71) import net.sourceforge.pmd.lang.java.ast.ASTResource; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 72) import net.sourceforge.pmd.lang.java.ast.ASTShiftExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 73) import net.sourceforge.pmd.lang.java.ast.ASTSingleMemberAnnotation; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 74) import net.sourceforge.pmd.lang.java.ast.ASTStatementExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 75) import net.sourceforge.pmd.lang.java.ast.ASTType; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 76) import net.sourceforge.pmd.lang.java.ast.ASTTypeArgument; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 77) import net.sourceforge.pmd.lang.java.ast.ASTTypeArguments; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 78) import net.sourceforge.pmd.lang.java.ast.ASTTypeBound; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 79) import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 80) import net.sourceforge.pmd.lang.java.ast.ASTTypeParameter; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 81) import net.sourceforge.pmd.lang.java.ast.ASTTypeParameters; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 82) import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 83) import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpressionNotPlusMinus; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 84) import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 85) import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 86) import net.sourceforge.pmd.lang.java.ast.ASTVariableInitializer; +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 87) import net.sourceforge.pmd.lang.java.ast.ASTWildcardBounds; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 88) import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode; +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 89) import net.sourceforge.pmd.lang.java.ast.JavaNode; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 90) import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter; +d40e80742 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-31 13:59:48 +0000 91) import net.sourceforge.pmd.lang.java.ast.TypeNode; +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 92) import net.sourceforge.pmd.lang.java.symboltable.ClassScope; +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 93) import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 94) import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 95) import net.sourceforge.pmd.lang.symboltable.NameOccurrence; +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 96) import net.sourceforge.pmd.lang.symboltable.Scope; + 97) + 98) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 99) // +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 100) // Helpful reading: +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 101) // http://www.janeg.ca/scjp/oper/promotions.html +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 102) // http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 103) // + 104) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 105) public class ClassTypeResolver extends JavaParserVisitorAdapter { + 106) +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 107) private static final Logger LOG = Logger.getLogger(ClassTypeResolver.class.getName()); + 108) +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 109) private static final Map> PRIMITIVE_TYPES; +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 110) private static final Map JAVA_LANG; + 111) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 112) private Map staticFieldImageToTypeDef; +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 113) private Map> staticNamesToClasses; +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 114) private List importOnDemandStaticClasses; +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 115) private ASTCompilationUnit currentAcu; + 116) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 117) static { +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 118) // Note: Assumption here that primitives come from same parent +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 119) // ClassLoader regardless of what ClassLoader we are passed +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 120) Map> thePrimitiveTypes = new HashMap<>(); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 121) thePrimitiveTypes.put("void", Void.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 122) thePrimitiveTypes.put("boolean", Boolean.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 123) thePrimitiveTypes.put("byte", Byte.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 124) thePrimitiveTypes.put("char", Character.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 125) thePrimitiveTypes.put("short", Short.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 126) thePrimitiveTypes.put("int", Integer.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 127) thePrimitiveTypes.put("long", Long.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 128) thePrimitiveTypes.put("float", Float.TYPE); +8564544d8 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:40:25 +0000 129) thePrimitiveTypes.put("double", Double.TYPE); +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 130) PRIMITIVE_TYPES = Collections.unmodifiableMap(thePrimitiveTypes); + 131) +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 132) Map theJavaLang = new HashMap<>(); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 133) theJavaLang.put("Boolean", "java.lang.Boolean"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 134) theJavaLang.put("Byte", "java.lang.Byte"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 135) theJavaLang.put("Character", "java.lang.Character"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 136) theJavaLang.put("CharSequence", "java.lang.CharSequence"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 137) theJavaLang.put("Class", "java.lang.Class"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 138) theJavaLang.put("ClassLoader", "java.lang.ClassLoader"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 139) theJavaLang.put("Cloneable", "java.lang.Cloneable"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 140) theJavaLang.put("Comparable", "java.lang.Comparable"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 141) theJavaLang.put("Compiler", "java.lang.Compiler"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 142) theJavaLang.put("Double", "java.lang.Double"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 143) theJavaLang.put("Float", "java.lang.Float"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 144) theJavaLang.put("InheritableThreadLocal", "java.lang.InheritableThreadLocal"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 145) theJavaLang.put("Integer", "java.lang.Integer"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 146) theJavaLang.put("Long", "java.lang.Long"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 147) theJavaLang.put("Math", "java.lang.Math"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 148) theJavaLang.put("Number", "java.lang.Number"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 149) theJavaLang.put("Object", "java.lang.Object"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 150) theJavaLang.put("Package", "java.lang.Package"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 151) theJavaLang.put("Process", "java.lang.Process"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 152) theJavaLang.put("Runnable", "java.lang.Runnable"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 153) theJavaLang.put("Runtime", "java.lang.Runtime"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 154) theJavaLang.put("RuntimePermission", "java.lang.RuntimePermission"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 155) theJavaLang.put("SecurityManager", "java.lang.SecurityManager"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 156) theJavaLang.put("Short", "java.lang.Short"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 157) theJavaLang.put("StackTraceElement", "java.lang.StackTraceElement"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 158) theJavaLang.put("StrictMath", "java.lang.StrictMath"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 159) theJavaLang.put("String", "java.lang.String"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 160) theJavaLang.put("StringBuffer", "java.lang.StringBuffer"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 161) theJavaLang.put("System", "java.lang.System"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 162) theJavaLang.put("Thread", "java.lang.Thread"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 163) theJavaLang.put("ThreadGroup", "java.lang.ThreadGroup"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 164) theJavaLang.put("ThreadLocal", "java.lang.ThreadLocal"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 165) theJavaLang.put("Throwable", "java.lang.Throwable"); +b178c29a2 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-05 22:38:42 +0000 166) theJavaLang.put("Void", "java.lang.Void"); +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 167) JAVA_LANG = Collections.unmodifiableMap(theJavaLang); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 168) } + 169) +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 170) private final PMDASMClassLoader pmdClassLoader; +516c08165 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2007-01-27 01:14:44 +0000 171) private Map importedClasses; +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 172) private List importedOnDemand; + 173) + 174) +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 175) public ClassTypeResolver() { +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 176) this(ClassTypeResolver.class.getClassLoader()); +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 177) } + 178) +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 179) public ClassTypeResolver(ClassLoader classLoader) { +9e4858b8c pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (rsalvador 2012-11-28 18:08:43 +0000 180) pmdClassLoader = PMDASMClassLoader.getInstance(classLoader); +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 181) } + 182) +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 183) // FUTURE ASTCompilationUnit should not be a TypeNode. Clean this up +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 184) // accordingly. +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 185) @Override +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 186) public Object visit(ASTCompilationUnit node, Object data) { +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 187) String className = null; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 188) try { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 189) currentAcu = node; +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 190) importedOnDemand = new ArrayList<>(); +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 191) importedClasses = new HashMap<>(); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 192) staticFieldImageToTypeDef = new HashMap<>(); +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 193) staticNamesToClasses = new HashMap<>(); +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 194) importOnDemandStaticClasses = new ArrayList<>(); + 195) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 196) // TODO: this fails to account for multiple classes in the same file +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 197) // later classes (in the ACU) won't have their Nested classes registered +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 198) className = getClassName(node); +40501042c pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-21 03:57:32 +0000 199) if (className != null) { +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 200) populateClassName(node, className); +40501042c pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-21 03:57:32 +0000 201) } +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 202) } catch (ClassNotFoundException | NoClassDefFoundError e) { +5f35ded04 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-11-16 10:38:42 +0000 203) if (LOG.isLoggable(Level.FINE)) { +1f6421ec8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Roman 2015-02-15 19:34:32 +0000 204) LOG.log(Level.FINE, "Could not find class " + className + ", due to: " + e); +5f35ded04 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-11-16 10:38:42 +0000 205) } +b172c19de pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (rsalvador 2012-11-27 21:17:15 +0000 206) } catch (LinkageError e) { +5f35ded04 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-11-16 10:38:42 +0000 207) if (LOG.isLoggable(Level.WARNING)) { +1f6421ec8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Roman 2015-02-15 19:34:32 +0000 208) LOG.log(Level.WARNING, "Could not find class " + className + ", due to: " + e); +5f35ded04 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-11-16 10:38:42 +0000 209) } +ad46a291e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-04-16 22:16:41 +0000 210) } finally { +ad46a291e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-04-16 22:16:41 +0000 211) populateImports(node); +ad46a291e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-04-16 22:16:41 +0000 212) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 213) return super.visit(node, data); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 214) } + 215) +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 216) @Override +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 217) public Object visit(ASTPackageDeclaration node, Object data) { +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 218) // no need to visit children, the only child, ASTName, will have no type +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 219) return data; +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 220) } + 221) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 222) @Override +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 223) public Object visit(ASTImportDeclaration node, Object data) { +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 224) ASTName importedType = (ASTName) node.jjtGetChild(0); + 225) +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 226) if (importedType.getType() != null) { +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 227) node.setType(importedType.getType()); +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 228) } else { +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 229) populateType(node, importedType.getImage()); +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 230) } + 231) +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 232) if (node.getType() != null) { +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 233) node.setPackage(node.getType().getPackage()); +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 234) } + 235) +6c7ec7533 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:44:23 +0000 236) // no need to visit children, the only child, ASTName, will have no type +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 237) return data; +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 238) } + 239) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 240) @Override +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 241) public Object visit(ASTTypeDeclaration node, Object data) { +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 242) super.visit(node, data); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 243) rollupTypeUnary(node); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 244) return data; +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 245) } + 246) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 247) @Override +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 248) public Object visit(ASTClassOrInterfaceType node, Object data) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 249) super.visit(node, data); + 250) +3d7faa7cd pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Brian Remedios 2011-07-31 07:41:47 +0000 251) String typeName = node.getImage(); + 252) +46daa878b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-19 22:18:21 +0000 253) if (node.isAnonymousClass()) { +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 254) QualifiableNode parent = node.getFirstParentOfAnyType(ASTAllocationExpression.class, ASTEnumConstant.class); + 255) +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 256) if (parent != null) { +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 257) typeName = parent.getQualifiedName().toString(); +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 258) } +3d7faa7cd pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Brian Remedios 2011-07-31 07:41:47 +0000 259) } + 260) +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 261) // FIXME, we should discard the array depth on this node, it should only be known to ASTReferenceType (#910) +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 262) populateType(node, typeName, node.getArrayDepth()); + 263) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 264) ASTTypeArguments typeArguments = node.getFirstChildOfType(ASTTypeArguments.class); + 265) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 266) if (typeArguments != null) { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 267) final JavaTypeDefinition[] boundGenerics = new JavaTypeDefinition[typeArguments.jjtGetNumChildren()]; +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 268) for (int i = 0; i < typeArguments.jjtGetNumChildren(); ++i) { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 269) boundGenerics[i] = ((TypeNode) typeArguments.jjtGetChild(i)).getTypeDefinition(); +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 270) } + 271) +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 272) node.setTypeDefinition(JavaTypeDefinition.forClass(node.getType(), boundGenerics)); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 273) } + 274) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 275) return data; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 276) } + 277) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 278) /** +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 279) * Set's the node's type to the found Class in the node's name (if there is a class to be found). +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 280) * +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 281) * @param node +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 282) * +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 283) * @return The index in the array produced by splitting the node's name by '.', which is not part of the +ece871c2f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2017-10-06 17:48:55 +0000 284) * class name found. Example: com.package.SomeClass.staticField.otherField, return would be 3 +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 285) */ +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 286) private int searchNodeNameForClass(TypeNode node) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 287) // this is the index from which field/method names start in the dotSplitImage array +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 288) int startIndex = node.getImage().split("\\.").length; + 289) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 290) // tries to find a class in the node's image by omitting the parts after each '.', example: +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 291) // First try: com.package.SomeClass.staticField.otherField +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 292) // Second try: com.package.SomeClass.staticField +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 293) // Third try: com.package.SomeClass <- found a class! +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 294) for (String reducedImage = node.getImage();;) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 295) populateType(node, reducedImage); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 296) if (node.getType() != null) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 297) break; // we found a class! +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 298) } + 299) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 300) // update the start index, so that code below knows where to start in the dotSplitImage array +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 301) --startIndex; + 302) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 303) int lastDotIndex = reducedImage.lastIndexOf('.'); + 304) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 305) if (lastDotIndex != -1) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 306) reducedImage = reducedImage.substring(0, lastDotIndex); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 307) } else { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 308) break; // there is no class +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 309) } +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 310) } + 311) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 312) return startIndex; +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 313) } + 314) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 315) private ASTArgumentList getArgumentList(ASTArguments args) { +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 316) if (args != null) { +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 317) return args.getFirstChildOfType(ASTArgumentList.class); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 318) } + 319) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 320) return null; +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 321) } + 322) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 323) private int getArgumentListArity(ASTArgumentList argList) { +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 324) if (argList != null) { +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 325) return argList.jjtGetNumChildren(); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 326) } + 327) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 328) return 0; +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 329) } + 330) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 331) @Override +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 332) public Object visit(ASTName node, Object data) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 333) Class accessingClass = getEnclosingTypeDeclarationClass(node); +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 334) String[] dotSplitImage = node.getImage().split("\\."); + 335) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 336) int startIndex = searchNodeNameForClass(node); + 337) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 338) ASTArguments astArguments = getSuffixMethodArgs(node); +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 339) ASTArgumentList astArgumentList = getArgumentList(astArguments); +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 340) int methodArgsArity = getArgumentListArity(astArgumentList); + 341) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 342) JavaTypeDefinition previousType; + 343) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 344) if (node.getType() != null) { // static field or method +67e4daa17 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-25 11:27:46 +0000 345) // node.getType() has been set by the call to searchNodeNameForClass above +67e4daa17 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-25 11:27:46 +0000 346) // node.getType() will have the value equal to the Class found by that method +989dd133f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2017-10-28 18:18:56 +0000 347) previousType = node.getTypeDefinition(); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 348) } else { // non-static field or method +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 349) if (dotSplitImage.length == 1 && astArguments != null) { // method +1426b23ce pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 350) List methods = getLocalApplicableMethods(node, dotSplitImage[0], +1426b23ce pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 351) Collections.emptyList(), +1426b23ce pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 352) methodArgsArity, accessingClass); + 353) +bc20be1ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 354) TypeNode enclosingType = getEnclosingTypeDeclaration(node); +bc20be1ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 355) if (enclosingType == null) { +bc20be1ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 356) return data; // we can't proceed, probably uncompiled sources +bc20be1ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 357) } + 358) +90b802526 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 359) previousType = getBestMethodReturnType(enclosingType.getTypeDefinition(), +90b802526 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 360) methods, astArgumentList); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 361) } else { // field +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 362) previousType = getTypeDefinitionOfVariableFromScope(node.getScope(), dotSplitImage[0], +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 363) accessingClass); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 364) } +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 365) startIndex = 1; // first element's type in dotSplitImage has already been resolved +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 366) } + 367) +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 368) // TODO: remove this if branch, it's only purpose is to make JUnitAssertionsShouldIncludeMessage's tests pass +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 369) // as the code is not compiled there and symbol table works on uncompiled code +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 370) if (node.getNameDeclaration() != null +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 371) && previousType == null // if it's not null, then let other code handle things +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 372) && node.getNameDeclaration().getNode() instanceof TypeNode) { +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 373) // Carry over the type (including generics) from the declaration +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 374) JavaTypeDefinition nodeType = ((TypeNode) node.getNameDeclaration().getNode()).getTypeDefinition(); +704d87b47 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-26 21:44:51 +0000 375) if (nodeType != null) { +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 376) node.setTypeDefinition(nodeType); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 377) return super.visit(node, data); +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 378) } +2fd1c89ed pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 17:49:29 +0000 379) } + 380) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 381) for (int i = startIndex; i < dotSplitImage.length; ++i) { +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 382) if (previousType == null) { +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 383) break; +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 384) } + 385) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 386) if (i == dotSplitImage.length - 1 && astArguments != null) { // method +bd503ba13 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-02 19:13:28 +0000 387) List methods = getApplicableMethods(previousType, dotSplitImage[i], +bd503ba13 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-02 19:13:28 +0000 388) Collections.emptyList(), +bd503ba13 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-02 19:13:28 +0000 389) methodArgsArity, accessingClass); + 390) +90b802526 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 391) previousType = getBestMethodReturnType(previousType, methods, astArgumentList); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 392) } else { // field +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 393) previousType = getFieldType(previousType, dotSplitImage[i], accessingClass); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 394) } +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 395) } + 396) +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 397) if (previousType != null) { +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 398) node.setTypeDefinition(previousType); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 399) } + 400) +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 401) return super.visit(node, data); +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 402) } + 403) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 404) /** +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 405) * This method looks for method invocations be simple name. +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 406) * It searches outwards class declarations and their supertypes and in the end, static method imports. +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 407) * Compiles a list of potentially applicable methods. +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 408) * https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.1 +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 409) */ +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 410) private List getLocalApplicableMethods(TypeNode node, String methodName, +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 411) List typeArguments, +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 412) int argArity, +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 413) Class accessingClass) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 414) List foundMethods = new ArrayList<>(); + 415) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 416) if (accessingClass == null) { +ed9b015c9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 11:57:50 +0000 417) return foundMethods; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 418) } + 419) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 420) // we search each enclosing type declaration, looking at their supertypes as well +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 421) for (node = getEnclosingTypeDeclaration(node); node != null; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 422) node = getEnclosingTypeDeclaration(node.jjtGetParent())) { + 423) +0c483205d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 19:19:45 +0000 424) foundMethods.addAll(getApplicableMethods(node.getTypeDefinition(), methodName, typeArguments, +0c483205d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 19:19:45 +0000 425) argArity, accessingClass)); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 426) } + 427) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 428) foundMethods.addAll(searchImportedStaticMethods(methodName, typeArguments, argArity, accessingClass)); + 429) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 430) return foundMethods; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 431) } + 432) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 433) private List searchImportedStaticMethods(String methodName, +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 434) List typeArguments, +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 435) int argArity, +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 436) Class accessingClass) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 437) List foundMethods = new ArrayList<>(); + 438) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 439) // TODO: member methods must not be looked at in the code below +67e4daa17 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-25 11:27:46 +0000 440) // TODO: add support for properly dealing with shadowing +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 441) List explicitImports = staticNamesToClasses.get(methodName); + 442) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 443) if (explicitImports != null) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 444) for (JavaTypeDefinition anImport : explicitImports) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 445) foundMethods.addAll(getApplicableMethods(anImport, methodName, typeArguments, argArity, +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 446) accessingClass)); +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 447) } +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 448) } + 449) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 450) if (!foundMethods.isEmpty()) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 451) // if we found an method by explicit imports, on deamand imports mustn't be searched, because +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 452) // explicit imports shadow them by name, regardless of method parameters +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 453) return foundMethods; +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 454) } + 455) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 456) for (JavaTypeDefinition anOnDemandImport : importOnDemandStaticClasses) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 457) foundMethods.addAll(getApplicableMethods(anOnDemandImport, methodName, typeArguments, argArity, +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 458) accessingClass)); +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 459) } + 460) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 461) return foundMethods; +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 462) } + 463) + 464) +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 465) /** +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 466) * This method can be called on a prefix +2a7fbc1d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-09 20:48:26 +0000 467) */ +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 468) private ASTArguments getSuffixMethodArgs(Node node) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 469) Node prefix = node.jjtGetParent(); + 470) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 471) if (prefix instanceof ASTPrimaryPrefix +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 472) && prefix.jjtGetParent().jjtGetNumChildren() >= 2) { +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 473) return prefix.jjtGetParent().jjtGetChild(1).getFirstChildOfType(ASTArguments.class); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 474) } + 475) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 476) return null; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 477) } + 478) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 479) /** +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 480) * Searches a JavaTypeDefinition and it's superclasses until a field with name {@code fieldImage} that +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 481) * is visible from the {@code accessingClass} class. Once it's found, it's possibly generic type is +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 482) * resolved with the help of {@code typeToSearch} TypeDefinition. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 483) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 484) * @param typeToSearch The type def. to search the field in. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 485) * @param fieldImage The simple name of the field. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 486) * @param accessingClass The class that is trying to access the field, some Class declared in the current ACU. +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 487) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 488) * @return JavaTypeDefinition of the resolved field or null if it could not be found. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 489) */ +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 490) private JavaTypeDefinition getFieldType(JavaTypeDefinition typeToSearch, String fieldImage, Class +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 491) accessingClass) { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 492) while (typeToSearch != null && typeToSearch.getType() != Object.class) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 493) try { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 494) final Field field = typeToSearch.getType().getDeclaredField(fieldImage); +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 495) if (isMemberVisibleFromClass(typeToSearch.getType(), field.getModifiers(), accessingClass)) { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 496) return typeToSearch.resolveTypeDefinition(field.getGenericType()); +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 497) } +b6482bb33 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:36:30 +0000 498) } catch (final NoSuchFieldException ignored) { +b6482bb33 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:36:30 +0000 499) // swallow +729d77614 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-12-31 03:48:23 +0000 500) } catch (final LinkageError e) { +729d77614 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-12-31 03:48:23 +0000 501) if (LOG.isLoggable(Level.WARNING)) { +729d77614 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-12-31 03:48:23 +0000 502) LOG.log(Level.WARNING, "Error during type resolution due to: " + e); +729d77614 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-12-31 03:48:23 +0000 503) } +b6482bb33 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:36:30 +0000 504) // TODO : report a missing class once we start doing that... +b6482bb33 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:36:30 +0000 505) return null; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 506) } + 507) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 508) // transform the type into it's supertype +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 509) typeToSearch = typeToSearch.resolveTypeDefinition(typeToSearch.getType().getGenericSuperclass()); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 510) } + 511) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 512) return null; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 513) } + 514) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 515) /** +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 516) * Search for a field by it's image stating from a scope and taking into account if it's visible from the +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 517) * accessingClass Class. The method takes into account that Nested inherited fields shadow outer scope fields. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 518) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 519) * @param scope The scope to start the search from. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 520) * @param image The name of the field, local variable or method parameter. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 521) * @param accessingClass The Class (which is defined in the current ACU) that is trying to access the field. +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 522) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 523) * @return Type def. of the field, or null if it could not be resolved. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 524) */ +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 525) private JavaTypeDefinition getTypeDefinitionOfVariableFromScope(Scope scope, String image, Class +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 526) accessingClass) { +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 527) if (accessingClass == null) { +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 528) return null; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 529) } + 530) +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 531) for (/* empty */; scope != null; scope = scope.getParent()) { +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 532) // search each enclosing scope one by one +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 533) for (Map.Entry> entry +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 534) : scope.getDeclarations(VariableNameDeclaration.class).entrySet()) { +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 535) if (entry.getKey().getImage().equals(image)) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 536) ASTType typeNode = entry.getKey().getDeclaratorId().getTypeNode(); + 537) +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 538) if (typeNode == null) { +1211e8836 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-19 11:25:08 +0000 539) // TODO : Type is inferred, ie, this is a lambda such as (var) -> var.equals(other) or a local var +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 540) return null; +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 541) } + 542) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 543) if (typeNode.jjtGetChild(0) instanceof ASTReferenceType) { +bd187a3c6 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 08:45:01 +0000 544) return ((TypeNode) typeNode.jjtGetChild(0)).getTypeDefinition(); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 545) } else { // primitive type +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 546) return JavaTypeDefinition.forClass(typeNode.getType()); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 547) } +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 548) } +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 549) } + 550) +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 551) // Nested class' inherited fields shadow enclosing variables +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 552) if (scope instanceof ClassScope) { +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 553) try { +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 554) // get the superclass type def. ot the Class the ClassScope belongs to +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 555) JavaTypeDefinition superClass +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 556) = getSuperClassTypeDefinition(((ClassScope) scope).getClassDeclaration().getNode(), +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 557) null); +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 558) // TODO: check if anonymous classes are class scope + 559) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 560) // try searching this type def. +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 561) JavaTypeDefinition foundTypeDef = getFieldType(superClass, image, accessingClass); + 562) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 563) if (foundTypeDef != null) { // if null, then it's not an inherited field +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 564) return foundTypeDef; +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 565) } +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 566) } catch (ClassCastException ignored) { +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 567) // if there is an anonymous class, getClassDeclaration().getType() will throw +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 568) // TODO: maybe there is a better way to handle this, maybe this hides bugs +c8763bef1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 569) } +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 570) } +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 571) } + 572) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 573) return searchImportedStaticFields(image); // will return null if not found +13025f875 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 574) } + 575) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 576) private JavaTypeDefinition searchImportedStaticFields(String fieldName) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 577) if (staticFieldImageToTypeDef.containsKey(fieldName)) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 578) return staticFieldImageToTypeDef.get(fieldName); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 579) } + 580) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 581) for (JavaTypeDefinition anOnDemandImport : importOnDemandStaticClasses) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 582) JavaTypeDefinition typeDef = getFieldType(anOnDemandImport, fieldName, currentAcu.getType()); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 583) if (typeDef != null) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 584) staticFieldImageToTypeDef.put(fieldName, typeDef); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 585) return typeDef; +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 586) } +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 587) } + 588) +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 589) return null; +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 590) } + 591) + 592) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 593) @Override +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 594) public Object visit(ASTFieldDeclaration node, Object data) { +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 595) super.visit(node, data); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 596) rollupTypeUnary(node); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 597) return data; +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 598) } + 599) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 600) @Override +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 601) public Object visit(ASTVariableDeclarator node, Object data) { +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 602) super.visit(node, data); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 603) rollupTypeUnary(node); +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 604) return data; +4e78fbaba pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 22:53:29 +0000 605) } + 606) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 607) @Override +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 608) public Object visit(ASTVariableDeclaratorId node, Object data) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 609) if (node == null || node.isTypeInferred()) { +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 610) return super.visit(node, data); +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 611) } + 612) +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 613) // Type common to all declarations in the same statement +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 614) JavaTypeDefinition baseType = node.getTypeNode().getTypeDefinition(); + 615) +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 616) if (baseType != null) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 617) // add the dimensions specific to the declarator id +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 618) node.setTypeDefinition(baseType.withDimensions(node.getArrayDepth())); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 619) } +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 620) return super.visit(node, data); +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 621) } + 622) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 623) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 624) public Object visit(ASTType node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 625) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 626) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 627) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 628) } + 629) +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 630) private void populateVariableDeclaratorFromType(ASTLocalVariableDeclaration node, JavaTypeDefinition typeDefinition) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 631) // assign this type to VariableDeclarator and VariableDeclaratorId +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 632) TypeNode var = node.getFirstChildOfType(ASTVariableDeclarator.class); +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 633) if (var != null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 634) var.setTypeDefinition(typeDefinition); +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 635) var = var.getFirstChildOfType(ASTVariableDeclaratorId.class); +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 636) } +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 637) if (var != null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 638) var.setTypeDefinition(typeDefinition); +a1b2d59fc pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:38 +0000 639) } +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 640) } + 641) +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 642) @Override +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 643) public Object visit(ASTLocalVariableDeclaration node, Object data) { +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 644) super.visit(node, data); +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 645) // resolve "var" types: Upward projection of the type of the initializer expression +a305f78e2 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-21 09:17:25 +0000 646) ASTType type = node.getTypeNode(); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 647) if (type == null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 648) // no type node -> type is inferred +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 649) ASTVariableInitializer initializer = node.getFirstDescendantOfType(ASTVariableInitializer.class); +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 650) if (initializer != null && initializer.jjtGetChild(0) instanceof ASTExpression) { +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 651) // only Expression is allowed, ArrayInitializer is not allowed in combination with "var". +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 652) ASTExpression expression = (ASTExpression) initializer.jjtGetChild(0); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 653) populateVariableDeclaratorFromType(node, expression.getTypeDefinition()); +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 654) } +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 655) } +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 656) return data; +f0b847a7a pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-07 17:47:25 +0000 657) } + 658) +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 659) @Override +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 660) public Object visit(ASTForStatement node, Object data) { +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 661) super.visit(node, data); +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 662) // resolve potential "var" type +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 663) if (node.jjtGetChild(0) instanceof ASTLocalVariableDeclaration) { +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 664) ASTLocalVariableDeclaration localVariableDeclaration = (ASTLocalVariableDeclaration) node.jjtGetChild(0); +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 665) ASTType type = localVariableDeclaration.getTypeNode(); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 666) if (type == null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 667) // no type node -> type is inferred +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 668) ASTExpression expression = node.getFirstChildOfType(ASTExpression.class); +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 669) if (expression != null && expression.getTypeDefinition() != null) { +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 670) // see https://docs.oracle.com/javase/specs/jls/se10/html/jls-14.html#jls-14.14.2 +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 671) // if the type is an array, then take the component type +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 672) // if the type is Iterable, then take X as type +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 673) // if the type is Iterable, take Object as type +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 674) JavaTypeDefinition typeDefinitionIterable = expression.getTypeDefinition(); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 675) JavaTypeDefinition typeDefinition = null; +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 676) if (typeDefinitionIterable.isArrayType()) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 677) typeDefinition = typeDefinitionIterable.getComponentType(); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 678) } else if (typeDefinitionIterable.isGeneric() && typeDefinitionIterable.getGenericType(0) != null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 679) typeDefinition = typeDefinitionIterable.getGenericType(0); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 680) } else { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 681) typeDefinition = JavaTypeDefinition.forClass(Object.class); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 682) } +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 683) populateVariableDeclaratorFromType(localVariableDeclaration, typeDefinition); +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 684) } +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 685) } +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 686) } +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 687) return data; +fd3c425d0 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 12:36:16 +0000 688) } + 689) +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 690) @Override +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 691) public Object visit(ASTResource node, Object data) { +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 692) super.visit(node, data); +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 693) // resolve "var" types: the type of the initializer expression +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 694) ASTType type = node.getTypeNode(); +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 695) if (type == null) { +a46288547 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:18:59 +0000 696) // no type node -> type is inferred +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 697) ASTExpression initializer = node.getFirstChildOfType(ASTExpression.class); + 698) +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 699) if (node.getVariableDeclaratorId() != null) { +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 700) node.getVariableDeclaratorId().setTypeDefinition(initializer.getTypeDefinition()); +b0266e3e7 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 14:16:52 +0000 701) } +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 702) } +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 703) return data; +e2815a62d pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-11 07:43:05 +0000 704) } + 705) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 706) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 707) public Object visit(ASTReferenceType node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 708) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 709) rollupTypeUnary(node); + 710) +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 711) JavaTypeDefinition elementTypeDef = node.getTypeDefinition(); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 712) if (elementTypeDef != null) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 713) // FIXME when ClassOrInterfaceType resolves type without dimensions, remove the test here +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 714) if (!elementTypeDef.isArrayType()) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 715) node.setTypeDefinition(elementTypeDef.withDimensions(node.getArrayDepth())); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 716) } +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 717) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 718) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 719) } + 720) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 721) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 722) public Object visit(ASTPrimitiveType node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 723) populateType(node, node.getImage()); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 724) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 725) } + 726) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 727) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 728) public Object visit(ASTExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 729) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 730) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 731) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 732) } + 733) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 734) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 735) public Object visit(ASTConditionalExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 736) super.visit(node, data); + 737) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 738) // TODO Rules for Ternary are complex + 739) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 740) rollupTypeUnary(node); + 741) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 742) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 743) } + 744) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 745) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 746) public Object visit(ASTConditionalOrExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 747) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 748) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 749) } + 750) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 751) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 752) public Object visit(ASTConditionalAndExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 753) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 754) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 755) } + 756) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 757) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 758) public Object visit(ASTInclusiveOrExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 759) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 760) rollupTypeBinaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 761) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 762) } + 763) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 764) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 765) public Object visit(ASTExclusiveOrExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 766) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 767) rollupTypeBinaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 768) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 769) } + 770) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 771) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 772) public Object visit(ASTAndExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 773) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 774) rollupTypeBinaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 775) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 776) } + 777) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 778) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 779) public Object visit(ASTEqualityExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 780) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 781) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 782) } + 783) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 784) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 785) public Object visit(ASTInstanceOfExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 786) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 787) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 788) } + 789) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 790) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 791) public Object visit(ASTRelationalExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 792) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 793) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 794) } + 795) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 796) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 797) public Object visit(ASTShiftExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 798) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 799) // Unary promotion on LHS is type of a shift operation +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 800) rollupTypeUnaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 801) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 802) } + 803) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 804) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 805) public Object visit(ASTAdditiveExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 806) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 807) rollupTypeBinaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 808) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 809) } + 810) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 811) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 812) public Object visit(ASTMultiplicativeExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 813) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 814) rollupTypeBinaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 815) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 816) } + 817) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 818) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 819) public Object visit(ASTUnaryExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 820) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 821) rollupTypeUnaryNumericPromotion(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 822) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 823) } + 824) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 825) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 826) public Object visit(ASTPreIncrementExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 827) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 828) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 829) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 830) } + 831) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 832) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 833) public Object visit(ASTPreDecrementExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 834) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 835) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 836) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 837) } + 838) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 839) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 840) public Object visit(ASTUnaryExpressionNotPlusMinus node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 841) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 842) if ("!".equals(node.getImage())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 843) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 844) } else { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 845) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 846) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 847) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 848) } + 849) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 850) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 851) public Object visit(ASTPostfixExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 852) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 853) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 854) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 855) } + 856) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 857) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 858) public Object visit(ASTCastExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 859) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 860) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 861) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 862) } + 863) + 864) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 865) @Override +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 866) public Object visit(ASTPrimaryExpression primaryNode, Object data) { +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 867) // visit method arguments in reverse +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 868) for (int i = primaryNode.jjtGetNumChildren() - 1; i >= 0; --i) { +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 869) ((JavaNode) primaryNode.jjtGetChild(i)).jjtAccept(this, data); +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 870) } + 871) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 872) JavaTypeDefinition primaryNodeType = null; +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 873) AbstractJavaTypeNode previousChild = null; +c2bb8e5f4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-20 22:31:54 +0000 874) AbstractJavaTypeNode nextChild; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 875) Class accessingClass = getEnclosingTypeDeclarationClass(primaryNode); + 876) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 877) for (int childIndex = 0; childIndex < primaryNode.jjtGetNumChildren(); ++childIndex) { +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 878) AbstractJavaTypeNode currentChild = (AbstractJavaTypeNode) primaryNode.jjtGetChild(childIndex); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 879) nextChild = childIndex + 1 < primaryNode.jjtGetNumChildren() +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 880) ? (AbstractJavaTypeNode) primaryNode.jjtGetChild(childIndex + 1) : null; + 881) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 882) // skip children which already have their type assigned +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 883) if (currentChild.getType() == null) { +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 884) // Last token, because if 'this' is a Suffix, it'll have tokens '.' and 'this' +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 885) if (currentChild.jjtGetLastToken().toString().equals("this")) { + 886) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 887) if (previousChild != null) { // Qualified 'this' expression +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 888) currentChild.setTypeDefinition(previousChild.getTypeDefinition()); +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 889) } else { // simple 'this' expression +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 890) ASTClassOrInterfaceDeclaration typeDeclaration +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 891) = currentChild.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); + 892) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 893) if (typeDeclaration != null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 894) currentChild.setTypeDefinition(typeDeclaration.getTypeDefinition()); +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 895) } +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 896) } + 897) +0ec1e44b1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 18:23:11 +0000 898) // Last token, because if 'super' is a Suffix, it'll have tokens '.' and 'super' +0ec1e44b1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 18:23:11 +0000 899) } else if (currentChild.jjtGetLastToken().toString().equals("super")) { + 900) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 901) if (previousChild != null) { // Qualified 'super' expression +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 902) // anonymous classes can't have qualified super expression, thus +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 903) // getSuperClassTypeDefinition's second argumet isn't null, but we are not +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 904) // looking for enclosing super types +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 905) currentChild.setTypeDefinition( +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 906) getSuperClassTypeDefinition(currentChild, previousChild.getType())); +0ec1e44b1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 18:23:11 +0000 907) } else { // simple 'super' expression +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 908) currentChild.setTypeDefinition(getSuperClassTypeDefinition(currentChild, null)); +0ec1e44b1 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 18:23:11 +0000 909) } + 910) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 911) } else if (currentChild.getFirstChildOfType(ASTArguments.class) != null) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 912) currentChild.setTypeDefinition(previousChild.getTypeDefinition()); +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 913) } else if (previousChild != null && previousChild.getType() != null) { +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 914) String currentChildImage = currentChild.getImage(); +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 915) if (currentChildImage == null) { +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 916) // this.foo(); foo would be in a Suffix and would have a null image +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 917) currentChildImage = currentChild.jjtGetLastToken().toString(); +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 918) } + 919) +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 920) ASTArguments astArguments = nextChild != null +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 921) ? nextChild.getFirstChildOfType(ASTArguments.class) : null; + 922) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 923) if (astArguments != null) { // method +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 924) ASTArgumentList astArgumentList = getArgumentList(astArguments); +60f6935f8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:25:51 +0000 925) int methodArgsArity = getArgumentListArity(astArgumentList); +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 926) List typeArguments = getMethodExplicitTypeArugments(currentChild); + 927) +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 928) List methods = getApplicableMethods(previousChild.getTypeDefinition(), +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 929) currentChildImage, +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 930) typeArguments, methodArgsArity, accessingClass); + 931) +90b802526 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 932) currentChild.setTypeDefinition(getBestMethodReturnType(previousChild.getTypeDefinition(), +90b802526 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-15 22:02:34 +0000 933) methods, astArgumentList)); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 934) } else { // field +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 935) currentChild.setTypeDefinition(getFieldType(previousChild.getTypeDefinition(), +995933889 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-27 14:50:50 +0000 936) currentChildImage, accessingClass)); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 937) } +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 938) } +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 939) } + 940) + 941) +f4ec16338 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-03 22:28:38 +0000 942) if (currentChild.getType() != null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 943) primaryNodeType = currentChild.getTypeDefinition(); +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 944) } else { +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 945) // avoid falsely passing tests +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 946) primaryNodeType = null; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 947) break; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 948) } + 949) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 950) previousChild = currentChild; +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 951) } + 952) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 953) primaryNode.setTypeDefinition(primaryNodeType); + 954) +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 955) return data; +babe32a16 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-05-30 15:37:47 +0000 956) } + 957) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 958) /** +ed9b015c9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 11:57:50 +0000 959) * Returns the the first Class declaration around the node. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 960) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 961) * @param node The node with the enclosing Class declaration. +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 962) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 963) * @return The JavaTypeDefinition of the enclosing Class declaration. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 964) */ +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 965) private TypeNode getEnclosingTypeDeclaration(Node node) { +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 966) Node previousNode = null; + 967) +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 968) while (node != null) { +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 969) if (node instanceof ASTClassOrInterfaceDeclaration) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 970) return (TypeNode) node; +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 971) // anonymous class declaration +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 972) } else if (node instanceof ASTAllocationExpression // is anonymous class declaration +ed9b015c9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 11:57:50 +0000 973) && node.getFirstChildOfType(ASTArrayDimsAndInits.class) == null // array cant be anonymous +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 974) && !(previousNode instanceof ASTArguments)) { // we might come out of the constructor +ed9b015c9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-05 11:57:50 +0000 975) return (TypeNode) node; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 976) } + 977) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 978) previousNode = node; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 979) node = node.jjtGetParent(); +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 980) } + 981) +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 982) return null; +41ed666d4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 16:11:20 +0000 983) } + 984) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 985) private Class getEnclosingTypeDeclarationClass(Node node) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 986) TypeNode typeDecl = getEnclosingTypeDeclaration(node); + 987) +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 988) if (typeDecl == null) { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 989) return null; +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 990) } else { +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 991) return typeDecl.getType(); +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 992) } +35597c9ef pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-03 22:06:32 +0000 993) } + 994) + 995) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 996) /** +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 997) * Get the type def. of the super class of the enclosing type declaration which has the same class +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 998) * as the second argument, or if the second argument is null, then anonymous classes are considered +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 999) * as well and the first enclosing scope's super class is returned. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1000) * +f1d315ff4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-23 18:34:45 +0000 1001) * @param node The node from which to start searching. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1002) * @param clazz The type of the enclosing class. +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1003) * +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1004) * @return The TypeDefinition of the superclass. +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1005) */ +46daa878b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-19 22:18:21 +0000 1006) private JavaTypeDefinition getSuperClassTypeDefinition(Node node, Class clazz) { +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1007) Node previousNode = null; +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1008) for (; node != null; previousNode = node, node = node.jjtGetParent()) { +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1009) if (node instanceof ASTClassOrInterfaceDeclaration // class declaration +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1010) // is the class we are looking for or caller requested first class +46daa878b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-19 22:18:21 +0000 1011) && (((TypeNode) node).getType() == clazz || clazz == null)) { + 1012) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1013) ASTExtendsList extendsList = node.getFirstChildOfType(ASTExtendsList.class); + 1014) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1015) if (extendsList != null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1016) return ((TypeNode) extendsList.jjtGetChild(0)).getTypeDefinition(); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1017) } else { +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 1018) return JavaTypeDefinition.forClass(Object.class); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1019) } +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 1020) // anonymous class declaration + 1021) +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1022) } else if (clazz == null // callers requested any class scope +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1023) && node instanceof ASTAllocationExpression // is anonymous class decl +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1024) && node.getFirstChildOfType(ASTArrayDimsAndInits.class) == null // arrays can't be anonymous +4175460d3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 13:42:22 +0000 1025) && !(previousNode instanceof ASTArguments)) { // we might come out of the constructor +b8e1738f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-15 00:48:15 +0000 1026) return node.getFirstChildOfType(ASTClassOrInterfaceType.class).getTypeDefinition(); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1027) } +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1028) } + 1029) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1030) return null; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1031) } + 1032) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1033) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1034) public Object visit(ASTPrimaryPrefix node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1035) super.visit(node, data); +065423d61 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 00:15:04 +0000 1036) rollupTypeUnary(node); + 1037) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1038) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1039) } + 1040) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1041) @Override +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1042) public Object visit(ASTTypeArgument node, Object data) { +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1043) if (node.jjtGetNumChildren() == 0) { // if type argument is '?' +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1044) node.setTypeDefinition(JavaTypeDefinition.forClass(UPPER_WILDCARD, Object.class)); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1045) } else { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1046) super.visit(node, data); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1047) rollupTypeUnary(node); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1048) } + 1049) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1050) return data; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1051) } + 1052) +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1053) @Override +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1054) public Object visit(ASTWildcardBounds node, Object data) { +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1055) super.visit(node, data); + 1056) +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1057) JavaTypeDefinition childType = node.getTypeBoundNode().getTypeDefinition(); + 1058) +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1059) if (node.isLowerBound()) { +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1060) node.setTypeDefinition(JavaTypeDefinition.forClass(LOWER_WILDCARD, childType)); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1061) } else { // upper bound +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1062) node.setTypeDefinition(JavaTypeDefinition.forClass(UPPER_WILDCARD, childType)); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1063) } + 1064) +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1065) return data; +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1066) } + 1067) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1068) @Override +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1069) public Object visit(ASTTypeParameters node, Object data) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1070) super.visit(node, data); + 1071) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1072) if (node.jjtGetParent() instanceof ASTClassOrInterfaceDeclaration) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1073) TypeNode parent = (TypeNode) node.jjtGetParent(); + 1074) +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 1075) final JavaTypeDefinition[] boundGenerics = new JavaTypeDefinition[node.jjtGetNumChildren()]; +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1076) int i = 0; +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1077) for (ASTTypeParameter arg : node) { +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1078) boundGenerics[i++] = arg.getTypeDefinition(); +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1079) } + 1080) +3bd69b15f pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-06-29 23:16:23 +0000 1081) parent.setTypeDefinition(JavaTypeDefinition.forClass(parent.getType(), boundGenerics)); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1082) } + 1083) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1084) return data; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1085) } + 1086) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1087) @Override +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1088) public Object visit(ASTTypeParameter node, Object data) { +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1089) if (!node.hasTypeBound()) { // type parameter doesn't have declared upper bounds +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1090) node.setTypeDefinition(JavaTypeDefinition.forClass(UPPER_BOUND, Object.class)); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1091) } else { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1092) super.visit(node, data); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1093) rollupTypeUnary(node); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1094) } + 1095) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1096) return data; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1097) } + 1098) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1099) @Override +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1100) public Object visit(ASTTypeBound node, Object data) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1101) super.visit(node, data); + 1102) +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1103) List typeNodes = node.getBoundTypeNodes(); + 1104) +b517838fb pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2017-10-04 19:09:49 +0000 1105) // TypeBound will have at least one child, but maybe more +b517838fb pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2017-10-04 19:09:49 +0000 1106) JavaTypeDefinition[] bounds = new JavaTypeDefinition[typeNodes.size()]; +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1107) int i = 0; +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1108) for (ASTClassOrInterfaceType bound : typeNodes) { +80e27d049 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-06-26 10:21:22 +0000 1109) bounds[i++] = bound.getTypeDefinition(); +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1110) } + 1111) +186d0edd9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-08-24 20:10:17 +0000 1112) node.setTypeDefinition(JavaTypeDefinition.forClass(UPPER_BOUND, bounds)); + 1113) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1114) return data; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1115) } + 1116) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1117) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1118) public Object visit(ASTNullLiteral node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1119) // No explicit type +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1120) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1121) } + 1122) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1123) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1124) public Object visit(ASTBooleanLiteral node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1125) populateType(node, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1126) return super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1127) } + 1128) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1129) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1130) public Object visit(ASTLiteral node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1131) super.visit(node, data); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1132) if (node.jjtGetNumChildren() != 0) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1133) rollupTypeUnary(node); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1134) } else { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1135) if (node.isIntLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1136) populateType(node, "int"); +6ee75a9e6 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-08-07 19:21:05 +0000 1137) } else if (node.isLongLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1138) populateType(node, "long"); +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1139) } else if (node.isFloatLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1140) populateType(node, "float"); +6ee75a9e6 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2014-08-07 19:21:05 +0000 1141) } else if (node.isDoubleLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1142) populateType(node, "double"); +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1143) } else if (node.isCharLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1144) populateType(node, "char"); +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1145) } else if (node.isStringLiteral()) { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1146) populateType(node, "java.lang.String"); +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1147) } else { +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1148) throw new IllegalStateException("PMD error, unknown literal type!"); +65c6faf51 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 08:40:13 +0000 1149) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1150) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1151) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1152) } + 1153) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1154) @Override +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1155) public Object visit(ASTAllocationExpression node, Object data) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1156) super.visit(node, data); + 1157) +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1158) final ASTArrayDimsAndInits dims = node.getFirstChildOfType(ASTArrayDimsAndInits.class); +1d02c24b3 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 03:08:26 +0000 1159) if (dims != null) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1160) final JavaTypeDefinition elementType = ((TypeNode) node.jjtGetChild(0)).getTypeDefinition(); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1161) if (elementType != null) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1162) node.setTypeDefinition(elementType.withDimensions(dims.getArrayDepth())); +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1163) } +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1164) } else { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1165) rollupTypeUnary(node); +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1166) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1167) return data; +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1168) } + 1169) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1170) @Override +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1171) public Object visit(ASTStatementExpression node, Object data) { +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1172) super.visit(node, data); +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1173) rollupTypeUnary(node); +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1174) return data; +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1175) } + 1176) + 1177) +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1178) @Override +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1179) public Object visit(ASTFormalParameter node, Object data) { +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1180) super.visit(node, data); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1181) JavaTypeDefinition varType = node.getVariableDeclaratorId().getTypeDefinition(); + 1182) +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1183) if (varType != null) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1184) if (node.isVarargs()) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1185) // The type of the formal parameter is defined in terms of the type +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1186) // of the declarator ID +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1187) node.getVariableDeclaratorId().setTypeDefinition(varType.withDimensions(1)); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1188) } +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1189) } +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1190) return data; +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1191) } + 1192) + 1193) +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1194) @Override +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1195) public Object visit(ASTAnnotation node, Object data) { +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1196) super.visit(node, data); +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1197) rollupTypeUnary(node); +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1198) return data; +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1199) } + 1200) +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1201) @Override +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1202) public Object visit(ASTNormalAnnotation node, Object data) { +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1203) super.visit(node, data); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1204) rollupTypeUnary(node); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1205) return data; +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1206) } + 1207) +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1208) @Override +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1209) public Object visit(ASTMarkerAnnotation node, Object data) { +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1210) super.visit(node, data); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1211) rollupTypeUnary(node); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1212) return data; +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1213) } + 1214) +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1215) @Override +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1216) public Object visit(ASTSingleMemberAnnotation node, Object data) { +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1217) super.visit(node, data); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1218) rollupTypeUnary(node); +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1219) return data; +d7bdb79cd pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-17 08:56:02 +0000 1220) } + 1221) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1222) // Roll up the type based on type of the first child node. +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1223) private void rollupTypeUnary(TypeNode typeNode) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1224) if (typeNode.jjtGetNumChildren() >= 1) { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1225) Node child = typeNode.jjtGetChild(0); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1226) if (child instanceof TypeNode) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1227) typeNode.setTypeDefinition(((TypeNode) child).getTypeDefinition()); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1228) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1229) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1230) } + 1231) +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1232) // Roll up the type based on type of the first child node using Unary +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1233) // Numeric Promotion per JLS 5.6.1 +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1234) private void rollupTypeUnaryNumericPromotion(TypeNode typeNode) { +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 1235) Node node = typeNode; +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 1236) if (node.jjtGetNumChildren() >= 1) { +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 1237) Node child = node.jjtGetChild(0); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1238) if (child instanceof TypeNode) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1239) Class type = ((TypeNode) child).getType(); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1240) if (type != null) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1241) if ("byte".equals(type.getName()) || "short".equals(type.getName()) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1242) || "char".equals(type.getName())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1243) populateType(typeNode, "int"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1244) } else { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1245) typeNode.setType(((TypeNode) child).getType()); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1246) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1247) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1248) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1249) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1250) } + 1251) +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1252) // Roll up the type based on type of the first and second child nodes using +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1253) // Binary Numeric Promotion per JLS 5.6.2 +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1254) private void rollupTypeBinaryNumericPromotion(TypeNode typeNode) { +b78c7f2aa pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-29 21:11:44 +0000 1255) Node node = typeNode; +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 1256) if (node.jjtGetNumChildren() >= 2) { +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 1257) Node child1 = node.jjtGetChild(0); +113e719ad pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-04-04 03:51:12 +0000 1258) Node child2 = node.jjtGetChild(1); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1259) if (child1 instanceof TypeNode && child2 instanceof TypeNode) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1260) Class type1 = ((TypeNode) child1).getType(); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1261) Class type2 = ((TypeNode) child2).getType(); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1262) if (type1 != null && type2 != null) { +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1263) // Yeah, String is not numeric, but easiest place to handle +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1264) // it, only affects ASTAdditiveExpression +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1265) if ("java.lang.String".equals(type1.getName()) || "java.lang.String".equals(type2.getName())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1266) populateType(typeNode, "java.lang.String"); +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1267) } else if ("boolean".equals(type1.getName()) || "boolean".equals(type2.getName())) { +7b7f85463 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:09:35 +0000 1268) populateType(typeNode, "boolean"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1269) } else if ("double".equals(type1.getName()) || "double".equals(type2.getName())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1270) populateType(typeNode, "double"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1271) } else if ("float".equals(type1.getName()) || "float".equals(type2.getName())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1272) populateType(typeNode, "float"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1273) } else if ("long".equals(type1.getName()) || "long".equals(type2.getName())) { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1274) populateType(typeNode, "long"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1275) } else { +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1276) populateType(typeNode, "int"); +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1277) } +065423d61 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 00:15:04 +0000 1278) } else if (type1 != null || type2 != null) { +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1279) // If one side is known to be a String, then the result is a +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1280) // String +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1281) // Yeah, String is not numeric, but easiest place to handle +2680c33d8 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 10:32:06 +0000 1282) // it, only affects ASTAdditiveExpression +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1283) if (type1 != null && "java.lang.String".equals(type1.getName()) +de9c2b0e3 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2008-06-22 18:07:30 +0000 1284) || type2 != null && "java.lang.String".equals(type2.getName())) { +065423d61 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 00:15:04 +0000 1285) populateType(typeNode, "java.lang.String"); +065423d61 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 00:15:04 +0000 1286) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1287) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1288) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1289) } +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1290) } + 1291) +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1292) private void populateType(TypeNode node, String className) { +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1293) populateType(node, className, 0); +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1294) } + 1295) +05927af57 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-27 01:31:29 +0000 1296) private void populateType(TypeNode node, String className, int arrayDimens) { + 1297) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1298) String qualifiedName = className; +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 1299) Class myType = PRIMITIVE_TYPES.get(className); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1300) if (myType == null && importedClasses != null) { +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1301) if (importedClasses.containsKey(className)) { +516c08165 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Xavier Le Vourch 2007-01-27 01:14:44 +0000 1302) qualifiedName = importedClasses.get(className); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1303) } else if (importedClasses.containsValue(className)) { +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1304) qualifiedName = className; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1305) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1306) if (qualifiedName != null) { +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1307) try { +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1308) /* +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1309) * TODO - the map right now contains just class names. if we +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1310) * use a map of classname/class then we don't have to hit +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1311) * the class loader for every type - much faster +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1312) */ +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1313) myType = pmdClassLoader.loadClass(qualifiedName); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1314) } catch (ClassNotFoundException e) { +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1315) myType = processOnDemand(qualifiedName); +b172c19de pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (rsalvador 2012-11-27 21:17:15 +0000 1316) } catch (LinkageError e) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1317) // we found the class, but there is a problem with it (see https://github.com/pmd/pmd/issues/1131) +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1318) if (LOG.isLoggable(Level.FINE)) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1319) LOG.log(Level.FINE, "Tried to load class " + qualifiedName + " from on demand import, " +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1320) + "with an incomplete classpath.", e); +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1321) } +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1322) return; +a11337cab pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-06 02:35:36 +0000 1323) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1324) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1325) } +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1326) if (myType == null && qualifiedName != null && qualifiedName.contains(".")) { +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1327) // try if the last part defines a inner class +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1328) String qualifiedNameInner = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')) + "$" +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1329) + qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1330) try { +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1331) myType = pmdClassLoader.loadClass(qualifiedNameInner); +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1332) } catch (ClassNotFoundException ignored) { +f3a358c41 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-03-09 08:58:04 +0000 1333) // ignored, we'll try again with a different package name/fqcn +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1334) } catch (LinkageError e) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1335) // we found the class, but there is a problem with it (see https://github.com/pmd/pmd/issues/1131) +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1336) if (LOG.isLoggable(Level.FINE)) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1337) LOG.log(Level.FINE, "Tried to load class " + qualifiedNameInner + " from on demand import, " +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1338) + "with an incomplete classpath.", e); +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1339) } +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1340) return; +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1341) } +88477e3f5 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-11-20 10:23:25 +0000 1342) } +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1343) if (myType == null && qualifiedName != null && !qualifiedName.contains(".")) { +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1344) // try again with java.lang.... +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1345) try { +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1346) myType = pmdClassLoader.loadClass("java.lang." + qualifiedName); +f3a358c41 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-03-09 08:58:04 +0000 1347) } catch (Exception ignored) { +f3a358c41 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-03-09 08:58:04 +0000 1348) // ignored, we'll try again with generics +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1349) } +f0d8759b7 pmd/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2013-03-30 14:04:47 +0000 1350) } + 1351) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1352) // try generics +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1353) // TODO: generic declarations can shadow type declarations ... :( +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1354) if (myType == null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1355) ASTTypeParameter parameter = getTypeParameterDeclaration(node, className); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1356) if (parameter != null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1357) node.setTypeDefinition(parameter.getTypeDefinition()); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1358) } +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1359) } else { +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1360) JavaTypeDefinition def = JavaTypeDefinition.forClass(myType); +7d46c453c pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-04-28 18:53:46 +0000 1361) node.setTypeDefinition(def.withDimensions(arrayDimens)); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1362) } +acc05d4c9 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2017-10-06 16:05:27 +0000 1363) } + 1364) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1365) private ASTTypeParameter getTypeParameterDeclaration(Node startNode, String image) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1366) for (Node parent = startNode.jjtGetParent(); parent != null; parent = parent.jjtGetParent()) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1367) ASTTypeParameters typeParameters = null; + 1368) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1369) if (parent instanceof ASTTypeParameters) { // if type parameter defined in the same < > +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1370) typeParameters = (ASTTypeParameters) parent; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1371) } else if (parent instanceof ASTConstructorDeclaration +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1372) || parent instanceof ASTMethodDeclaration +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1373) || parent instanceof ASTClassOrInterfaceDeclaration) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1374) typeParameters = parent.getFirstChildOfType(ASTTypeParameters.class); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1375) } + 1376) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1377) if (typeParameters != null) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1378) for (int index = 0; index < typeParameters.jjtGetNumChildren(); ++index) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1379) String imageToCompareTo = typeParameters.jjtGetChild(index).getImage(); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1380) if (imageToCompareTo != null && imageToCompareTo.equals(image)) { +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1381) return (ASTTypeParameter) typeParameters.jjtGetChild(index); +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1382) } +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1383) } +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1384) } +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1385) } + 1386) +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1387) return null; +68c8fabdf pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-06-14 22:55:55 +0000 1388) } + 1389) +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1390) /** +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1391) * Check whether the supplied class name exists. +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1392) */ +00249eb78 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-02-28 09:34:24 +0000 1393) public boolean classNameExists(String fullyQualifiedClassName) { +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1394) try { +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1395) pmdClassLoader.loadClass(fullyQualifiedClassName); +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1396) return true; // Class found +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1397) } catch (ClassNotFoundException e) { +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1398) return false; +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1399) } catch (LinkageError e2) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1400) // Class exists, but may be invalid (see https://github.com/pmd/pmd/issues/1131) +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1401) return true; +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1402) } +411540708 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-10-15 14:20:26 +0000 1403) } + 1404) +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1405) public Class loadClass(String fullyQualifiedClassName) { +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1406) try { +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1407) return pmdClassLoader.loadClass(fullyQualifiedClassName); +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1408) } catch (ClassNotFoundException e) { +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1409) return null; +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1410) } catch (LinkageError e2) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1411) if (LOG.isLoggable(Level.FINE)) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1412) LOG.log(Level.FINE, "Tried to load class " + fullyQualifiedClassName + " from on demand import, " +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1413) + "with an incomplete classpath.", e2); +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1414) } +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1415) return null; +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1416) } +9522ab3cd pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2015-01-22 18:30:20 +0000 1417) } + 1418) +40a46d11a pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-03-05 06:36:33 +0000 1419) private Class processOnDemand(String qualifiedName) { +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1420) for (String entry : importedOnDemand) { +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1421) String fullClassName = entry + "." + qualifiedName; +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1422) try { +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1423) return pmdClassLoader.loadClass(fullClassName); +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1424) } catch (ClassNotFoundException ignored) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1425) // ignored +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1426) } catch (LinkageError e) { +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1427) if (LOG.isLoggable(Level.FINE)) { +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1428) LOG.log(Level.FINE, "Tried to load class " + fullClassName + " from on demand import, " +3c6a29240 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-05-28 19:28:12 +0000 1429) + "with an incomplete classpath.", e); +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1430) } +d6213b79b pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-24 21:54:37 +0000 1431) } +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1432) } +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1433) return null; +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1434) } + 1435) +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 1436) private String getClassName(ASTCompilationUnit node) { +f4441ce93 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-03-11 09:15:28 +0000 1437) ASTAnyTypeDeclaration classDecl = node.getFirstDescendantOfType(ASTAnyTypeDeclaration.class); +8674cb4b1 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-19 03:06:34 +0000 1438) if (classDecl == null) { +f4441ce93 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2018-03-11 09:15:28 +0000 1439) // package-info.java? +fbadbcbe5 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-18 21:47:48 +0000 1440) return null; +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1441) } + 1442) + 1443) +8674cb4b1 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-19 03:06:34 +0000 1444) if (node.declarationsAreInDefaultPackage()) { +8674cb4b1 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-19 03:06:34 +0000 1445) return classDecl.getImage(); +8674cb4b1 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-19 03:06:34 +0000 1446) } +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 1447) importedOnDemand.add(node.getPackageDeclaration().getPackageNameImage()); +ccc144337 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Clément Fournier 2018-03-19 13:25:00 +0000 1448) return classDecl.getQualifiedName().toString(); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1449) } + 1450) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1451) /** +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1452) * If the outer class wasn't found then we'll get in here +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1453) * +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1454) * @param node +0ebcac070 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Andreas Dangel 2016-12-02 09:21:27 +0000 1455) */ +f0acb0aea pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-21 12:35:52 +0000 1456) private void populateImports(ASTCompilationUnit node) { +bfc8b24bd pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-01-29 18:09:16 +0000 1457) List theImportDeclarations = node.findChildrenOfType(ASTImportDeclaration.class); + 1458) +e0a5913f8 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2008-06-30 06:28:58 +0000 1459) importedClasses.putAll(JAVA_LANG); + 1460) +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1461) // go through the imports +bfc8b24bd pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-01-29 18:09:16 +0000 1462) for (ASTImportDeclaration anImportDeclaration : theImportDeclarations) { +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1463) String strPackage = anImportDeclaration.getPackageName(); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1464) if (anImportDeclaration.isStatic()) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1465) if (anImportDeclaration.isImportOnDemand()) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1466) importOnDemandStaticClasses.add(JavaTypeDefinition.forClass(loadClass(strPackage))); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1467) } else { // not import on-demand +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1468) String strName = anImportDeclaration.getImportedName(); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1469) String fieldName = strName.substring(strName.lastIndexOf('.') + 1); + 1470) +dbe016886 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Juan Martín Sotuyo Dodero 2017-10-10 15:08:52 +0000 1471) Class staticClassWithField = loadClass(strPackage); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1472) if (staticClassWithField != null) { +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1473) JavaTypeDefinition typeDef = getFieldType(JavaTypeDefinition.forClass(staticClassWithField), +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1474) fieldName, currentAcu.getType()); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1475) staticFieldImageToTypeDef.put(fieldName, typeDef); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1476) } + 1477) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1478) List typeList = staticNamesToClasses.get(fieldName); + 1479) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1480) if (typeList == null) { +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1481) typeList = new ArrayList<>(); +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1482) } + 1483) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1484) typeList.add(JavaTypeDefinition.forClass(staticClassWithField)); + 1485) +2146a077e pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-24 17:38:08 +0000 1486) staticNamesToClasses.put(fieldName, typeList); +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1487) } +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1488) } else { // non-static +ad46a291e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Wouter Zelle 2007-04-16 22:16:41 +0000 1489) if (anImportDeclaration.isImportOnDemand()) { +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1490) importedOnDemand.add(strPackage); +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1491) } else { // not import on-demand +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1492) String strName = anImportDeclaration.getImportedName(); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1493) importedClasses.put(strName, strName); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1494) importedClasses.put(strName.substring(strPackage.length() + 1), strName); +881218544 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-02-03 12:48:12 +0000 1495) } +800cfa6e4 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Bendegúz Nagy 2017-07-19 19:22:09 +0000 1496) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1497) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1498) } + 1499) + 1500) +3bbc6575e pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2007-08-28 21:01:03 +0000 1501) private void populateClassName(ASTCompilationUnit node, String className) throws ClassNotFoundException { +40501042c pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Tom Copeland 2007-11-21 03:57:32 +0000 1502) node.setType(pmdClassLoader.loadClass(className)); +3aedf63a9 pmd/src/net/sourceforge/pmd/lang/java/typeresolution/ClassTypeResolver.java (Ryan Gustafson 2009-11-27 18:10:15 +0000 1503) importedClasses.putAll(pmdClassLoader.getImportedClasses(className)); +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1504) } +6215d97b9 pmd/src/net/sourceforge/pmd/typeresolution/ClassTypeResolver.java (Allan Caplan 2006-10-26 02:35:38 +0000 1505) }