public SymbolReference<ResolvedTypeDeclaration> solve(ThisExpr node) { // If 'this' is prefixed by a class eg. MyClass.this if (node.getClassExpr().isPresent()) { // Get the class name String className = node.getClassExpr().get().toString(); // Attempt to resolve using a typeSolver SymbolReference<ResolvedReferenceTypeDeclaration> clazz = typeSolver.tryToSolveType(className); if (clazz.isSolved()) { return SymbolReference.solved(clazz.getCorrespondingDeclaration()); } // Attempt to resolve locally in Compilation unit Optional<CompilationUnit> cu = node.findAncestor(CompilationUnit.class); if (cu.isPresent()) { Optional<ClassOrInterfaceDeclaration> classByName = cu.get().getClassByName(className); if (classByName.isPresent()) { return SymbolReference.solved(getTypeDeclaration(classByName.get())); } } } return SymbolReference.solved(getTypeDeclaration(findContainingTypeDeclOrObjectCreationExpr(node))); }
@Override public ResolvedType visit(ThisExpr node, Boolean solveLambdas) { // If 'this' is prefixed by a class eg. MyClass.this if (node.getClassExpr().isPresent()) { // Get the class name String className = node.getClassExpr().get().toString(); // Attempt to resolve using a typeSolver SymbolReference<ResolvedReferenceTypeDeclaration> clazz = typeSolver.tryToSolveType(className); if (clazz.isSolved()) { return new ReferenceTypeImpl(clazz.getCorrespondingDeclaration(), typeSolver); } // Attempt to resolve locally in Compilation unit Optional<CompilationUnit> cu = node.findAncestor(CompilationUnit.class); if (cu.isPresent()) { Optional<ClassOrInterfaceDeclaration> classByName = cu.get().getClassByName(className); if (classByName.isPresent()) { return new ReferenceTypeImpl(facade.getTypeDeclaration(classByName.get()), typeSolver); } } } return new ReferenceTypeImpl(facade.getTypeDeclaration(facade.findContainingTypeDeclOrObjectCreationExpr(node)), typeSolver); }