use of com.github.javaparser.ast.type.TypeParameter in project javaparser by javaparser.
the class VoidVisitorAdapter method visit.
@Override
public void visit(final ClassOrInterfaceDeclaration n, final A arg) {
visitComment(n.getComment(), arg);
visitAnnotations(n, arg);
n.getNameExpr().accept(this, arg);
for (final TypeParameter t : n.getTypeParameters()) {
t.accept(this, arg);
}
for (final ClassOrInterfaceType c : n.getExtends()) {
c.accept(this, arg);
}
for (final ClassOrInterfaceType c : n.getImplements()) {
c.accept(this, arg);
}
for (final BodyDeclaration<?> member : n.getMembers()) {
member.accept(this, arg);
}
}
use of com.github.javaparser.ast.type.TypeParameter in project javaparser by javaparser.
the class AnonymousClassDeclarationContext method solveType.
@Override
public SymbolReference<ResolvedTypeDeclaration> solveType(String name, TypeSolver typeSolver) {
List<com.github.javaparser.ast.body.TypeDeclaration> typeDeclarations = myDeclaration.findMembersOfKind(com.github.javaparser.ast.body.TypeDeclaration.class);
Optional<SymbolReference<ResolvedTypeDeclaration>> exactMatch = typeDeclarations.stream().filter(internalType -> internalType.getName().getId().equals(name)).findFirst().map(internalType -> SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration(internalType)));
if (exactMatch.isPresent()) {
return exactMatch.get();
}
Optional<SymbolReference<ResolvedTypeDeclaration>> recursiveMatch = typeDeclarations.stream().filter(internalType -> name.startsWith(String.format("%s.", internalType.getName()))).findFirst().map(internalType -> JavaParserFactory.getContext(internalType, typeSolver).solveType(name.substring(internalType.getName().getId().length() + 1), typeSolver));
if (recursiveMatch.isPresent()) {
return recursiveMatch.get();
}
Optional<SymbolReference<ResolvedTypeDeclaration>> typeArgumentsMatch = wrappedNode.getTypeArguments().map(nodes -> ((NodeWithTypeArguments<?>) nodes).getTypeArguments().orElse(new NodeList<>())).orElse(new NodeList<>()).stream().filter(type -> type.toString().equals(name)).findFirst().map(matchingType -> SymbolReference.solved(new JavaParserTypeParameter(new TypeParameter(matchingType.toString()), typeSolver)));
if (typeArgumentsMatch.isPresent()) {
return typeArgumentsMatch.get();
}
// Look into extended classes and implemented interfaces
for (ResolvedReferenceType ancestor : myDeclaration.getAncestors()) {
// look at names of extended classes and implemented interfaces (this may not be important because they are checked in CompilationUnitContext)
if (ancestor.getTypeDeclaration().getName().equals(name)) {
return SymbolReference.solved(ancestor.getTypeDeclaration());
}
// look into internal types of extended classes and implemented interfaces
try {
for (ResolvedTypeDeclaration internalTypeDeclaration : ancestor.getTypeDeclaration().internalTypes()) {
if (internalTypeDeclaration.getName().equals(name)) {
return SymbolReference.solved(internalTypeDeclaration);
}
}
} catch (UnsupportedOperationException e) {
// just continue using the next ancestor
}
}
return getParent().solveType(name, typeSolver);
}
use of com.github.javaparser.ast.type.TypeParameter in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationTransformationsTest method addingTypeParameterAsLastWhenThereAreSome.
@Test
public void addingTypeParameterAsLastWhenThereAreSome() throws IOException {
ClassOrInterfaceDeclaration cid = consider("class A<U> {}");
cid.addTypeParameter(new TypeParameter("T", new NodeList<>()));
assertTransformedToString("class A<U, T> {}", cid);
}
use of com.github.javaparser.ast.type.TypeParameter in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationTransformationsTest method addingTypeParameterWhenThereAreNone.
// typeParameters
@Test
public void addingTypeParameterWhenThereAreNone() throws IOException {
ClassOrInterfaceDeclaration cid = consider("class A {}");
cid.addTypeParameter(new TypeParameter("T", new NodeList<>()));
assertTransformedToString("class A<T> {}", cid);
}
Aggregations