use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class CompilationUnitContext method solveMethod.
@Override
public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly, TypeSolver typeSolver) {
for (ImportDeclaration importDecl : wrappedNode.getImports()) {
if (importDecl.isStatic()) {
if (importDecl.isAsterisk()) {
String importString = importDecl.getNameAsString();
if (this.wrappedNode.getPackageDeclaration().isPresent() && this.wrappedNode.getPackageDeclaration().get().getName().getIdentifier().equals(packageName(importString)) && this.wrappedNode.getTypes().stream().anyMatch(it -> it.getName().getIdentifier().equals(toSimpleName(importString)))) {
// a lower level so this will fail
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
ResolvedTypeDeclaration ref = typeSolver.solveType(importString);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
} else {
String qName = importDecl.getNameAsString();
if (qName.equals(name) || qName.endsWith("." + name)) {
String typeName = getType(qName);
ResolvedTypeDeclaration ref = typeSolver.solveType(typeName);
SymbolReference<ResolvedMethodDeclaration> method = MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true, typeSolver);
if (method.isSolved()) {
return method;
}
}
}
}
}
return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
}
use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class JavaParserTypeAdapter method solveType.
public SymbolReference<ResolvedTypeDeclaration> solveType(String name, TypeSolver typeSolver) {
if (wrappedNode instanceof NodeWithTypeParameters<?>) {
NodeList<TypeParameter> typeParameters = ((NodeWithTypeParameters<?>) wrappedNode).getTypeParameters();
for (com.github.javaparser.ast.type.TypeParameter typeParameter : typeParameters) {
if (typeParameter.getName().getId().equals(name)) {
return SymbolReference.solved(new JavaParserTypeVariableDeclaration(typeParameter, typeSolver));
}
}
}
// Internal classes
for (BodyDeclaration<?> member : this.wrappedNode.getMembers()) {
if (member instanceof com.github.javaparser.ast.body.TypeDeclaration) {
com.github.javaparser.ast.body.TypeDeclaration<?> internalType = (com.github.javaparser.ast.body.TypeDeclaration<?>) member;
String prefix = internalType.getName() + ".";
if (internalType.getName().getId().equals(name)) {
if (internalType instanceof ClassOrInterfaceDeclaration) {
return SymbolReference.solved(new JavaParserClassDeclaration((com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) internalType, typeSolver));
} else if (internalType instanceof EnumDeclaration) {
return SymbolReference.solved(new JavaParserEnumDeclaration((com.github.javaparser.ast.body.EnumDeclaration) internalType, typeSolver));
} else {
throw new UnsupportedOperationException();
}
} else if (name.startsWith(prefix) && name.length() > prefix.length()) {
if (internalType instanceof ClassOrInterfaceDeclaration) {
return new JavaParserClassDeclaration((com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) internalType, typeSolver).solveType(name.substring(prefix.length()), typeSolver);
} else if (internalType instanceof EnumDeclaration) {
return new SymbolSolver(typeSolver).solveTypeInType(new JavaParserEnumDeclaration((com.github.javaparser.ast.body.EnumDeclaration) internalType, typeSolver), name.substring(prefix.length()));
} else {
throw new UnsupportedOperationException();
}
}
}
}
return SymbolReference.unsolved(ResolvedTypeDeclaration.class);
}
use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToQualifiedInternalOfInternalClass.
@Test
public void solveTypeRefToQualifiedInternalOfInternalClass() {
CompilationUnit cu = parseSample("ClassWithTypes");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("B.C", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
}
use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToInternalEnum.
@Test
public void solveTypeRefToInternalEnum() {
CompilationUnit cu = parseSample("ClassWithTypes");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("E", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
}
use of com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationContextResolutionTest method solveTypeRefToInternalClass.
@Test
public void solveTypeRefToInternalClass() {
CompilationUnit cu = parseSample("ClassWithTypes");
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = Navigator.demandClass(cu, "A");
Context context = new ClassOrInterfaceDeclarationContext(classOrInterfaceDeclaration, typeSolver);
SymbolReference<ResolvedTypeDeclaration> ref = context.solveType("B", new MemoryTypeSolver());
assertEquals(true, ref.isSolved());
}
Aggregations