Skip to content

Commit

Permalink
model: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Oct 22, 2016
1 parent ba1a6f4 commit 6fcf635
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
Expand Up @@ -76,17 +76,12 @@ public Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {
if (lambdaType.isReferenceType()) {
for (Tuple2<TypeParameterDeclaration, Type> entry : lambdaType.asReferenceType().getTypeParametersMap()) {
if (entry._2.isTypeVariable() && entry._2.asTypeParameter().declaredOnType()) {
Optional<Type> ot = t.asReferenceType().getGenericParameterByName(entry._1.getName());
if (ot.isPresent()) {
lambdaType = lambdaType.replaceParam(entry._1.getName(), ot.get());
}
Type ot = t.asReferenceType().typeParametersMap().getValue(entry._1);
lambdaType = lambdaType.replaceParam(entry._1.getName(), ot);
}
}
} else if (lambdaType.isTypeVariable() && lambdaType.asTypeParameter().declaredOnType()) {
Optional<Type> ot = t.asReferenceType().getGenericParameterByName(lambdaType.asTypeParameter().getName());
if (ot.isPresent()) {
lambdaType = ot.get();
}
lambdaType = t.asReferenceType().typeParametersMap().getValue(lambdaType.asTypeParameter());
}

Value value = new Value(lambdaType, name);
Expand Down
Expand Up @@ -54,7 +54,6 @@ public abstract class ReferenceType implements Type, TypeParametrized {

public ReferenceType(TypeDeclaration typeDeclaration, TypeSolver typeSolver) {
this(typeDeclaration, deriveParams(typeDeclaration), typeSolver);
this.typeSolver = typeSolver;
}

public ReferenceType(TypeDeclaration typeDeclaration, List<Type> typeParameters, TypeSolver typeSolver) {
Expand Down Expand Up @@ -210,15 +209,11 @@ public List<ReferenceType> getAllAncestors() {
TypeDeclaration objectType = typeSolver.solveType(Object.class.getCanonicalName());
ReferenceType objectRef = create(objectType, typeSolver);

ancestors = ancestors.stream().map((a) -> replaceTypeParams(a).asReferenceType()).collect(Collectors.toList());
// TODO replace type typeParametersValues
ancestors = ancestors.stream()
.map((a) -> replaceTypeParams(a).asReferenceType())
.collect(Collectors.toList());

for (int i = 0; i < ancestors.size(); i++) {
if (ancestors.get(i).getQualifiedName().equals(Object.class.getCanonicalName())) {
ancestors.remove(i);
i--;
}
}
ancestors.removeIf(a -> a.getQualifiedName().equals(Object.class.getCanonicalName()));
ancestors.add(objectRef);
return ancestors;
}
Expand All @@ -237,14 +232,11 @@ public List<ReferenceType> getAllInterfacesAncestors() {
* Get the type associated with the type parameter with the given name.
* It returns Optional.empty unless the type declaration declares a type parameter with the given name.
*/
@Deprecated
public Optional<Type> getGenericParameterByName(String name) {
int i = 0;
for (TypeParameterDeclaration tp : typeDeclaration.getTypeParameters()) {
if (tp.getName().equals(name)) {
return Optional.of(this.typeParameters.get(i));
return Optional.of(this.typeParametersMap().getValue(tp));
}
i++;
}
return Optional.empty();
}
Expand Down

0 comments on commit 6fcf635

Please sign in to comment.