@Override public Set<ResolvedMethodDeclaration> getDeclaredMethods() { return findMembersOfKind(com.github.javaparser.ast.body.MethodDeclaration.class) .stream() .map(method -> new JavaParserMethodDeclaration(method, typeSolver)) .collect(Collectors.toSet()); }
@Override public ResolvedParameterDeclaration getParam(int i) { if (i < 0 || i >= getNumberOfParams()) { throw new IllegalArgumentException(String.format("No param with index %d. Number of params: %d", i, getNumberOfParams())); } return new JavaParserParameterDeclaration(wrappedNode.getParameters().get(i), typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } return JavaParserFacade.get(typeSolver).convert(wrappedNode.getThrownExceptions() .get(index), wrappedNode); } }
@Override public String getContainerQualifiedName() { ResolvedTypeParametrizable container = getContainer(); if (container instanceof ResolvedReferenceTypeDeclaration) { return ((ResolvedReferenceTypeDeclaration) container).getQualifiedName(); } else if (container instanceof JavaParserConstructorDeclaration) { return ((JavaParserConstructorDeclaration) container).getQualifiedSignature(); } else { return ((JavaParserMethodDeclaration) container).getQualifiedSignature(); } }
@Override public ResolvedType getReturnType() { return JavaParserFacade.get(typeSolver).convert(wrappedNode.getType(), getContext()); }
static MethodUsage resolveTypeVariables(Context context, ResolvedMethodDeclaration methodDeclaration, List<ResolvedType> parameterTypes) { if (methodDeclaration instanceof JavaParserMethodDeclaration) { return ((JavaParserMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavassistMethodDeclaration) { return ((JavassistMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavaParserEnumDeclaration.ValuesMethod) { return ((JavaParserEnumDeclaration.ValuesMethod) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof ReflectionMethodDeclaration) { return ((ReflectionMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else { throw new UnsupportedOperationException(); } } }
private static List<ResolvedMethodDeclaration> getMethodsWithoutDuplicates(List<ResolvedMethodDeclaration> methods) { Set<ResolvedMethodDeclaration> s = new TreeSet<>((m1, m2) -> { if (m1 instanceof JavaParserMethodDeclaration && m2 instanceof JavaParserMethodDeclaration && ((JavaParserMethodDeclaration) m1).getWrappedNode().equals(((JavaParserMethodDeclaration) m2).getWrappedNode())) { return 0; } return 1; }); s.addAll(methods); List<ResolvedMethodDeclaration> res = new ArrayList<>(); Set<String> usedSignatures = new HashSet<>(); for (ResolvedMethodDeclaration md : methods) { String signature = md.getQualifiedSignature(); if (!usedSignatures.contains(signature)) { usedSignatures.add(signature); res.add(md); } } return res; }
@Override public String getContainerId() { ResolvedTypeParametrizable container = getContainer(); if (container instanceof ResolvedReferenceTypeDeclaration) { return ((ResolvedReferenceTypeDeclaration) container).getId(); } else if (container instanceof JavaParserConstructorDeclaration) { return ((JavaParserConstructorDeclaration) container).getQualifiedSignature(); } else { return ((JavaParserMethodDeclaration) container).getQualifiedSignature(); } }
@Override public ResolvedType getReturnType() { return JavaParserFacade.get(typeSolver).convert(wrappedNode.getType(), getContext()); }
static MethodUsage resolveTypeVariables(Context context, ResolvedMethodDeclaration methodDeclaration, List<ResolvedType> parameterTypes) { if (methodDeclaration instanceof JavaParserMethodDeclaration) { return ((JavaParserMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavassistMethodDeclaration) { return ((JavassistMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof JavaParserEnumDeclaration.ValuesMethod) { return ((JavaParserEnumDeclaration.ValuesMethod) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else if (methodDeclaration instanceof ReflectionMethodDeclaration) { return ((ReflectionMethodDeclaration) methodDeclaration).resolveTypeVariables(context, parameterTypes); } else { throw new UnsupportedOperationException(); } } }
private static List<ResolvedMethodDeclaration> getMethodsWithoutDuplicates(List<ResolvedMethodDeclaration> methods) { Set<ResolvedMethodDeclaration> s = new TreeSet<>((m1, m2) -> { if (m1 instanceof JavaParserMethodDeclaration && m2 instanceof JavaParserMethodDeclaration && ((JavaParserMethodDeclaration) m1).getWrappedNode().equals(((JavaParserMethodDeclaration) m2).getWrappedNode())) { return 0; } return 1; }); s.addAll(methods); List<ResolvedMethodDeclaration> res = new ArrayList<>(); Set<String> usedSignatures = new HashSet<>(); for (ResolvedMethodDeclaration md : methods) { String signature = md.getQualifiedSignature(); if (!usedSignatures.contains(signature)) { usedSignatures.add(signature); res.add(md); } } return res; }
@Override public Set<ResolvedMethodDeclaration> getDeclaredMethods() { Set<ResolvedMethodDeclaration> methods = new HashSet<>(); for (BodyDeclaration<?> member : wrappedNode.getMembers()) { if (member instanceof com.github.javaparser.ast.body.MethodDeclaration) { methods.add(new JavaParserMethodDeclaration((com.github.javaparser.ast.body.MethodDeclaration) member, typeSolver)); } } return methods; }
@Override public String getContainerId() { ResolvedTypeParametrizable container = getContainer(); if (container instanceof ResolvedReferenceTypeDeclaration) { return ((ResolvedReferenceTypeDeclaration) container).getId(); } else if (container instanceof JavaParserConstructorDeclaration) { return ((JavaParserConstructorDeclaration) container).getQualifiedSignature(); } else { return ((JavaParserMethodDeclaration) container).getQualifiedSignature(); } }
@Override public ResolvedParameterDeclaration getParam(int i) { if (i < 0 || i >= getNumberOfParams()) { throw new IllegalArgumentException(String.format("No param with index %d. Number of params: %d", i, getNumberOfParams())); } return new JavaParserParameterDeclaration(wrappedNode.getParameters().get(i), typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } return JavaParserFacade.get(typeSolver).convert(wrappedNode.getThrownExceptions() .get(index), wrappedNode); } }
@Override public ResolvedType getReturnType() { return JavaParserFacade.get(typeSolver).convert(wrappedNode.getType(), getContext()); }
@Override public Set<ResolvedMethodDeclaration> getDeclaredMethods() { Set<ResolvedMethodDeclaration> methods = new HashSet<>(); for (BodyDeclaration<?> member : wrappedNode.getMembers()) { if (member instanceof com.github.javaparser.ast.body.MethodDeclaration) { methods.add(new JavaParserMethodDeclaration((com.github.javaparser.ast.body.MethodDeclaration) member, typeSolver)); } } return methods; }
@Override public String getContainerId() { ResolvedTypeParametrizable container = getContainer(); if (container instanceof ResolvedReferenceTypeDeclaration) { return ((ResolvedReferenceTypeDeclaration) container).getId(); } else if (container instanceof JavaParserConstructorDeclaration) { return ((JavaParserConstructorDeclaration) container).getQualifiedSignature(); } else { return ((JavaParserMethodDeclaration) container).getQualifiedSignature(); } }
@Override public ResolvedParameterDeclaration getParam(int i) { if (i < 0 || i >= getNumberOfParams()) { throw new IllegalArgumentException(String.format("No param with index %d. Number of params: %d", i, getNumberOfParams())); } return new JavaParserParameterDeclaration(wrappedNode.getParameters().get(i), typeSolver); }
@Override public ResolvedType getSpecifiedException(int index) { if (index < 0 || index >= getNumberOfSpecifiedExceptions()) { throw new IllegalArgumentException(String.format("No exception with index %d. Number of exceptions: %d", index, getNumberOfSpecifiedExceptions())); } return JavaParserFacade.get(typeSolver).convert(wrappedNode.getThrownExceptions() .get(index), wrappedNode); }