diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/BasicSymbolsMill.java b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/BasicSymbolsMill.java index a976d5ae71..5c036e7363 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/BasicSymbolsMill.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/BasicSymbolsMill.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import de.monticore.symbols.basicsymbols._symboltable.IBasicSymbolsGlobalScope; import de.monticore.symbols.basicsymbols._symboltable.TypeSymbol; +import de.monticore.symboltable.modifiers.AccessModifier; import java.util.List; import java.util.Collections; @@ -61,6 +62,7 @@ protected TypeSymbol createPrimitive(String name){ .setEnclosingScope(globalScope()) .setFullName(name) .setSpannedScope(scope()) + .setAccessModifier(AccessModifier.ALL_INCLUSION) .build(); } diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/FunctionSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/FunctionSymbol.java index 6a9575c625..c72c25649e 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/FunctionSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/FunctionSymbol.java @@ -102,10 +102,10 @@ public SymTypeOfFunction getFunctionType() { public AccessModifier getAccessModifier() { // supporting legacy source code... if(accessModifier == null) { - Log.info("AccessModifier of function '" + Log.trace("AccessModifier of function '" + getFullName() + "' was not set (null)", "BasicSymbols"); - return AccessModifier.ALL_INCLUSION; + accessModifier = AccessModifier.ALL_INCLUSION; } return accessModifier; } diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeSymbol.java index b6fa0c370d..df33675d64 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeSymbol.java @@ -99,10 +99,10 @@ public SymTypeExpression getSuperClass() { public AccessModifier getAccessModifier() { // supporting legacy source code... if(accessModifier == null) { - Log.info("AccessModifier of type '" + Log.trace("AccessModifier of type '" + getFullName() + "' was not set (null)", "BasicSymbols"); - return AccessModifier.ALL_INCLUSION; + accessModifier = AccessModifier.ALL_INCLUSION; } return accessModifier; } diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeVarSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeVarSymbol.java index 00da48d8e3..3734ac63a2 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeVarSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/TypeVarSymbol.java @@ -31,10 +31,10 @@ public boolean deepEquals(TypeVarSymbol other) { public AccessModifier getAccessModifier() { // supporting legacy source code... if(accessModifier == null) { - Log.info("AccessModifier of type variable '" + Log.trace("AccessModifier of type variable '" + getFullName() + "' was not set (null)", "BasicSymbols"); - return AccessModifier.ALL_INCLUSION; + accessModifier = AccessModifier.ALL_INCLUSION; } return accessModifier; } diff --git a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/VariableSymbol.java b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/VariableSymbol.java index d0a536d363..df84990107 100644 --- a/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/VariableSymbol.java +++ b/monticore-grammar/src/main/java/de/monticore/symbols/basicsymbols/_symboltable/VariableSymbol.java @@ -50,10 +50,10 @@ public void replaceTypeVariables(Map replaceMa public AccessModifier getAccessModifier() { // supporting legacy source code... if(accessModifier == null) { - Log.info("AccessModifier of variable '" + Log.trace("AccessModifier of variable '" + getFullName() + "' was not set (null)", "BasicSymbols"); - return AccessModifier.ALL_INCLUSION; + accessModifier = AccessModifier.ALL_INCLUSION; } return accessModifier; } diff --git a/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java b/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java index e24fd00abb..d97541d313 100644 --- a/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java +++ b/monticore-grammar/src/main/java/de/monticore/types3/util/WithinTypeBasicSymbolsResolver.java @@ -264,9 +264,8 @@ protected Optional resolveVariableLocally( Optional resolved = scope.resolveVariable( name, accessModifier, - predicate.and(v -> v.getEnclosingScope() == scope) + predicate.and(getIsLocalSymbolPredicate(scope)) ); - resolved = filterNonLocalSymbols(resolved, scope); return resolved; } @@ -283,9 +282,8 @@ protected List resolveFunctionLocally( false, name, accessModifier, - predicate.and(f -> f.getEnclosingScope() == scope) + predicate.and(getIsLocalSymbolPredicate(scope)) ); - resolved = filterNonLocalSymbols(resolved, scope); return resolved; } @@ -302,9 +300,8 @@ protected Optional resolveTypeLocally( false, name, accessModifier, - predicate.and(t -> t.getEnclosingScope() == scope) + predicate.and(getIsLocalSymbolPredicate(scope)) ); - resolved = filterNonLocalSymbols(resolved, scope); // prefer variables to concrete types in the same scope, // e.g., class A{class B{} B b = new B();} is not valid Java if (resolved.stream().anyMatch(getTypeDispatcher()::isTypeVar)) { @@ -323,44 +320,20 @@ protected Optional resolveTypeLocally( * Even more legacy code workarounds: * filter out anything that is not in the exact scope * due to questionable resolve strategy overrides in Scope classes... - * Changes the original list!!! */ - protected List filterNonLocalSymbols( - List symbols, - IScope scope - ) { - Iterator sItr = symbols.iterator(); - while (sItr.hasNext()) { - ISymbol symbol = sItr.next(); - if (symbol.getEnclosingScope() != scope) { - Log.info("filtered symbol '" - + symbol.getFullName() + "' as it was resolved " + protected Predicate getIsLocalSymbolPredicate(IScope localScope) { + return s -> { + if (s.getEnclosingScope() != localScope) { + Log.trace("filtered symbol '" + + s.getFullName() + "' as it was resolved " + "in a different scope, even though " + "\"resolve[...]Locally[...]\" was used", LOG_NAME ); - sItr.remove(); + return false; } - } - return symbols; - } - - protected Optional filterNonLocalSymbols( - Optional symbolOpt, - IScope scope - ) { - if (symbolOpt.isPresent()) { - if (symbolOpt.get().getEnclosingScope() != scope) { - Log.info("filtered symbol '" - + symbolOpt.get().getFullName() + "' as it was resolved " - + "in a different scope, even though " - + "\"resolve[...]Locally[...]\" was used", - LOG_NAME - ); - symbolOpt = Optional.empty(); - } - } - return symbolOpt; + return true; + }; } protected BasicSymbolsTypeDispatcher getTypeDispatcher() {