Skip to content
Closed
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 @@ -3,12 +3,9 @@

import com.google.common.base.Preconditions;
import de.monticore.types3.ISymTypeVisitor;
import de.monticore.types3.util.SymTypeExpressionComparator;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Spliterator;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
Expand All @@ -22,7 +19,8 @@ public class SymTypeOfIntersection extends SymTypeExpression {

public SymTypeOfIntersection(Collection<? extends SymTypeExpression> types) {
Preconditions.checkNotNull(types);
this.intersectedTypes = new LinkedHashSet<>();
// TreeSet with comparator properly filters equal types
this.intersectedTypes = new TreeSet<>(new SymTypeExpressionComparator());
this.intersectedTypes.addAll(types);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@
import de.monticore.types3.generics.TypeParameterRelations;
import de.se_rwth.commons.logging.Log;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -101,19 +94,27 @@ protected Optional<SymTypeExpression> _resolveVariable(
AccessModifier superModifier = private2Protected(accessModifier);
List<SymTypeExpression> superTypes = getSuperTypes(thisType);
resolvedSymType = Optional.empty();

// During OCL collection flattening, the same type is resolved twice for a field access of List<X>,
// since List<X> extends Collection<X> (only valid in OCL).
// Thus, exactly equal types are filtered out.
Set<SymTypeExpression> resolvedTypes = new TreeSet<>(new SymTypeExpressionComparator());
for (SymTypeExpression superType : superTypes) {
Optional<SymTypeExpression> resolvedInSuper =
resolveVariable(superType, name, superModifier, predicate);
if (resolvedSymType.isPresent() && resolvedInSuper.isPresent()) {
Log.error("0xFD222 found variables with name \""
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"");
if (resolvedInSuper.isPresent()) {
resolvedTypes.add(resolvedInSuper.get());
}
else if (resolvedSymType.isEmpty() && resolvedInSuper.isPresent()) {
resolvedSymType = resolvedInSuper;
}
//filter based on local variables
}

if (resolvedTypes.size() > 1) {
Log.error("0xFD222 found variables with name \""
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"");
} else if (resolvedTypes.size() == 1) {
resolvedSymType = Optional.of(resolvedTypes.iterator().next());
}
//filter based on local variables
}

// not expecting free type variables for fields,
Expand Down
Loading