use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class Java50Fix method createAddOverrideAnnotationOperations.
private static void createAddOverrideAnnotationOperations(CompilationUnit compilationUnit, boolean addOverrideInterfaceAnnotation, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> result) {
for (int i = 0; i < locations.length; i++) {
IProblemLocation problem = locations[i];
int problemId = problem.getProblemId();
if (isMissingOverrideAnnotationProblem(problemId)) {
if (!isMissingOverrideAnnotationInterfaceProblem(problemId) || addOverrideInterfaceAnnotation) {
ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
if (selectedNode != null) {
ASTNode declaringNode = getDeclaringNode(selectedNode);
if (declaringNode instanceof BodyDeclaration) {
BodyDeclaration declaration = (BodyDeclaration) declaringNode;
AnnotationRewriteOperation operation = new AnnotationRewriteOperation(declaration, OVERRIDE);
result.add(operation);
}
}
}
}
}
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class Java50Fix method createFix.
private static Java50Fix createFix(CompilationUnit compilationUnit, IProblemLocation problem, String annotation, String label) {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
return null;
ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
if (selectedNode == null)
return null;
ASTNode declaringNode = getDeclaringNode(selectedNode);
if (!(declaringNode instanceof BodyDeclaration))
return null;
BodyDeclaration declaration = (BodyDeclaration) declaringNode;
AnnotationRewriteOperation operation = new AnnotationRewriteOperation(declaration, annotation);
return new Java50Fix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation });
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class ScopeAnalyzer method addLocalDeclarations.
private boolean addLocalDeclarations(ASTNode node, int offset, int flags, IBindingRequestor requestor) {
if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) {
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(node);
if (declaration instanceof MethodDeclaration || declaration instanceof Initializer || declaration instanceof FieldDeclaration) {
ScopeAnalyzerVisitor visitor = new ScopeAnalyzerVisitor(offset, flags, requestor);
declaration.accept(visitor);
return visitor.fBreak;
}
}
return false;
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class JavadocTagsSubProcessor method getMissingJavadocTagProposals.
public static void getMissingJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
node = ASTNodes.getNormalizedNode(node);
BodyDeclaration bodyDeclaration = ASTResolving.findParentBodyDeclaration(node);
if (bodyDeclaration == null) {
return;
}
Javadoc javadoc = bodyDeclaration.getJavadoc();
if (javadoc == null) {
return;
}
String label;
StructuralPropertyDescriptor location = node.getLocationInParent();
if (location == SingleVariableDeclaration.NAME_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
if (node.getParent().getLocationInParent() != MethodDeclaration.PARAMETERS_PROPERTY) {
// paranoia checks
return;
}
} else if (location == TypeParameter.NAME_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description;
StructuralPropertyDescriptor parentLocation = node.getParent().getLocationInParent();
if (parentLocation != MethodDeclaration.TYPE_PARAMETERS_PROPERTY && parentLocation != TypeDeclaration.TYPE_PARAMETERS_PROPERTY) {
// paranoia checks
return;
}
} else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_returntag_description;
} else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
label = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_throwstag_description;
} else {
return;
}
ASTRewriteCorrectionProposal proposal = new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDeclaration, node, IProposalRelevance.ADD_MISSING_TAG);
proposals.add(proposal);
String label2 = CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description;
ASTRewriteCorrectionProposal addAllMissing = new AddAllMissingJavadocTagsProposal(label2, context.getCompilationUnit(), bodyDeclaration, IProposalRelevance.ADD_ALL_MISSING_TAGS);
proposals.add(addAllMissing);
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class JavadocTagsSubProcessor method getMissingJavadocCommentProposals.
public static void getMissingJavadocCommentProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> 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