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

work in progress

parent 62207526
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,9 @@ aspect ProgramToScopeTree { ...@@ -18,7 +18,9 @@ aspect ProgramToScopeTree {
Block contributes scope() to ASTNode.scope() for containingScope(); Block contributes scope() to ASTNode.scope() for containingScope();
// collect all elements // collect all elements
// TODO exclude declarators not in statements (for, enhancedfor, try)
Declarator contributes asDeclaration() to ASTNode.scope() for containingScope(); Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
ResourceDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope();
ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope(); ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope();
/** fallback attribute to ensure every AST element could pontentially be a scope */ /** fallback attribute to ensure every AST element could pontentially be a scope */
...@@ -66,4 +68,8 @@ aspect ScopeGenerationAttributes { ...@@ -66,4 +68,8 @@ aspect ScopeGenerationAttributes {
eq BasicCatch.getParameter().succeedingScope() = getBlock(); eq BasicCatch.getParameter().succeedingScope() = getBlock();
eq MethodDecl.getParameter().succeedingScope() = getBlock(); eq MethodDecl.getParameter().succeedingScope() = getBlock();
eq ConstructorDecl.getParameter().succeedingScope() = getBlock(); eq ConstructorDecl.getParameter().succeedingScope() = getBlock();
inh ASTNode ResourceDeclaration.succeedingScope();
eq TryWithResources.getResource().succeedingScope() = getBlock();
eq EnhancedForStmt.getVariableDecl().succeedingScope() = (getStmt() instanceof Block) ? getStmt() : null;
eq VarDeclStmt.getDeclarator().succeedingScope() = null;
} }
...@@ -2,26 +2,43 @@ package p1; ...@@ -2,26 +2,43 @@ package p1;
public abstract class ClassA { public abstract class ClassA {
A fieldA; int fieldA;
int fieldB;
public ClassA(int constructorParameterA) { public ClassA(int constructorParameterA) {
A localConstructorVarA = new A(); int localConstructorVarA = 0;
} }
public void methodNameA(int parameterA) { public void methodNameA(int parameterA) {
A localVarA = new A(); int localVarA = 1;
int localVarB = 1;
{ {
A localVarInBlockA = new A(); int localVarInBlockA = 2;
// this is shadowed: // this is shadowed (and forbidden)
A localVarA = new A(); int localVarA = 3;
} }
// this is shadowed (over two levels) // this is shadowed (over two levels, not forbidden)
A fieldA; int fieldA;
try (
// this is forbidden
java.util.zip.ZipFile localVarB = new java.util.zip.ZipFile("zipFileName");
// this is okay
java.io.BufferedWriter fieldB = java.nio.file.Files.newBufferedWriter(null)
) { /* do stuff */ } catch (java.io.IOException e) {/* do stuff */}
}
int i;
class Local {
{
for (int i = 0; i < 10; i++) System.out.println(i);
}
} }
// this does not appear as a scope (and, more importantly, the parameters are not added anywhere else) // this does not appear as a scope (and, more importantly, the parameters are not added anywhere else)
public void methodNameB(int parameterForAbstractMethodB); public abstract void methodNameB(int parameterForAbstractMethodB);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment