From c8c0383647fcc169fe428938c7f48d5fca6e858a Mon Sep 17 00:00:00 2001
From: Johannes Mey <johannes.mey@tu-dresden.de>
Date: Tue, 24 Dec 2019 11:25:16 +0100
Subject: [PATCH] fix types for which containingScope() is defined

---
 scope4j/src/main/jastadd/ProgramToScopeTree.jrag | 8 ++++++--
 testprograms/simpleScope/A.java                  | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
index 497d557..6a155b9 100644
--- a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+++ b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
@@ -68,9 +68,13 @@ aspect ProgramToScopeTree {
 
 aspect ScopeGenerationAttributes {
 
-  // TODO this is only correct for declarations, not for all AST nodes!
   /** determine the scope an AST element is contained in or belongs to.*/
-  inh lazy ASTNode ASTNode.containingScope();
+  inh lazy ASTNode TypeDecl.containingScope();
+  inh lazy ASTNode Block.containingScope();
+  inh lazy ASTNode ForStmt.containingScope();
+  inh lazy ASTNode EnhancedForStmt.containingScope();
+  inh lazy ASTNode Declarator.containingScope();
+  inh lazy ASTNode ParameterDeclaration.containingScope();
   // contained in scope:
   eq Program.getChild().containingScope() = this;
   eq TypeDecl.getChild().containingScope() = this;
diff --git a/testprograms/simpleScope/A.java b/testprograms/simpleScope/A.java
index d166924..bed8e30 100644
--- a/testprograms/simpleScope/A.java
+++ b/testprograms/simpleScope/A.java
@@ -12,6 +12,7 @@ public abstract class ClassA {
   public void methodNameA(int parameterA) {
     int localVarA = 1;
     int localVarB = 1;
+    int localVarC = 1;
 
     {
       int localVarInBlockA = 2;
@@ -22,7 +23,7 @@ public abstract class ClassA {
 
     class Local {
       {
-        for (int localVarA = 0; localVarA < 10; localVarA++) System.out.println(localVarA);
+        for (int localVarC = 0; localVarC < 10; localVarC++) System.out.println(localVarC);
       }
     }
 
-- 
GitLab