本文整理汇总了Java中org.eclipse.jdt.internal.corext.dom.ASTNodes.getNormalizedNode方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNodes.getNormalizedNode方法的具体用法?Java ASTNodes.getNormalizedNode怎么用?Java ASTNodes.getNormalizedNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.dom.ASTNodes
的用法示例。
在下文中一共展示了ASTNodes.getNormalizedNode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isIntroduceFactoryAvailable
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static boolean isIntroduceFactoryAvailable(final JavaTextSelection selection)
throws JavaModelException {
final IJavaElement[] elements = selection.resolveElementAtOffset();
if (elements.length == 1 && elements[0] instanceof IMethod)
return isIntroduceFactoryAvailable((IMethod) elements[0]);
// there's no IMethod for the default constructor
if (!Checks.isAvailable(selection.resolveEnclosingElement())) return false;
ASTNode node = selection.resolveCoveringNode();
if (node == null) {
ASTNode[] selectedNodes = selection.resolveSelectedNodes();
if (selectedNodes != null && selectedNodes.length == 1) {
node = selectedNodes[0];
if (node == null) return false;
} else {
return false;
}
}
if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return true;
node = ASTNodes.getNormalizedNode(node);
if (node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) return true;
return false;
}
示例2: getTargetNode
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
/**
* Finds and returns the <code>ASTNode</code> for the given source text selection, if it is an
* entire constructor call or the class name portion of a constructor call or constructor
* declaration, or null otherwise.
*
* @param unit The compilation unit in which the selection was made
* @param offset The textual offset of the start of the selection
* @param length The length of the selection in characters
* @return ClassInstanceCreation or MethodDeclaration
*/
private ASTNode getTargetNode(ICompilationUnit unit, int offset, int length) {
ASTNode node = ASTNodes.getNormalizedNode(NodeFinder.perform(fCU, offset, length));
if (node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) return node;
if (node.getNodeType() == ASTNode.METHOD_DECLARATION
&& ((MethodDeclaration) node).isConstructor()) return node;
// we have some sub node. Make sure its the right child of the parent
StructuralPropertyDescriptor location = node.getLocationInParent();
ASTNode parent = node.getParent();
if (location == ClassInstanceCreation.TYPE_PROPERTY) {
return parent;
} else if (location == MethodDeclaration.NAME_PROPERTY
&& ((MethodDeclaration) parent).isConstructor()) {
return parent;
}
return null;
}
示例3: addRedundantSuperInterfaceProposal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static void addRedundantSuperInterfaceProposal(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof Name)) {
return;
}
ASTNode node = ASTNodes.getNormalizedNode(selectedNode);
ASTRewrite rewrite = ASTRewrite.create(node.getAST());
rewrite.remove(node, null);
String label = CorrectionMessages.LocalCorrectionsSubProcessor_remove_redundant_superinterface;
Image image =
JavaPluginImages.get(
JavaPluginImages
.IMG_TOOL_DELETE); // JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
rewrite,
IProposalRelevance.REMOVE_REDUNDANT_SUPER_INTERFACE,
image);
proposals.add(proposal);
}
示例4: removeMismatchedArguments
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static void removeMismatchedArguments(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveredNode(context.getASTRoot());
if (!(selectedNode instanceof SimpleName)) {
return;
}
ASTNode normalizedNode = ASTNodes.getNormalizedNode(selectedNode);
if (normalizedNode instanceof ParameterizedType) {
ASTRewrite rewrite = ASTRewrite.create(normalizedNode.getAST());
ParameterizedType pt = (ParameterizedType) normalizedNode;
ASTNode mt = rewrite.createMoveTarget(pt.getType());
rewrite.replace(pt, mt, null);
String label = CorrectionMessages.TypeArgumentMismatchSubProcessor_removeTypeArguments;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label, cu, rewrite, IProposalRelevance.REMOVE_TYPE_ARGUMENTS, image);
proposals.add(proposal);
}
}
示例5: addUnnecessaryThrownExceptionProposal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static void addUnnecessaryThrownExceptionProposal(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
selectedNode = ASTNodes.getNormalizedNode(selectedNode);
if (selectedNode == null
|| selectedNode.getLocationInParent()
!= MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
return;
}
MethodDeclaration decl = (MethodDeclaration) selectedNode.getParent();
IMethodBinding binding = decl.resolveBinding();
if (binding != null) {
List<Type> thrownExceptions = decl.thrownExceptionTypes();
int index = thrownExceptions.indexOf(selectedNode);
if (index == -1) {
return;
}
ChangeDescription[] desc = new ChangeDescription[thrownExceptions.size()];
desc[index] = new RemoveDescription();
ICompilationUnit cu = context.getCompilationUnit();
String label = CorrectionMessages.LocalCorrectionsSubProcessor_unnecessarythrow_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION);
proposals.add(
new ChangeMethodSignatureProposal(
label,
cu,
selectedNode,
binding,
null,
desc,
IProposalRelevance.UNNECESSARY_THROW,
image));
}
JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(
context, problem, proposals);
}
示例6: getPossibleSuperTypeBinding
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private ITypeBinding getPossibleSuperTypeBinding(ASTNode node) {
if (fTypeKind == K_ANNOTATION) {
return null;
}
AST ast = node.getAST();
node = ASTNodes.getNormalizedNode(node);
ASTNode parent = node.getParent();
switch (parent.getNodeType()) {
case ASTNode.METHOD_DECLARATION:
if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
return ast.resolveWellKnownType("java.lang.Exception"); // $NON-NLS-1$
}
break;
case ASTNode.THROW_STATEMENT:
return ast.resolveWellKnownType("java.lang.Exception"); // $NON-NLS-1$
case ASTNode.SINGLE_VARIABLE_DECLARATION:
if (parent.getLocationInParent() == CatchClause.EXCEPTION_PROPERTY) {
return ast.resolveWellKnownType("java.lang.Exception"); // $NON-NLS-1$
}
break;
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
case ASTNode.FIELD_DECLARATION:
return null; // no guessing for LHS types, cannot be a supertype of a known type
case ASTNode.PARAMETERIZED_TYPE:
return null; // Inheritance doesn't help: A<X> z= new A<String>(); ->
}
ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
if (binding != null && !binding.isRecovered()) {
return binding;
}
return null;
}
示例7: getBinding
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
/**
* Extracts the binding from the token's simple name. Works around bug 62605 to return the correct
* constructor binding in a ClassInstanceCreation.
*
* @param token the token to extract the binding from
* @return the token's binding, or <code>null</code>
*/
private static IBinding getBinding(SemanticToken token) {
ASTNode node = token.getNode();
ASTNode normalized = ASTNodes.getNormalizedNode(node);
if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
// work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
return ((ClassInstanceCreation) normalized.getParent()).resolveConstructorBinding();
}
return token.getBinding();
}
示例8: addTypeArgumentsFromContext
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static void addTypeArgumentsFromContext(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
// similar to UnresolvedElementsSubProcessor.getTypeProposals(context, problem, proposals);
ICompilationUnit cu = context.getCompilationUnit();
CompilationUnit root = context.getASTRoot();
ASTNode selectedNode = problem.getCoveringNode(root);
if (selectedNode == null) {
return;
}
while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
selectedNode = selectedNode.getParent();
}
Name node = null;
if (selectedNode instanceof SimpleType) {
node = ((SimpleType) selectedNode).getName();
} else if (selectedNode instanceof NameQualifiedType) {
node = ((NameQualifiedType) selectedNode).getName();
} else if (selectedNode instanceof ArrayType) {
Type elementType = ((ArrayType) selectedNode).getElementType();
if (elementType.isSimpleType()) {
node = ((SimpleType) elementType).getName();
} else if (elementType.isNameQualifiedType()) {
node = ((NameQualifiedType) elementType).getName();
} else {
return;
}
} else if (selectedNode instanceof Name) {
node = (Name) selectedNode;
} else {
return;
}
// try to resolve type in context
ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
if (binding != null) {
ASTNode parent = node.getParent();
if (parent instanceof Type
&& parent.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY
&& binding.isInterface()) { // bug 351853
return;
}
ITypeBinding simpleBinding = binding;
if (simpleBinding.isArray()) {
simpleBinding = simpleBinding.getElementType();
}
simpleBinding = simpleBinding.getTypeDeclaration();
if (!simpleBinding.isRecovered()) {
if (binding.isParameterizedType()
&& (node.getParent() instanceof SimpleType
|| node.getParent() instanceof NameQualifiedType)
&& !(node.getParent().getParent() instanceof Type)) {
proposals.add(
UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(
cu, binding, node, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
}
}
} else {
ASTNode normalizedNode = ASTNodes.getNormalizedNode(node);
if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
ITypeBinding normBinding = ASTResolving.guessBindingForTypeReference(normalizedNode);
if (normBinding != null && !normBinding.isRecovered()) {
proposals.add(
UnresolvedElementsSubProcessor.createTypeRefChangeFullProposal(
cu, normBinding, normalizedNode, IProposalRelevance.TYPE_ARGUMENTS_FROM_CONTEXT));
}
}
}
}
示例9: getConvertAnonymousToNestedProposal
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean getConvertAnonymousToNestedProposal(
IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals)
throws CoreException {
if (!(node instanceof Name)) return false;
ASTNode normalized = ASTNodes.getNormalizedNode(node);
if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) return false;
final AnonymousClassDeclaration anonymTypeDecl =
((ClassInstanceCreation) normalized.getParent()).getAnonymousClassDeclaration();
if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) {
return false;
}
if (proposals == null) {
return true;
}
final ICompilationUnit cu = context.getCompilationUnit();
final ConvertAnonymousToNestedRefactoring refactoring =
new ConvertAnonymousToNestedRefactoring(anonymTypeDecl);
String extTypeName = ASTNodes.getSimpleNameIdentifier((Name) node);
ITypeBinding anonymTypeBinding = anonymTypeDecl.resolveBinding();
String className;
if (anonymTypeBinding.getInterfaces().length == 0) {
className =
Messages.format(
CorrectionMessages.QuickAssistProcessor_name_extension_from_interface, extTypeName);
} else {
className =
Messages.format(
CorrectionMessages.QuickAssistProcessor_name_extension_from_class, extTypeName);
}
String[][] existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className);
int i = 1;
while (existingTypes != null) {
i++;
existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className + i);
}
refactoring.setClassName(i == 1 ? className : className + i);
if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
refactoring.setLinkedProposalModel(linkedProposalModel);
String label = CorrectionMessages.QuickAssistProcessor_convert_anonym_to_nested;
Image image =
JavaPlugin.getImageDescriptorRegistry()
.get(
JavaElementImageProvider.getTypeImageDescriptor(
true, false, Flags.AccPrivate, false));
RefactoringCorrectionProposal proposal =
new RefactoringCorrectionProposal(
label, cu, refactoring, IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED, image);
proposal.setLinkedProposalModel(linkedProposalModel);
proposal.setCommandId(CONVERT_ANONYMOUS_TO_LOCAL_ID);
proposals.add(proposal);
}
return false;
}
示例10: getConvertAnonymousClassCreationsToLambdaProposals
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean getConvertAnonymousClassCreationsToLambdaProposals(
IInvocationContext context,
ASTNode covering,
Collection<ICommandAccess> resultingCollections) {
while (covering instanceof Name
|| covering instanceof Type
|| covering instanceof Dimension
|| covering.getParent() instanceof MethodDeclaration
|| covering.getLocationInParent() == AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY) {
covering = covering.getParent();
}
ClassInstanceCreation cic;
if (covering instanceof ClassInstanceCreation) {
cic = (ClassInstanceCreation) covering;
} else if (covering.getLocationInParent()
== ClassInstanceCreation.ANONYMOUS_CLASS_DECLARATION_PROPERTY) {
cic = (ClassInstanceCreation) covering.getParent();
} else if (covering instanceof Name) {
ASTNode normalized = ASTNodes.getNormalizedNode(covering);
if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) return false;
cic = (ClassInstanceCreation) normalized.getParent();
} else {
return false;
}
IProposableFix fix = LambdaExpressionsFix.createConvertToLambdaFix(cic);
if (fix == null) return false;
if (resultingCollections == null) return true;
// add correction proposal
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
Map<String, String> options = new Hashtable<String, String>();
options.put(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptions.TRUE);
options.put(CleanUpConstants.USE_LAMBDA, CleanUpOptions.TRUE);
FixCorrectionProposal proposal =
new FixCorrectionProposal(
fix,
new ExpressionsCleanUp(options),
IProposalRelevance.CONVERT_TO_LAMBDA_EXPRESSION,
image,
context);
resultingCollections.add(proposal);
return true;
}
示例11: getAssignParamToFieldProposals
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean getAssignParamToFieldProposals(
IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
node = ASTNodes.getNormalizedNode(node);
ASTNode parent = node.getParent();
if (!(parent instanceof SingleVariableDeclaration)
|| !(parent.getParent() instanceof MethodDeclaration)) {
return false;
}
SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) parent;
IVariableBinding binding = paramDecl.resolveBinding();
MethodDeclaration methodDecl = (MethodDeclaration) parent.getParent();
if (binding == null || methodDecl.getBody() == null) {
return false;
}
ITypeBinding typeBinding = binding.getType();
if (typeBinding == null) {
return false;
}
if (resultingCollections == null) {
return true;
}
ITypeBinding parentType = Bindings.getBindingOfParentType(node);
if (parentType != null) {
if (parentType.isInterface()) {
return false;
}
// assign to existing fields
CompilationUnit root = context.getASTRoot();
IVariableBinding[] declaredFields = parentType.getDeclaredFields();
boolean isStaticContext = ASTResolving.isInStaticContext(node);
for (int i = 0; i < declaredFields.length; i++) {
IVariableBinding curr = declaredFields[i];
if (isStaticContext == Modifier.isStatic(curr.getModifiers())
&& typeBinding.isAssignmentCompatible(curr.getType())) {
ASTNode fieldDeclFrag = root.findDeclaringNode(curr);
if (fieldDeclFrag instanceof VariableDeclarationFragment) {
VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclFrag;
if (fragment.getInitializer() == null) {
resultingCollections.add(
new AssignToVariableAssistProposal(
context.getCompilationUnit(),
paramDecl,
fragment,
typeBinding,
IProposalRelevance.ASSIGN_PARAM_TO_EXISTING_FIELD));
}
}
}
}
}
AssignToVariableAssistProposal fieldProposal =
new AssignToVariableAssistProposal(
context.getCompilationUnit(),
paramDecl,
null,
typeBinding,
IProposalRelevance.ASSIGN_PARAM_TO_NEW_FIELD);
fieldProposal.setCommandId(ASSIGN_PARAM_TO_FIELD_ID);
resultingCollections.add(fieldProposal);
return true;
}
示例12: addSimilarTypeProposals
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static void addSimilarTypeProposals(
int kind, ICompilationUnit cu, Name node, int relevance, Collection<ICommandAccess> proposals)
throws CoreException {
SimilarElement[] elements = SimilarElementsRequestor.findSimilarElement(cu, node, kind);
// try to resolve type in context -> highest severity
String resolvedTypeName = null;
ITypeBinding binding = ASTResolving.guessBindingForTypeReference(node);
if (binding != null) {
ITypeBinding simpleBinding = binding;
if (simpleBinding.isArray()) {
simpleBinding = simpleBinding.getElementType();
}
simpleBinding = simpleBinding.getTypeDeclaration();
if (!simpleBinding.isRecovered()) {
resolvedTypeName = simpleBinding.getQualifiedName();
CUCorrectionProposal proposal =
createTypeRefChangeProposal(cu, resolvedTypeName, node, relevance + 2, elements.length);
proposals.add(proposal);
if (proposal instanceof AddImportCorrectionProposal)
proposal.setRelevance(relevance + elements.length + 2);
if (binding.isParameterizedType()
&& (node.getParent() instanceof SimpleType
|| node.getParent() instanceof NameQualifiedType)
&& !(node.getParent().getParent() instanceof Type)) {
proposals.add(createTypeRefChangeFullProposal(cu, binding, node, relevance + 5));
}
}
} else {
ASTNode normalizedNode = ASTNodes.getNormalizedNode(node);
if (!(normalizedNode.getParent() instanceof Type) && node.getParent() != normalizedNode) {
ITypeBinding normBinding = ASTResolving.guessBindingForTypeReference(normalizedNode);
if (normBinding != null && !normBinding.isRecovered()) {
proposals.add(
createTypeRefChangeFullProposal(cu, normBinding, normalizedNode, relevance + 5));
}
}
}
// add all similar elements
for (int i = 0; i < elements.length; i++) {
SimilarElement elem = elements[i];
if ((elem.getKind() & SimilarElementsRequestor.ALL_TYPES) != 0) {
String fullName = elem.getName();
if (!fullName.equals(resolvedTypeName)) {
proposals.add(
createTypeRefChangeProposal(cu, fullName, node, relevance, elements.length));
}
}
}
}
示例13: getMissingJavadocTagProposals
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
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) {
return; // paranoia checks
}
} 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) {
return; // paranoia checks
}
} 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);
}
示例14: getUnusedAndUndocumentedParameterOrExceptionProposals
import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static void getUnusedAndUndocumentedParameterOrExceptionProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
IJavaProject project = cu.getJavaProject();
if (!JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true))) {
return;
}
int problemId = problem.getProblemId();
boolean isUnusedTypeParam = problemId == IProblem.UnusedTypeParameter;
boolean isUnusedParam = problemId == IProblem.ArgumentIsNeverUsed || isUnusedTypeParam;
String key =
isUnusedParam
? JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE
: JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_INCLUDE_DOC_COMMENT_REFERENCE;
if (!JavaCore.ENABLED.equals(project.getOption(key, true))) {
return;
}
ASTNode node = problem.getCoveringNode(context.getASTRoot());
if (node == null) {
return;
}
BodyDeclaration bodyDecl = ASTResolving.findParentBodyDeclaration(node);
if (bodyDecl == null || ASTResolving.getParentMethodOrTypeBinding(bodyDecl) == null) {
return;
}
String label;
if (isUnusedTypeParam) {
label = CorrectionMessages.JavadocTagsSubProcessor_document_type_parameter_description;
} else if (isUnusedParam) {
label = CorrectionMessages.JavadocTagsSubProcessor_document_parameter_description;
} else {
node = ASTNodes.getNormalizedNode(node);
label = CorrectionMessages.JavadocTagsSubProcessor_document_exception_description;
}
ASTRewriteCorrectionProposal proposal =
new AddMissingJavadocTagProposal(
label,
context.getCompilationUnit(),
bodyDecl,
node,
IProposalRelevance.DOCUMENT_UNUSED_ITEM);
proposals.add(proposal);
}