org.eclipse.jdt.ui.text.java.IProblemLocation Java Examples

The following examples show how to use org.eclipse.jdt.ui.text.java.IProblemLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NullAnnotationsCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fix for {@link IProblem#NullableFieldReference}
 * @param context context
 * @param problem problem to be fixed
 * @param proposals accumulator for computed proposals
 */
public static void addExtractCheckedLocalProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	CompilationUnit compilationUnit = context.getASTRoot();
	ICompilationUnit cu= (ICompilationUnit) compilationUnit.getJavaElement();

	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

	SimpleName name= findProblemFieldName(selectedNode, problem.getProblemId());
	if (name == null)
		return;

	ASTNode method= ASTNodes.getParent(selectedNode, MethodDeclaration.class);
	if (method == null)
		method= ASTNodes.getParent(selectedNode, Initializer.class);
	if (method == null)
		return;
	
	proposals.add(new ExtractToNullCheckedLocalProposal(cu, compilationUnit, name, method));
}
 
Example #2
Source File: QuickFixProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
	if (locations == null || locations.length == 0) {
		return null;
	}

	HashSet<Integer> handledProblems= new HashSet<Integer>(locations.length);
	ArrayList<ICommandAccess> resultingCollections= new ArrayList<ICommandAccess>();
	for (int i= 0; i < locations.length; i++) {
		IProblemLocation curr= locations[i];
		Integer id= new Integer(curr.getProblemId());
		if (handledProblems.add(id)) {
			process(context, curr, resultingCollections);
		}
	}
	return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
 
Example #3
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static CompilationUnitRewriteOperationsFix[] createNonStaticAccessFixes(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (!isNonStaticAccess(problem))
		return null;

	ToStaticAccessOperation operations[]= createToStaticAccessOperations(compilationUnit, new HashMap<ASTNode, Block>(), problem, false);
	if (operations == null)
		return null;

	String label1= Messages.format(FixMessages.CodeStyleFix_ChangeAccessToStatic_description, operations[0].getAccessorName());
	CompilationUnitRewriteOperationsFix fix1= new CompilationUnitRewriteOperationsFix(label1, compilationUnit, operations[0]);

	if (operations.length > 1) {
		String label2= Messages.format(FixMessages.CodeStyleFix_ChangeAccessToStaticUsingInstanceType_description, operations[1].getAccessorName());
		CompilationUnitRewriteOperationsFix fix2= new CompilationUnitRewriteOperationsFix(label2, compilationUnit, operations[1]);
		return new CompilationUnitRewriteOperationsFix[] {fix1, fix2};
	}
	return new CompilationUnitRewriteOperationsFix[] {fix1};
}
 
Example #4
Source File: CodeStyleFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static AddThisQualifierOperation getUnqualifiedFieldAccessResolveOperation(CompilationUnit compilationUnit, IProblemLocation problem) {
	SimpleName name= getName(compilationUnit, problem);
	if (name == null)
		return null;

	IBinding binding= name.resolveBinding();
	if (binding == null || binding.getKind() != IBinding.VARIABLE)
		return null;

	ImportRewrite imports= StubUtility.createImportRewrite(compilationUnit, true);

	String replacement= getThisExpressionQualifier(((IVariableBinding) binding).getDeclaringClass(), imports, name);
	if (replacement == null)
		return null;

	if (replacement.length() == 0)
		replacement= null;

	return new AddThisQualifierOperation(replacement, name);
}
 
Example #5
Source File: UnimplementedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ASTNode getSelectedTypeNode(CompilationUnit root, IProblemLocation problem) {
	ASTNode selectedNode= problem.getCoveringNode(root);
	if (selectedNode == null)
		return null;

	if (selectedNode.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION) { // bug 200016
		selectedNode= selectedNode.getParent();
	}

	if (selectedNode.getLocationInParent() == EnumConstantDeclaration.NAME_PROPERTY) {
		selectedNode= selectedNode.getParent();
	}
	if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME && selectedNode.getParent() instanceof AbstractTypeDeclaration) {
		return selectedNode.getParent();
	} else if (selectedNode.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
		return ((ClassInstanceCreation) selectedNode).getAnonymousClassDeclaration();
	} else if (selectedNode.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
		EnumConstantDeclaration enumConst= (EnumConstantDeclaration) selectedNode;
		if (enumConst.getAnonymousClassDeclaration() != null)
			return enumConst.getAnonymousClassDeclaration();
		return enumConst;
	} else {
		return null;
	}
}
 
Example #6
Source File: Java50Fix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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});
}
 
