From 8d2a53d3d73cacce5048019d20719abcf9866883 Mon Sep 17 00:00:00 2001
From: Johannes Mey <johannes.mey@tu-dresden.de>
Date: Sat, 4 Jan 2020 20:15:36 +0100
Subject: [PATCH] treat all TypeDecls equally

---
 .../src/main/jastadd/ProgramToScopeTree.jrag  | 25 +++++++------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
index 1cb2b14..1c4e4a1 100644
--- a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+++ b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
@@ -6,7 +6,7 @@ aspect ProgramToScopeTree {
     // add all classes
     for (CompilationUnit cu : getCompilationUnitList()) {
       for (TypeDecl typeDecl : cu.getTypeDeclList()) {
-          tree.addElement(typeDecl.isClassDecl() ? ((ClassDecl)typeDecl).protectedScope() : typeDecl.scope());
+          tree.addElement(typeDecl.protectedScope());
       }
     }
 
@@ -43,22 +43,21 @@ aspect ProgramToScopeTree {
   coll Scope ASTNode.scope() [asScope()] with addElement root Program;
 
   /** a relational nta collection attribute to compute a special scope containing visible fields and subtypes */
-  coll TypeDeclScope ClassDecl.protectedScope() [asProtectedScope()] with addElement root Program;
-  coll TypeDeclScope ClassDecl.packageScope() [asPackageScope()] with addElement root Program;
+  coll TypeDeclScope TypeDecl.protectedScope() [asProtectedScope()] with addElement root Program;
+  coll TypeDeclScope TypeDecl.packageScope() [asPackageScope()] with addElement root Program;
 
   // collect all scopes
-  TypeDecl  contributes scope() when !isNestedType() && !isClassDecl() to ASTNode.scope() for containingScope();
-  ClassDecl contributes protectedScope() when isNestedType() to ASTNode.scope() for containingScope();
+  TypeDecl contributes protectedScope() when isNestedType() to ASTNode.scope() for containingScope();
   Block contributes scope() to ASTNode.scope() for containingScope();
   ForStmt contributes scope() when !(getStmt() instanceof Block) to ASTNode.scope() for containingScope();
   EnhancedForStmt contributes scope() when !(getStmt() instanceof Block) to ASTNode.scope() for containingScope();
 
   // collect all elements
-  Declarator contributes asDeclaration() when !isField() || isPrivate() to ASTNode.scope() for containingScope();
+  Declarator contributes asDeclaration() when /* is NOT in interface || */ !isField() || isPrivate() to ASTNode.scope() for containingScope();
   // field which is neither private, protected, nor public -> package-private scope
-  Declarator contributes asDeclaration() when isField() && !isPrivate() && !(isProtected() || isPublic()) to ClassDecl.packageScope() for containingScope();
+  Declarator contributes asDeclaration() when isField() && !isPrivate() && !(isProtected() || isPublic()) to TypeDecl.packageScope() for containingScope();
   // field which is either protected or public -> protected scope
-  Declarator contributes asDeclaration() when isField() && !isPrivate() && (isProtected() || isPublic()) to ClassDecl.protectedScope() for containingScope();
+  Declarator contributes asDeclaration() when /* is in interface && */ isField() && !isPrivate() && (isProtected() || isPublic()) to TypeDecl.protectedScope() for containingScope();
   ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for containingScope();
 }
 
@@ -80,25 +79,19 @@ aspect ScopeTreeConstructors {
   }
 
   syn lazy TypeDeclScope TypeDecl.asScope() {
-    TypeDeclScope scope = new TypeDeclScope();
-    scope.setTypeDecl(this);
-    return scope;
-  }
-
-  syn lazy TypeDeclScope ClassDecl.asScope() {
     TypeDeclScope scope = new PrivateClassDeclScope();
     scope.setTypeDecl(this);
     return scope;
   }
 
-  syn lazy TypeDeclScope ClassDecl.asProtectedScope() {
+  syn lazy TypeDeclScope TypeDecl.asProtectedScope() {
     TypeDeclScope scope = new ProtectedClassDeclScope();
     scope.setTypeDecl(this);
     scope.addElement(packageScope());
     return scope;
   }
 
-  syn lazy TypeDeclScope ClassDecl.asPackageScope() {
+  syn lazy TypeDeclScope TypeDecl.asPackageScope() {
     TypeDeclScope scope = new PackageClassDeclScope();
     scope.setTypeDecl(this);
     scope.addElement(scope());
-- 
GitLab