@Override public List<ResolvedConstructorDeclaration> getConstructors() { return findMembersOfKind(com.github.javaparser.ast.body.ConstructorDeclaration.class) .stream() .map(ctor -> new JavaParserConstructorDeclaration(this, ctor, typeSolver)) .collect(Collectors.toList()); }
@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 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(); } }
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration)node.getParentNode().get(); ResolvedClassDeclaration resolvedClass = resolveDeclaration(classOrInterfaceDeclaration, ResolvedClassDeclaration.class).asClass(); ResolvedConstructorDeclaration resolved = resolvedClass.getConstructors().stream().filter(c -> ((JavaParserConstructorDeclaration)c).getWrappedNode() == constructorDeclaration).findFirst().get(); if (resultClass.isInstance(resolved)) { return resultClass.cast(resolved);
@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(); } }
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration)node.getParentNode().get(); ResolvedClassDeclaration resolvedClass = resolveDeclaration(classOrInterfaceDeclaration, ResolvedClassDeclaration.class).asClass(); ResolvedConstructorDeclaration resolved = resolvedClass.getConstructors().stream().filter(c -> ((JavaParserConstructorDeclaration)c).getWrappedNode() == constructorDeclaration).findFirst().get(); if (resultClass.isInstance(resolved)) { return resultClass.cast(resolved);
@Override public List<ResolvedConstructorDeclaration> getConstructors() { return findMembersOfKind(com.github.javaparser.ast.body.ConstructorDeclaration.class) .stream() .map(ctor -> new JavaParserConstructorDeclaration(this, ctor, typeSolver)) .collect(Collectors.toList()); }
@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 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); } }
ResolvedConstructorDeclaration resolved = resolvedTypeDeclaration.getConstructors().stream() .filter(c -> c instanceof JavaParserConstructorDeclaration) .filter(c -> ((JavaParserConstructorDeclaration) c).getWrappedNode() == constructorDeclaration) .findFirst() .orElseThrow(() -> new RuntimeException("This constructor cannot be found in its parent. This seems wrong"));
@Override public List<ResolvedConstructorDeclaration> getConstructors() { return findMembersOfKind(com.github.javaparser.ast.body.ConstructorDeclaration.class) .stream() .map(ctor -> new JavaParserConstructorDeclaration(this, ctor, typeSolver)) .collect(Collectors.toList()); }
@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); } }
static <N extends ResolvedReferenceTypeDeclaration> List<ResolvedConstructorDeclaration> getConstructors(NodeWithConstructors<?> wrappedNode, TypeSolver typeSolver, N container) { List<ResolvedConstructorDeclaration> declared = wrappedNode.getConstructors().stream() .map(c -> new JavaParserConstructorDeclaration<N>(container, c, typeSolver)) .collect(Collectors.toList()); if (declared.isEmpty()) { // If there are no constructors insert the default constructor return ImmutableList.of(new DefaultConstructorDeclaration<N>(container)); } else { return declared; } } }
@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 List<ResolvedConstructorDeclaration> getConstructors() { List<ResolvedConstructorDeclaration> declared = new LinkedList<>(); for (BodyDeclaration<?> member : wrappedNode.getMembers()) { if (member instanceof com.github.javaparser.ast.body.ConstructorDeclaration) { com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration = (com.github.javaparser.ast.body.ConstructorDeclaration) member; declared.add(new JavaParserConstructorDeclaration(this, constructorDeclaration, typeSolver)); } } if (declared.isEmpty()) { // If there are no constructors insert the default constructor return ImmutableList.of(new DefaultConstructorDeclaration(this)); } else { return declared; } }
@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(); } }