protected MethodUsage toMethodUsage(MethodReferenceExpr methodReferenceExpr) { if (!(methodReferenceExpr.getScope() instanceof TypeExpr)) { throw new UnsupportedOperationException(); } TypeExpr typeExpr = (TypeExpr) methodReferenceExpr.getScope(); if (!(typeExpr.getType() instanceof com.github.javaparser.ast.type.ClassOrInterfaceType)) { throw new UnsupportedOperationException(typeExpr.getType().getClass().getCanonicalName()); } ClassOrInterfaceType classOrInterfaceType = (ClassOrInterfaceType) typeExpr.getType(); SymbolReference<ResolvedTypeDeclaration> typeDeclarationSymbolReference = JavaParserFactory.getContext(classOrInterfaceType, typeSolver).solveType(classOrInterfaceType.getName().getId(), typeSolver); if (!typeDeclarationSymbolReference.isSolved()) { throw new UnsupportedOperationException(); } List<MethodUsage> methodUsages = ((ResolvedReferenceTypeDeclaration) typeDeclarationSymbolReference.getCorrespondingDeclaration()).getAllMethods().stream().filter(it -> it.getName().equals(methodReferenceExpr.getIdentifier())).collect(Collectors.toList()); switch (methodUsages.size()) { case 0: throw new UnsupportedOperationException(); case 1: return methodUsages.get(0); default: throw new UnsupportedOperationException(); } }
protected MethodUsage toMethodUsage(MethodReferenceExpr methodReferenceExpr) { if (!(methodReferenceExpr.getScope() instanceof TypeExpr)) { throw new UnsupportedOperationException(); } TypeExpr typeExpr = (TypeExpr) methodReferenceExpr.getScope(); if (!(typeExpr.getType() instanceof com.github.javaparser.ast.type.ClassOrInterfaceType)) { throw new UnsupportedOperationException(typeExpr.getType().getClass().getCanonicalName()); } ClassOrInterfaceType classOrInterfaceType = (ClassOrInterfaceType) typeExpr.getType(); SymbolReference<ResolvedTypeDeclaration> typeDeclarationSymbolReference = JavaParserFactory.getContext(classOrInterfaceType, typeSolver).solveType(classOrInterfaceType.getName().getId()); if (!typeDeclarationSymbolReference.isSolved()) { throw new UnsupportedOperationException(); } List<MethodUsage> methodUsages = ((ResolvedReferenceTypeDeclaration) typeDeclarationSymbolReference.getCorrespondingDeclaration()).getAllMethods().stream().filter(it -> it.getName().equals(methodReferenceExpr.getIdentifier())).collect(Collectors.toList()); switch (methodUsages.size()) { case 0: throw new UnsupportedOperationException(); case 1: return methodUsages.get(0); default: throw new UnsupportedOperationException(); } }
protected MethodUsage toMethodUsage(MethodReferenceExpr methodReferenceExpr) { if (!(methodReferenceExpr.getScope() instanceof TypeExpr)) { throw new UnsupportedOperationException(); } TypeExpr typeExpr = (TypeExpr) methodReferenceExpr.getScope(); if (!(typeExpr.getType() instanceof com.github.javaparser.ast.type.ClassOrInterfaceType)) { throw new UnsupportedOperationException(typeExpr.getType().getClass().getCanonicalName()); } ClassOrInterfaceType classOrInterfaceType = (ClassOrInterfaceType) typeExpr.getType(); SymbolReference<ResolvedTypeDeclaration> typeDeclarationSymbolReference = JavaParserFactory.getContext(classOrInterfaceType, typeSolver).solveType(classOrInterfaceType.getName().getId(), typeSolver); if (!typeDeclarationSymbolReference.isSolved()) { throw new UnsupportedOperationException(); } List<MethodUsage> methodUsages = ((ResolvedReferenceTypeDeclaration) typeDeclarationSymbolReference.getCorrespondingDeclaration()).getAllMethods().stream().filter(it -> it.getName().equals(methodReferenceExpr.getIdentifier())).collect(Collectors.toList()); switch (methodUsages.size()) { case 0: throw new UnsupportedOperationException(); case 1: return methodUsages.get(0); default: throw new UnsupportedOperationException(); } }
return NameRole.REFERENCE; if (whenParentIs(TypeExpr.class, name, (p, c) -> p.getType() == c)) { return NameRole.REFERENCE;
p1.getType() == c1 && whenParentIs(MethodReferenceExpr.class, p1, (p2, c2) -> p2.getScope() == c2) )) {