use of org.eclipse.jdt.core.dom.TypeDeclaration in project sts4 by spring-projects.
the class WebfluxRouterSymbolProvider method extractNestedValue.
private void extractNestedValue(ASTNode node, Collection<WebfluxRouteElement> values, Function<MethodInvocation, WebfluxRouteElement> extractor) {
if (node == null || node instanceof TypeDeclaration) {
return;
}
if (node instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) node;
IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
if (WebfluxUtils.ROUTER_FUNCTIONS_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (WebfluxUtils.REQUEST_PREDICATE_NEST_METHOD.equals(name)) {
List<?> arguments = methodInvocation.arguments();
for (Object argument : arguments) {
if (argument instanceof MethodInvocation) {
MethodInvocation nestedMethod = (MethodInvocation) argument;
WebfluxRouteElement value = extractor.apply(nestedMethod);
if (value != null) {
values.add(value);
}
}
}
}
}
}
extractNestedValue(node.getParent(), values, extractor);
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project sts4 by spring-projects.
the class ComponentInjectionsHoverProvider method addAutomaticallyWiredContructor.
@Override
protected void addAutomaticallyWiredContructor(StringBuilder hover, Annotation annotation, LiveBeansModel beans, LiveBean bean, IJavaProject project) {
TypeDeclaration typeDecl = ASTUtils.findDeclaringType(annotation);
if (typeDecl != null) {
MethodDeclaration[] constructors = ASTUtils.findConstructors(typeDecl);
if (constructors != null && constructors.length == 1 && !hasAutowiredAnnotation(constructors[0])) {
String[] dependencies = bean.getDependencies();
if (dependencies != null && dependencies.length > 0) {
hover.append("\n\n");
hover.append(LiveHoverUtils.showBean(bean) + " got autowired with:\n\n");
boolean firstDependency = true;
for (String injectedBean : dependencies) {
if (!firstDependency) {
hover.append("\n");
}
List<LiveBean> dependencyBeans = beans.getBeansOfName(injectedBean);
for (LiveBean dependencyBean : dependencyBeans) {
hover.append("- " + LiveHoverUtils.showBeanWithResource(server, dependencyBean, " ", project));
}
firstDependency = false;
}
}
}
}
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse.jdt.ls by eclipse.
the class UnresolvedElementsSubProcessor method addNewTypeProposals.
public static void addNewTypeProposals(ICompilationUnit cu, Name refNode, int kind, int relevance, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
Name node = refNode;
do {
String typeName = ASTNodes.getSimpleNameIdentifier(node);
Name qualifier = null;
// only propose to create types for qualifiers when the name starts with upper case
boolean isPossibleName = isLikelyTypeName(typeName) || node == refNode;
if (isPossibleName) {
IPackageFragment enclosingPackage = null;
IType enclosingType = null;
if (node.isSimpleName()) {
enclosingPackage = (IPackageFragment) cu.getParent();
// don't suggest member type, user can select it in wizard
} else {
Name qualifierName = ((QualifiedName) node).getQualifier();
IBinding binding = qualifierName.resolveBinding();
if (binding != null && binding.isRecovered()) {
binding = null;
}
if (binding instanceof ITypeBinding) {
enclosingType = (IType) binding.getJavaElement();
} else if (binding instanceof IPackageBinding) {
qualifier = qualifierName;
enclosingPackage = (IPackageFragment) binding.getJavaElement();
} else {
IJavaElement[] res = cu.codeSelect(qualifierName.getStartPosition(), qualifierName.getLength());
if (res != null && res.length > 0 && res[0] instanceof IType) {
enclosingType = (IType) res[0];
} else {
qualifier = qualifierName;
enclosingPackage = JavaModelUtil.getPackageFragmentRoot(cu).getPackageFragment(ASTResolving.getFullName(qualifierName));
}
}
}
int rel = relevance;
if (enclosingPackage != null && isLikelyPackageName(enclosingPackage.getElementName())) {
rel += 3;
}
if (enclosingPackage != null && !enclosingPackage.getCompilationUnit(typeName + JavaModelUtil.DEFAULT_CU_SUFFIX).exists() || enclosingType != null && !enclosingType.isReadOnly() && !enclosingType.getType(typeName).exists()) {
// new member type
IJavaElement enclosing = enclosingPackage != null ? (IJavaElement) enclosingPackage : enclosingType;
if ((kind & TypeKinds.CLASSES) != 0) {
proposals.add(new NewCUProposal(cu, node, NewCUProposal.K_CLASS, enclosing, rel + 3));
}
if ((kind & TypeKinds.INTERFACES) != 0) {
proposals.add(new NewCUProposal(cu, node, NewCUProposal.K_INTERFACE, enclosing, rel + 2));
}
if ((kind & TypeKinds.ENUMS) != 0) {
proposals.add(new NewCUProposal(cu, node, NewCUProposal.K_ENUM, enclosing, rel));
}
if ((kind & TypeKinds.ANNOTATIONS) != 0) {
proposals.add(new NewCUProposal(cu, node, NewCUProposal.K_ANNOTATION, enclosing, rel + 1));
// TODO: addNullityAnnotationTypesProposals(cu, node, proposals);
}
}
}
node = qualifier;
} while (node != null);
// type parameter proposals
if (refNode.isSimpleName() && (kind & TypeKinds.VARIABLES) != 0) {
CompilationUnit root = (CompilationUnit) refNode.getRoot();
String name = ((SimpleName) refNode).getIdentifier();
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(refNode);
int baseRel = relevance;
if (isLikelyTypeParameterName(name)) {
baseRel += 8;
}
while (declaration != null) {
IBinding binding = null;
int rel = baseRel;
if (declaration instanceof MethodDeclaration) {
binding = ((MethodDeclaration) declaration).resolveBinding();
if (isLikelyMethodTypeParameterName(name)) {
rel += 2;
}
} else if (declaration instanceof TypeDeclaration) {
binding = ((TypeDeclaration) declaration).resolveBinding();
rel++;
}
if (binding != null) {
AddTypeParameterProposal proposal = new AddTypeParameterProposal(cu, binding, root, name, null, rel);
proposals.add(proposal);
}
if (!Modifier.isStatic(declaration.getModifiers())) {
declaration = ASTResolving.findParentBodyDeclaration(declaration.getParent());
} else {
declaration = null;
}
}
}
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse.jdt.ls by eclipse.
the class LocalCorrectionsSubProcessor method addConstructorFromSuperclassProposal.
public static void addConstructorFromSuperclassProposal(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
TypeDeclaration typeDeclaration = null;
if (selectedNode.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) {
typeDeclaration = (TypeDeclaration) selectedNode.getParent();
} else {
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(selectedNode);
if (declaration instanceof Initializer && problem.getProblemId() == IProblem.UnhandledExceptionInDefaultConstructor) {
addUncaughtExceptionProposals(context, problem, proposals);
}
return;
}
ITypeBinding binding = typeDeclaration.resolveBinding();
if (binding == null || binding.getSuperclass() == null) {
return;
}
ICompilationUnit cu = context.getCompilationUnit();
IMethodBinding[] methods = binding.getSuperclass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
IMethodBinding curr = methods[i];
if (curr.isConstructor() && !Modifier.isPrivate(curr.getModifiers())) {
proposals.add(new ConstructorFromSuperclassProposal(cu, typeDeclaration, curr, IProposalRelevance.ADD_CONSTRUCTOR_FROM_SUPER_CLASS));
}
}
}
use of org.eclipse.jdt.core.dom.TypeDeclaration in project eclipse.jdt.ls by eclipse.
the class JavadocTagsSubProcessor method getMissingJavadocCommentProposals.
public static void getMissingJavadocCommentProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(node);
if (declaration == null) {
return;
}
ICompilationUnit cu = context.getCompilationUnit();
ITypeBinding binding = Bindings.getBindingOfParentType(declaration);
if (binding == null) {
return;
}
if (declaration instanceof MethodDeclaration) {
MethodDeclaration methodDecl = (MethodDeclaration) declaration;
IMethodBinding methodBinding = methodDecl.resolveBinding();
IMethodBinding overridden = null;
if (methodBinding != null) {
overridden = Bindings.findOverriddenMethod(methodBinding, true);
}
String string = CodeGeneration.getMethodComment(cu, binding.getName(), methodDecl, overridden, String.valueOf('\n'));
if (string != null) {
String label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_method_description;
proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_METHOD, declaration.getStartPosition(), string));
}
} else if (declaration instanceof AbstractTypeDeclaration) {
String typeQualifiedName = Bindings.getTypeQualifiedName(binding);
String[] typeParamNames;
if (declaration instanceof TypeDeclaration) {
List<TypeParameter> typeParams = ((TypeDeclaration) declaration).typeParameters();
typeParamNames = new String[typeParams.size()];
for (int i = 0; i < typeParamNames.length; i++) {
typeParamNames[i] = (typeParams.get(i)).getName().getIdentifier();
}
} else {
typeParamNames = new String[0];
}
String string = CodeGeneration.getTypeComment(cu, typeQualifiedName, typeParamNames, String.valueOf('\n'));
if (string != null) {
String label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_type_description;
proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_TYPE, declaration.getStartPosition(), string));
}
} else if (declaration instanceof FieldDeclaration) {
// $NON-NLS-1$
String comment = "/**\n *\n */\n";
List<VariableDeclarationFragment> fragments = ((FieldDeclaration) declaration).fragments();
if (fragments != null && fragments.size() > 0) {
VariableDeclaration decl = fragments.get(0);
String fieldName = decl.getName().getIdentifier();
String typeName = binding.getName();
comment = CodeGeneration.getFieldComment(cu, typeName, fieldName, String.valueOf('\n'));
}
if (comment != null) {
String label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_field_description;
proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_FIELD, declaration.getStartPosition(), comment));
}
} else if (declaration instanceof EnumConstantDeclaration) {
EnumConstantDeclaration enumDecl = (EnumConstantDeclaration) declaration;
String id = enumDecl.getName().getIdentifier();
String comment = CodeGeneration.getFieldComment(cu, binding.getName(), id, String.valueOf('\n'));
String label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_enumconst_description;
proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_ENUM, declaration.getStartPosition(), comment));
}
}
Aggregations