Example #7
Source File: Java50Fix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void createAddDeprecatedAnnotationOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> result) {
	for (int i= 0; i < locations.length; i++) {
		IProblemLocation problem= locations[i];

		if (isMissingDeprecationProblem(problem.getProblemId())) {
			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, DEPRECATED);
					result.add(operation);
				}
			}
		}
	}
}
 
Example #8
Source File: UnimplementedCodeCleanUp.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int computeNumberOfFixes(CompilationUnit compilationUnit) {
	if (!isEnabled(CleanUpConstants.ADD_MISSING_METHODES) && !isEnabled(MAKE_TYPE_ABSTRACT))
		return 0;

	IProblemLocation[] locations= filter(convertProblems(compilationUnit.getProblems()), new int[] { IProblem.AbstractMethodMustBeImplemented, IProblem.EnumConstantMustImplementAbstractMethod });

	HashSet<ASTNode> types= new HashSet<ASTNode>();
	for (int i= 0; i < locations.length; i++) {
		ASTNode type= UnimplementedCodeFix.getSelectedTypeNode(compilationUnit, locations[i]);
		if (type != null) {
			types.add(type);
		}
	}

	return types.size();
}
 
Example #9
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static UnusedCodeFix createUnusedMemberFix(CompilationUnit compilationUnit, IProblemLocation problem, boolean removeAllAssignements) {
	if (isUnusedMember(problem)) {
		SimpleName name= getUnusedName(compilationUnit, problem);
		if (name != null) {
			IBinding binding= name.resolveBinding();
			if (binding != null) {
				if (isFormalParameterInEnhancedForStatement(name))
					return null;

				String label= getDisplayString(name, binding, removeAllAssignements);
				RemoveUnusedMemberOperation operation= new RemoveUnusedMemberOperation(new SimpleName[] { name }, removeAllAssignements);
				return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, removeAllAssignements));
			}
		}
	}
	return null;
}
 
Example #10
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
static boolean noErrorsAtLocation(IProblemLocation[] locations) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			if (location.isError()) {
				if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType())
						&& JavaCore.getOptionForConfigurableSeverity(location.getProblemId()) != null) {
					// continue (only drop out for severe (non-optional) errors)
				} else {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #11
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static UnusedCodeFix createRemoveUnusedCastFix(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (problem.getProblemId() != IProblem.UnnecessaryCast)
		return null;

	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

	ASTNode curr= selectedNode;
	while (curr instanceof ParenthesizedExpression) {
		curr= ((ParenthesizedExpression) curr).getExpression();
	}

	if (!(curr instanceof CastExpression))
		return null;

	return new UnusedCodeFix(FixMessages.UnusedCodeFix_RemoveCast_description, compilationUnit, new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression)curr)});
}
 
Example #12
Source File: ReturnTypeSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addMethodRetunsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws JavaModelException {
	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (!(selectedNode instanceof ReturnStatement)) {
		return;
	}
	ReturnStatement returnStatement= (ReturnStatement) selectedNode;
	Expression expression= returnStatement.getExpression();
	if (expression == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methDecl= (MethodDeclaration) decl;
		Type retType= methDecl.getReturnType2();
		if (retType == null || retType.resolveBinding() == null) {
			return;
		}
		TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
	}
}
 
Example #13
Source File: ModifierCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addNeedToEmulateProposal(IInvocationContext context, IProblemLocation problem, Collection<ModifierChangeCorrectionProposal> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (!(selectedNode instanceof SimpleName)) {
		return;
	}

	IBinding binding= ((SimpleName) selectedNode).resolveBinding();
	if (binding instanceof IVariableBinding) {
		binding= ((IVariableBinding) binding).getVariableDeclaration();
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		String label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertofinal_description, BasicElementLabels.getJavaElementName(binding.getName()));
		proposals.add(new ModifierChangeCorrectionProposal(label, cu, binding, selectedNode, Modifier.FINAL, 0, IProposalRelevance.CHANGE_MODIFIER_OF_VARIABLE_TO_FINAL, image));
	}
}
 
Example #14
Source File: CorrectionMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IProblemLocation createFromMarker(IMarker marker, ICompilationUnit cu) {
	try {
		int id= marker.getAttribute(IJavaModelMarker.ID, -1);
		int start= marker.getAttribute(IMarker.CHAR_START, -1);
		int end= marker.getAttribute(IMarker.CHAR_END, -1);
		int severity= marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
		String[] arguments= CorrectionEngine.getProblemArguments(marker);
		String markerType= marker.getType();
		if (cu != null && id != -1 && start != -1 && end != -1 && arguments != null) {
			boolean isError= (severity == IMarker.SEVERITY_ERROR);
			return new ProblemLocation(start, end - start, id, arguments, isError, markerType);
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #15
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void getMissingEnumConstantCaseProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	for (Iterator<ICommandAccess> iterator= proposals.iterator(); iterator.hasNext();) {
		ICommandAccess proposal= iterator.next();
		if (proposal instanceof ChangeCorrectionProposal) {
			if (CorrectionMessages.LocalCorrectionsSubProcessor_add_missing_cases_description.equals(((ChangeCorrectionProposal) proposal).getName())) {
				return;
			}
		}
	}
	
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) {
		SwitchStatement statement= (SwitchStatement) selectedNode.getParent();
		ITypeBinding binding= statement.getExpression().resolveTypeBinding();
		if (binding == null || !binding.isEnum()) {
			return;
		}

		ArrayList<String> missingEnumCases= new ArrayList<String>();
		boolean hasDefault= evaluateMissingSwitchCases(binding, statement.statements(), missingEnumCases);
		if (missingEnumCases.size() == 0 && hasDefault)
			return;

		createMissingCaseProposals(context, statement, missingEnumCases, proposals);
	}
}
 
Example #16
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) {
		AST ast= selectedNode.getAST();
		SwitchStatement parent= (SwitchStatement) selectedNode.getParent();
		
		for (Statement statement : (List<Statement>) parent.statements()) {
			if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) {
				
				// insert //$CASES-OMITTED$:
				ASTRewrite rewrite= ASTRewrite.create(ast);
				rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer());
				ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
				ASTNode casesOmittedComment= rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
				listRewrite.insertBefore(casesOmittedComment, statement, null);
				
				String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted;
				Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
				ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED, image);
				proposals.add(proposal);
				break;
			}
		}
	}
}
 
Example #17
Source File: NullAnnotationsCleanUp.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ICleanUpFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException {
	if (compilationUnit == null)
		return null;
	IProblemLocation[] locations= null;
	ArrayList<IProblemLocation> filteredLocations= new ArrayList<IProblemLocation>();
	if (problems != null) {
		for (int i= 0; i < problems.length; i++) {
			if (problems[i].getProblemId() == this.handledProblemID)
				filteredLocations.add(problems[i]);
		}
		locations= filteredLocations.toArray(new IProblemLocation[filteredLocations.size()]);
	}
	return NullAnnotationsFix.createCleanUp(compilationUnit, locations, this.handledProblemID);
}
 
Example #18
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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= 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);

}
 
Example #19
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addUnusedMemberProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	int problemId = problem.getProblemId();
	UnusedCodeFix fix= UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, false);
	if (fix != null) {
		addProposal(context, proposals, fix);
	}

	if (problemId==IProblem.LocalVariableIsNeverUsed){
		fix= UnusedCodeFix.createUnusedMemberFix(context.getASTRoot(), problem, true);
		addProposal(context, proposals, fix);
	}

	if (problemId == IProblem.ArgumentIsNeverUsed) {
		JavadocTagsSubProcessor.getUnusedAndUndocumentedParameterOrExceptionProposals(context, problem, proposals);
	}

	if (problemId == IProblem.UnusedPrivateField) {
		GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, problem, proposals, IProposalRelevance.GETTER_SETTER_UNUSED_PRIVATE_FIELD);
	}

}
 
Example #20
Source File: ModifierCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addNonFinalLocalProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
	if (!(selectedNode instanceof SimpleName)) {
		return;
	}

	IBinding binding= ((SimpleName) selectedNode).resolveBinding();
	if (binding instanceof IVariableBinding) {
		binding= ((IVariableBinding) binding).getVariableDeclaration();
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		String label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertofinal_description, BasicElementLabels.getJavaElementName(binding.getName()));
		proposals.add(new ModifierChangeCorrectionProposal(label, cu, binding, selectedNode, Modifier.FINAL, 0, IProposalRelevance.CHANGE_MODIFIER_TO_FINAL, image));
	}
}
 
Example #21
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit,
		boolean removeUnusedPrivateMethods,
		boolean removeUnusedPrivateConstructors,
		boolean removeUnusedPrivateFields,
		boolean removeUnusedPrivateTypes,
		boolean removeUnusedLocalVariables,
		boolean removeUnusedImports,
		boolean removeUnusedCast) {

	IProblem[] problems= compilationUnit.getProblems();
	IProblemLocation[] locations= new IProblemLocation[problems.length];
	for (int i= 0; i < problems.length; i++) {
		locations[i]= new ProblemLocation(problems[i]);
	}

	return createCleanUp(compilationUnit, locations,
			removeUnusedPrivateMethods,
			removeUnusedPrivateConstructors,
			removeUnusedPrivateFields,
			removeUnusedPrivateTypes,
			removeUnusedLocalVariables,
			removeUnusedImports,
			removeUnusedCast);
}
 
