Skip to content
Snippets Groups Projects
Commit ffbd4c9c authored by Johannes Mey's avatar Johannes Mey
Browse files

fixed package check, adapted tests (please check!). test now always require...

fixed package check, adapted tests (please check!). test now always require (part of the) file name, ask me why!
parent 5c9d40c3
No related branches found
No related tags found
No related merge requests found
...@@ -18,11 +18,11 @@ aspect ProgramToScopeTree { ...@@ -18,11 +18,11 @@ aspect ProgramToScopeTree {
to ASTNode.scope() to ASTNode.scope()
for containingScope(); for containingScope();
ClassDecl contributes protectedScope() ClassDecl contributes protectedScope()
when !isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource() && !accessibleFromPackage(superclass().hostPackage()) when !isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource() && !hostPackage().equals(superclass().hostPackage())
to ClassDecl.protectedScope() to ClassDecl.protectedScope()
for superclass(); for superclass();
ClassDecl contributes protectedScope() ClassDecl contributes protectedScope()
when !isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource() && accessibleFromPackage(superclass().hostPackage()) when !isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource() && hostPackage().equals(superclass().hostPackage())
to ClassDecl.packageScope() to ClassDecl.packageScope()
for superclass(); for superclass();
Block contributes scope() to ASTNode.scope() for containingScope(); Block contributes scope() to ASTNode.scope() for containingScope();
......
...@@ -17,24 +17,24 @@ public class InnerTest extends ScopeAnalysisTest { ...@@ -17,24 +17,24 @@ public class InnerTest extends ScopeAnalysisTest {
System.out.println(findings); System.out.println(findings);
// anonymous class // anonymous class
assertShadow(findings, "fieldA", 11, 13); assertShadow(findings, "fieldA", "ClassA", 11, "ClassA", 13);
assertShadow(findings, "fieldA", 13, 3); assertShadow(findings, "fieldA", "ClassA", 13, "ClassA", 3);
// local inner class // local inner class
assertShadow(findings, "fieldA", 27, 29); assertShadow(findings, "fieldA", "ClassA", 27, "ClassA", 29);
assertShadow(findings, "fieldA", 29, 3); assertShadow(findings, "fieldA", "ClassA", 29, "ClassA", 3);
assertShadow(findings, "changingVar", 25, 19); assertShadow(findings, "changingVar", "ClassA", 25, "ClassA", 19);
// static member class // static member class
assertShadow(findings, "fieldA", 37, 35); assertShadow(findings, "fieldA", "ClassA", 37, "ClassA", 35);
assertShadow(findings, "fieldA", 35, 3); assertShadow(findings, "fieldA", "ClassA", 35, "ClassA", 3);
// member class // member class
assertShadow(findings, "fieldA", 44, 42); assertShadow(findings, "fieldA", "ClassA", 44, "ClassA", 42);
assertShadow(findings, "fieldA", 42, 3); assertShadow(findings, "fieldA", "ClassA", 42, "ClassA", 3);
// anonymous class defined in other class // anonymous class defined in other class
assertShadow(findings, "fieldB", 5, 10); assertShadow(findings, "fieldB", "ClassB", 5, "ClassB", 10);
// this finding is currently not found // this finding is currently not found
// assertShadow(findings, "fieldB", 10, 4); // assertShadow(findings, "fieldB", 10, 4);
......
...@@ -78,20 +78,20 @@ public class ProtectedTest extends ScopeAnalysisTest { ...@@ -78,20 +78,20 @@ public class ProtectedTest extends ScopeAnalysisTest {
assertShadow(findings, "fProtected", classD, 15, classA, 11); assertShadow(findings, "fProtected", classD, 15, classA, 11);
assertShadow(findings, "fPublic", classD, 16, classA, 12); assertShadow(findings, "fPublic", classD, 16, classA, 12);
// D.D() // D.D()
assertShadow(findings, "fPrivate", classD, 19, classA, 13); assertNotShadow(findings, "fPrivate", classD, 19, classA, 9); // true, but not helpful
assertShadow(findings, "fPackage", classD, 20, classA, 14); assertNotShadow(findings, "fPackage", classD, 20, classA, 10); // true, but not helpful
assertShadow(findings, "fProtected", classD, 21, classA, 15); assertShadow(findings, "fProtected", classD, 21, classD, 15);
assertShadow(findings, "fPublic", classD, 22, classA, 16); assertShadow(findings, "fPublic", classD, 22, classD, 16);
// D.foo() // D.foo()
assertShadow(findings, "fPrivate", classD, 26, classA, 13); assertNotShadow(findings, "fPrivate", classD, 26, classA, 9); // true, but not helpful
assertShadow(findings, "fPackage", classD, 27, classA, 14); assertNotShadow(findings, "fPackage", classD, 27, classA, 10); // true, but not helpful
assertShadow(findings, "fProtected", classD, 28, classA, 15); assertShadow(findings, "fProtected", classD, 28, classD, 15);
assertShadow(findings, "fPublic", classD, 29, classA, 16); assertShadow(findings, "fPublic", classD, 29, classD, 16);
// D.bar() // D.bar()
assertShadow(findings, "fPrivate", classD, 32, classA, 13); assertNotShadow(findings, "fPrivate", classD, 32, classA, 9); // true, but not helpful
assertShadow(findings, "fPackage", classD, 33, classA, 14); assertNotShadow(findings, "fPackage", classD, 33, classA, 10); // true, but not helpful
assertShadow(findings, "fProtected", classD, 34, classA, 15); assertShadow(findings, "fProtected", classD, 34, classD, 15);
assertShadow(findings, "fPublic", classD, 35, classA, 16); assertShadow(findings, "fPublic", classD, 35, classD, 16);
// within class E // within class E
// E.E() // E.E()
......
...@@ -23,22 +23,13 @@ public abstract class ScopeAnalysisTest { ...@@ -23,22 +23,13 @@ public abstract class ScopeAnalysisTest {
Assertions.fail(failMessage.get()); Assertions.fail(failMessage.get());
} }
static void assertShadow(Set<AbstractFinding> findings, String name, int shadowerLine, int shadowedLine) {
assertShadow(findings,
(shadower, shadowed) ->
shadowed.getName().equals(name) &&
shadowed.lineNumber() == shadowedLine &&
shadower.lineNumber() == shadowerLine,
() -> "No shadow finding found for name '" + name + "' in lines " + shadowerLine + " > " + shadowedLine);
}
static void assertShadow(Set<AbstractFinding> findings, String name, String shadowerSourceFile, int shadowerLine, String shadowedSourceFile, int shadowedLine) { static void assertShadow(Set<AbstractFinding> findings, String name, String shadowerSourceFile, int shadowerLine, String shadowedSourceFile, int shadowedLine) {
assertShadow(findings, assertShadow(findings,
(shadower, shadowed) -> (shadower, shadowed) ->
shadowed.getName().equals(name) && shadowed.getName().equals(name) &&
shadowed.sourceFile().equals(shadowedSourceFile) && shadowed.sourceFile().contains(shadowedSourceFile) &&
shadowed.lineNumber() == shadowedLine && shadowed.lineNumber() == shadowedLine &&
shadower.sourceFile().equals(shadowerSourceFile) && shadower.sourceFile().contains(shadowerSourceFile) &&
shadower.lineNumber() == shadowerLine, shadower.lineNumber() == shadowerLine,
() -> "No shadow finding found for name '" + name + "' in " +shadowerSourceFile + ":" + shadowerLine + " > " + shadowedSourceFile + ":" + shadowedLine); () -> "No shadow finding found for name '" + name + "' in " +shadowerSourceFile + ":" + shadowerLine + " > " + shadowedSourceFile + ":" + shadowedLine);
} }
...@@ -55,18 +46,9 @@ public abstract class ScopeAnalysisTest { ...@@ -55,18 +46,9 @@ public abstract class ScopeAnalysisTest {
Assertions.fail("No multi-decl finding found for name '" + name + "' in line " + declLine); Assertions.fail("No multi-decl finding found for name '" + name + "' in line " + declLine);
} }
static void assertNotShadow(Set<AbstractFinding> findings, String name, int shadowerLine, int shadowedLine) {
try {
assertShadow(findings, name, shadowerLine, shadowedLine);
} catch (AssertionError e) {
return;
}
Assertions.fail("There should not be a shadow finding for name '" + name + "' in lines " + shadowerLine + " > " + shadowedLine);
}
static void assertNotShadow(Set<AbstractFinding> findings, String name, String shadowerSourceFile, int shadowerLine, String shadowedSourceFile, int shadowedLine) { static void assertNotShadow(Set<AbstractFinding> findings, String name, String shadowerSourceFile, int shadowerLine, String shadowedSourceFile, int shadowedLine) {
try { try {
assertShadow(findings, name, shadowerLine, shadowedLine); assertShadow(findings, name, shadowerSourceFile, shadowerLine, shadowedSourceFile, shadowedLine);
} catch (AssertionError e) { } catch (AssertionError e) {
return; return;
} }
......
...@@ -14,11 +14,11 @@ public class SimpleScopeTest extends ScopeAnalysisTest { ...@@ -14,11 +14,11 @@ public class SimpleScopeTest extends ScopeAnalysisTest {
ScopeAnalysis scopeAnalysis = new ScopeAnalysis(); ScopeAnalysis scopeAnalysis = new ScopeAnalysis();
Set<AbstractFinding> findings = scopeAnalysis.analyze("src/test/resources/simple", true, false); Set<AbstractFinding> findings = scopeAnalysis.analyze("src/test/resources/simple", true, false);
assertShadow(findings, "localVarA", 19, 11); assertShadow(findings, "localVarA", "ClassA", 19, "ClassA", 11);
assertShadow(findings, "localVarB", 33, 12); assertShadow(findings, "localVarB", "ClassA", 33, "ClassA", 12);
assertShadow(findings, "localVarC", 24, 13); assertShadow(findings, "localVarC", "ClassA", 24, "ClassA", 13);
assertShadow(findings, "fieldA", 29, 3); assertShadow(findings, "fieldA", "ClassA", 29, "ClassA", 3);
assertShadow(findings, "fieldB", 36, 4); assertShadow(findings, "fieldB", "ClassA", 36, "ClassA", 4);
Assertions.assertEquals(5, findings.size()); Assertions.assertEquals(5, findings.size());
} }
......
...@@ -16,9 +16,9 @@ public class SuperclassFieldsTest extends ScopeAnalysisTest { ...@@ -16,9 +16,9 @@ public class SuperclassFieldsTest extends ScopeAnalysisTest {
Set<AbstractFinding> findings = scopeAnalysis.analyze("src/test/resources/superclassFields", false, false); Set<AbstractFinding> findings = scopeAnalysis.analyze("src/test/resources/superclassFields", false, false);
assertShadow(findings, "fieldC", 19, 3); assertShadow(findings, "fieldC", "ClassB", 19, "ClassB", 3);
assertShadow(findings, "fieldB", 21, 2); assertShadow(findings, "fieldB", "ClassB", 21, "ClassB", 2);
assertShadow(findings, "fieldB", 2, 4); assertShadow(findings, "fieldB", "ClassB", 2, "ClassA", 4);
Assertions.assertEquals(3, findings.size()); Assertions.assertEquals(3, findings.size());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment