Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
import de.monticore.symbols.basicsymbols._symboltable.TypeSymbol;
import de.monticore.symbols.basicsymbols._symboltable.VariableSymbol;
import de.monticore.symboltable.IScopeSpanningSymbol;
import de.monticore.symboltable.ISymbol;
import de.monticore.symboltable.ImportStatement;
import de.monticore.symboltable.modifiers.AccessModifier;
import de.monticore.types.check.SymTypeExpression;
import de.monticore.types.check.SymTypeExpressionFactory;
import de.se_rwth.commons.logging.Log;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -57,6 +57,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Predicate;

import static de.se_rwth.commons.Names.getQualifier;
Expand Down Expand Up @@ -103,44 +104,14 @@ default List<TypeSymbol> continueTypeWithEnclosingScope(
AccessModifier modifier,
Predicate<TypeSymbol> predicate
) {
final LinkedHashSet<TypeSymbol> result = new LinkedHashSet<>();
if (
checkIfContinueWithEnclosingScope(foundSymbols)
&& getEnclosingScope() != null
) {

var importStatements = new LinkedList<ImportStatement>();
if(getEnclosingScope().isPresentAstNode()) {
var visitor = new SysMLImportsAndPackagesVisitor2() {
@Override
public void visit(ASTSysMLImportStatement node) {
if (getEnclosingScope().equals(node.getEnclosingScope())) {
importStatements.add(new ImportStatement(node.getMCQualifiedName().getQName(),
node.isStar() || node.isRecursive()));
}
}
};
var traverser = SysMLv2Mill.inheritanceTraverser();
traverser.add4SysMLImportsAndPackages(visitor);
getEnclosingScope().getAstNode().accept(traverser);
}

Set<String> potentialNames = calcQNamesForEnclosingScope(name, importStatements);

for (String potentialName : potentialNames) {
result.addAll(getEnclosingScope().resolveTypeMany( foundSymbols,
potentialName,
modifier,
predicate)
);
}
}

return new ArrayList<>(result);
return continueWithEnclosingScope(foundSymbols,
name,
(foundInIteration, qualifiedName) ->
getEnclosingScope().resolveTypeMany(foundInIteration, qualifiedName, modifier, predicate));
}

/**
* @see ISysMLv2Scope#continueTypeWithEnclosingScope(boolean, String, AccessModifier, Predicate)
* @see ISysMLv2Scope#continueTypeWithEnclosingScope
*/
@Override
default List<VariableSymbol> continueVariableWithEnclosingScope(
Expand All @@ -149,44 +120,14 @@ default List<VariableSymbol> continueVariableWithEnclosingScope(
AccessModifier modifier,
Predicate<VariableSymbol> predicate
) {
final LinkedHashSet<VariableSymbol> result = new LinkedHashSet<>();
if (
checkIfContinueWithEnclosingScope(foundSymbols)
&& getEnclosingScope() != null
) {

var importStatements = new LinkedList<ImportStatement>();
if(getEnclosingScope().isPresentAstNode()) {
var visitor = new SysMLImportsAndPackagesVisitor2() {
@Override
public void visit(ASTSysMLImportStatement node) {
if (getEnclosingScope().equals(node.getEnclosingScope())) {
importStatements.add(new ImportStatement(node.getMCQualifiedName().getQName(),
node.isStar() || node.isRecursive()));
}
}
};
var traverser = SysMLv2Mill.inheritanceTraverser();
traverser.add4SysMLImportsAndPackages(visitor);
getEnclosingScope().getAstNode().accept(traverser);
}

Set<String> potentialNames = calcQNamesForEnclosingScope(name, importStatements);

for (String potentialName : potentialNames) {
result.addAll(getEnclosingScope().resolveVariableMany( foundSymbols,
potentialName,
modifier,
predicate)
);
}
}

return new ArrayList<>(result);
return this.continueWithEnclosingScope(foundSymbols,
name,
(foundInIteration, qualifiedName) ->
getEnclosingScope().resolveVariableMany(foundInIteration, qualifiedName, modifier, predicate));
}

/**
* @see ISysMLv2Scope#continueTypeWithEnclosingScope(boolean, String, AccessModifier, Predicate)
* @see ISysMLv2Scope#continueTypeWithEnclosingScope
*/
@Override
default List<FunctionSymbol> continueFunctionWithEnclosingScope(
Expand All @@ -195,20 +136,46 @@ default List<FunctionSymbol> continueFunctionWithEnclosingScope(
AccessModifier modifier,
Predicate<FunctionSymbol> predicate
) {
final LinkedHashSet<FunctionSymbol> result = new LinkedHashSet<>();
if (
checkIfContinueWithEnclosingScope(foundSymbols)
&& (getEnclosingScope() != null)
) {
return continueWithEnclosingScope(foundSymbols,
name,
(foundInIteration, qualifiedName) ->
getEnclosingScope().resolveFunctionMany(foundInIteration, qualifiedName, modifier, predicate));
}

/**
* Generic continueWithEnclosing for multiple symbols. The structure is the
* same for all resolutions. We Abstract the SymbolType as T and introduce a
* Function argument where we will pass the specific Type-Dependent resolve
* call.
*
* @param foundSymbols marker if we have already found matching symbols
* @param name The name of the symbol we are searching
* @param resolver the resolveManyT call for the specific Type T
* @return The List of retrieved symbols
* @param <T> Symboltype to be processes, also used within resolver
*/
default <T extends ISymbol> List<T> continueWithEnclosingScope(
boolean foundSymbols,
String name,
BiFunction<Boolean, String, List<T>> resolver
) {
final LinkedHashSet<T> result = new LinkedHashSet<>();
if (checkIfContinueWithEnclosingScope(foundSymbols)
&& getEnclosingScope() != null) {

var importStatements = new LinkedList<ImportStatement>();

// collect import statements based on enclosing scopes AST-Imports
if(getEnclosingScope().isPresentAstNode()) {
var visitor = new SysMLImportsAndPackagesVisitor2() {
@Override
public void visit(ASTSysMLImportStatement node) {
// collect imports located directly within the enclosing scope
if (getEnclosingScope().equals(node.getEnclosingScope())) {
importStatements.add(new ImportStatement(node.getMCQualifiedName().getQName(),
node.isStar() || node.isRecursive()));
importStatements.add(new ImportStatement(
node.getMCQualifiedName().getQName(),
node.isStar() || node.isRecursive())
);
}
}
};
Expand All @@ -219,12 +186,12 @@ public void visit(ASTSysMLImportStatement node) {

Set<String> potentialNames = calcQNamesForEnclosingScope(name, importStatements);

// Hier wird die abstrakte Resolver-Funktion genutzt
for (String potentialName : potentialNames) {
result.addAll(getEnclosingScope().resolveFunctionMany( foundSymbols,
potentialName,
modifier,
predicate)
);
// The provided resolver is calling the exact resolveManyTYPE
var resolvedFromEnclosing = resolver.apply(foundSymbols, potentialName);
foundSymbols = foundSymbols | resolvedFromEnclosing.size() > 0;
result.addAll(resolvedFromEnclosing);
}
}

Expand Down

This file was deleted.

Loading