Example #22
Source File: SuppressWarningsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addRemoveUnusedSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
	if (!(coveringNode instanceof StringLiteral))
		return;

	StringLiteral literal= (StringLiteral) coveringNode;

	if (coveringNode.getParent() instanceof MemberValuePair) {
		coveringNode= coveringNode.getParent();
	}

	ASTNode parent= coveringNode.getParent();

	ASTRewrite rewrite= ASTRewrite.create(coveringNode.getAST());
	if (parent instanceof SingleMemberAnnotation) {
		rewrite.remove(parent, null);
	} else if (parent instanceof NormalAnnotation) {
		NormalAnnotation annot= (NormalAnnotation) parent;
		if (annot.values().size() == 1) {
			rewrite.remove(annot, null);
		} else {
			rewrite.remove(coveringNode, null);
		}
	} else if (parent instanceof ArrayInitializer) {
		rewrite.remove(coveringNode, null);
	} else {
		return;
	}
	String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_remove_annotation_label, literal.getLiteralValue());
	Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
	ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_ANNOTATION, image);
	proposals.add(proposal);
}
 
Example #23
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: ModifierCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	IProposableFix fix= Java50Fix.createAddOverrideAnnotationFix(context.getASTRoot(), problem);
	if (fix != null) {
		Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE);
		FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.ADD_OVERRIDE_ANNOTATION, image, context);
		proposals.add(proposal);
	}
}
 
Example #25
Source File: StringFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addNLSTag, boolean removeNLSTag) throws CoreException, JavaModelException {
	if (!addNLSTag && !removeNLSTag)
		return null;

	IProblem[] problems= compilationUnit.getProblems();
	IProblemLocation[] locations= new IProblemLocation[problems.length];
	for (int i= 0; i < problems.length; i++) {
		locations[i]= new ProblemLocation(problems[i]);
	}
	return createCleanUp(compilationUnit, addNLSTag, removeNLSTag, locations);
}
 
Example #26
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean containsMatchingProblem(IProblemLocation[] locations, int problemId) {
	if (locations != null) {
		for (int i= 0; i < locations.length; i++) {
			IProblemLocation location= locations[i];
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(location.getMarkerType())
					&& location.getProblemId() == problemId) {
				return true;
			}
		}
	}
	return false;
}
 
Example #27
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void addRemoveRedundantTypeArgumentsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	IProposableFix fix= TypeParametersFix.createRemoveRedundantTypeArgumentsFix(context.getASTRoot(), problem);
	if (fix != null) {
		Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
		Map<String, String> options= new HashMap<String, String>();
		options.put(CleanUpConstants.USE_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.REMOVE_REDUNDANT_TYPE_ARGUMENTS, CleanUpOptions.TRUE);
		FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new TypeParametersCleanUp(options), IProposalRelevance.REMOVE_REDUNDANT_TYPE_ARGUMENTS, image, context);
		proposals.add(proposal);
	}
}
 
Example #28
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ImportDeclaration getImportDeclaration(IProblemLocation problem, CompilationUnit compilationUnit) {
	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);
	if (selectedNode != null) {
		ASTNode node= ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
		if (node instanceof ImportDeclaration) {
			return (ImportDeclaration)node;
		}
	}
	return null;
}
 
Example #29
Source File: TypeParametersFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static TypeParametersFix createRemoveRedundantTypeArgumentsFix(CompilationUnit compilationUnit, IProblemLocation problem) {
	int id= problem.getProblemId();
	if (id == IProblem.RedundantSpecificationOfTypeArguments) {
		ParameterizedType parameterizedType= getParameterizedType(compilationUnit, problem);
		if (parameterizedType == null)
			return null;
		RemoveTypeArgumentsOperation operation= new RemoveTypeArgumentsOperation(parameterizedType);
		return new TypeParametersFix(FixMessages.TypeParametersFix_remove_redundant_type_arguments_name, compilationUnit, new CompilationUnitRewriteOperation[] { operation });
	}
	return null;
}
 
Example #30
Source File: JavadocTagsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void getRemoveJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
	ASTNode node= problem.getCoveringNode(context.getASTRoot());
	while (node != null && !(node instanceof TagElement)) {
		node= node.getParent();
	}
	if (node == null) {
		return;
	}
	ASTRewrite rewrite= ASTRewrite.create(node.getAST());
	rewrite.remove(node, null);

	String label= CorrectionMessages.JavadocTagsSubProcessor_removetag_description;
	Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
	proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG, image));
}