Java Code Examples for org.eclipse.jdt.ui.text.java.IProblemLocation#getProblemId()
The following examples show how to use
org.eclipse.jdt.ui.text.java.IProblemLocation#getProblemId() .
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: UnusedCodeFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 2
Source File: QuickFixProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 4
Source File: Java50Fix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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); } } } } } }
Example 5
Source File: Java50CleanUp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { int id= problem.getProblemId(); if (Java50Fix.isMissingOverrideAnnotationProblem(id)) { if (isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE)) { return ! Java50Fix.isMissingOverrideAnnotationInterfaceProblem(id) || isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION); } } else if (Java50Fix.isMissingDeprecationProblem(id)) { return isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS) && isEnabled(CleanUpConstants.ADD_MISSING_ANNOTATIONS_DEPRECATED); } else if (Java50Fix.isRawTypeReferenceProblem(id)) { return isEnabled(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES); } return false; }
Example 6
Source File: ProblemHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean hasProblem(IProblem[] problems, IProblemLocation location) { for (int i= 0; i < problems.length; i++) { IProblem problem= problems[i]; if (problem.getID() == location.getProblemId() && problem.getSourceStart() == location.getOffset()) return true; } return false; }
Example 7
Source File: TypeParametersFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems, boolean insertInferredTypeArguments, boolean removeRedundantTypeArguments) { if (insertInferredTypeArguments) { final ArrayList<ASTNode> changedNodes= new ArrayList<ASTNode>(); compilationUnit.accept(new InsertTypeArgumentsVisitor(changedNodes)); if (changedNodes.isEmpty()) return null; CompilationUnitRewriteOperation op= new InsertTypeArgumentsOperation(changedNodes.toArray(new ParameterizedType[changedNodes.size()])); return new TypeParametersFix(FixMessages.TypeParametersFix_insert_inferred_type_arguments_name, compilationUnit, new CompilationUnitRewriteOperation[] { op }); } else if (removeRedundantTypeArguments) { List<CompilationUnitRewriteOperation> result= new ArrayList<CompilationUnitRewriteOperation>(); for (int i= 0; i < problems.length; i++) { IProblemLocation problem= problems[i]; int id= problem.getProblemId(); if (id == IProblem.RedundantSpecificationOfTypeArguments) { ParameterizedType parameterizedType= getParameterizedType(compilationUnit, problem); if (parameterizedType == null) return null; result.add(new RemoveTypeArgumentsOperation(parameterizedType)); } } if (!result.isEmpty()) { return new TypeParametersFix(FixMessages.TypeParametersFix_remove_redundant_type_arguments_name, compilationUnit, result.toArray(new CompilationUnitRewriteOperation[result.size()])); } } return null; }
Example 8
Source File: CorrectionMarkerResolutionGenerator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean hasProblem(IProblem[] problems, IProblemLocation location) { for (int i= 0; i < problems.length; i++) { IProblem problem= problems[i]; if (problem.getID() == location.getProblemId() && problem.getSourceStart() == location.getOffset()) return true; } return false; }
Example 9
Source File: UnimplementedCodeCleanUp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { int id= problem.getProblemId(); if (id == IProblem.AbstractMethodMustBeImplemented || id == IProblem.EnumConstantMustImplementAbstractMethod) return isEnabled(CleanUpConstants.ADD_MISSING_METHODES) || isEnabled(MAKE_TYPE_ABSTRACT); return false; }
Example 10
Source File: AbstractMultiFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean contains(ArrayList<IProblemLocation> problems, IProblemLocation problem) { for (int i= 0; i < problems.size(); i++) { IProblemLocation existing= problems.get(i); if (existing.getProblemId() == problem.getProblemId() && existing.getOffset() == problem.getOffset() && existing.getLength() == problem.getLength()) { return true; } } return false; }
Example 11
Source File: UnnecessaryCodeCleanUp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { if (problem.getProblemId() == IProblem.UnnecessaryCast) return isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); return false; }
Example 12
Source File: NullAnnotationsCleanUp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { int id= problem.getProblemId(); if (id == this.handledProblemID) { // FIXME search specifically: return param (which??) // if (QuickFixes.hasExplicitNullnessAnnotation(compilationUnit, problem.getOffset())) // return false; return true; } return false; }
Example 13
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static CompilationUnitRewriteOperationsFix createAddFieldQualifierFix(CompilationUnit compilationUnit, IProblemLocation problem) { if (IProblem.UnqualifiedFieldAccess != problem.getProblemId()) return null; AddThisQualifierOperation operation= getUnqualifiedFieldAccessResolveOperation(compilationUnit, problem); if (operation == null) return null; String groupName= operation.getDescription(); return new CodeStyleFix(groupName, compilationUnit, new CompilationUnitRewriteOperation[] {operation}); }
Example 14
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 15
Source File: NullAnnotationsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void createRemoveRedundantNullAnnotationsOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> result) { for (int i= 0; i < locations.length; i++) { IProblemLocation problem= locations[i]; if (problem == null) continue; // problem was filtered out by createCleanUp() int problemId= problem.getProblemId(); if (problemId == IProblem.RedundantNullAnnotation || problemId == IProblem.RedundantNullDefaultAnnotationPackage || problemId == IProblem.RedundantNullDefaultAnnotationType || problemId == IProblem.RedundantNullDefaultAnnotationMethod) { RemoveRedundantAnnotationRewriteOperation operation= new RemoveRedundantAnnotationRewriteOperation(compilationUnit, problem); result.add(operation); } } }
Example 16
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static void addInvalidVariableNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { // hiding, redefined or future keyword CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); if (selectedNode instanceof MethodDeclaration) { selectedNode= ((MethodDeclaration) selectedNode).getName(); } if (!(selectedNode instanceof SimpleName)) { return; } SimpleName nameNode= (SimpleName) selectedNode; String valueSuggestion= null; String name; switch (problem.getProblemId()) { case IProblem.LocalVariableHidingLocalVariable: case IProblem.LocalVariableHidingField: name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_local_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier())); break; case IProblem.FieldHidingLocalVariable: case IProblem.FieldHidingField: case IProblem.DuplicateField: name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_field_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier())); break; case IProblem.ArgumentHidingLocalVariable: case IProblem.ArgumentHidingField: name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_hiding_argument_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier())); break; case IProblem.DuplicateMethod: name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_renaming_duplicate_method, BasicElementLabels.getJavaElementName(nameNode.getIdentifier())); break; default: name= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_rename_var_label, BasicElementLabels.getJavaElementName(nameNode.getIdentifier())); } if (problem.getProblemId() == IProblem.UseEnumAsAnIdentifier) { valueSuggestion= "enumeration"; //$NON-NLS-1$ } else { valueSuggestion= nameNode.getIdentifier() + '1'; } LinkedNamesAssistProposal proposal= new LinkedNamesAssistProposal(name, context, nameNode, valueSuggestion); proposals.add(proposal); }
Example 17
Source File: UnusedCodeFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static boolean isUnusedImport(IProblemLocation problem) { int id= problem.getProblemId(); return id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound; }
Example 18
Source File: NullAnnotationsRewriteOperations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static SignatureAnnotationRewriteOperation createAddAnnotationToOverriddenOperation(CompilationUnit compilationUnit, IProblemLocation problem, String annotationToAdd, String annotationToRemove, boolean allowRemove) { 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); switch (problem.getProblemId()) { case IProblem.IllegalDefinitionToNonNullParameter: case IProblem.IllegalRedefinitionToNonNullParameter: break; case IProblem.IllegalReturnNullityRedefinition: if (declaringNode == null) declaringNode= selectedNode; break; default: return null; } String annotationNameLabel= annotationToAdd; int lastDot= annotationToAdd.lastIndexOf('.'); if (lastDot != -1) annotationNameLabel= annotationToAdd.substring(lastDot + 1); annotationNameLabel= BasicElementLabels.getJavaElementName(annotationNameLabel); if (declaringNode instanceof MethodDeclaration) { // complaint is in signature of this method MethodDeclaration declaration= (MethodDeclaration) declaringNode; switch (problem.getProblemId()) { case IProblem.IllegalDefinitionToNonNullParameter: case IProblem.IllegalRedefinitionToNonNullParameter: return createChangeOverriddenParameterOperation(compilationUnit, cu, declaration, selectedNode, allowRemove, annotationToAdd, annotationToRemove, annotationNameLabel); case IProblem.IllegalReturnNullityRedefinition: if (hasNullAnnotation(declaration)) { // don't adjust super if local has no explicit annotation (?) return createChangeOverriddenReturnOperation(compilationUnit, cu, declaration, allowRemove, annotationToAdd, annotationToRemove, annotationNameLabel); } } } return null; }
Example 19
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static boolean isNonStaticAccess(IProblemLocation problem) { return (problem.getProblemId() == IProblem.NonStaticAccessToStaticField || problem.getProblemId() == IProblem.NonStaticAccessToStaticMethod || problem.getProblemId() == IProblem.NonStaticOrAlienTypeReceiver); }
Example 20
Source File: NullAnnotationsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static void createAddNullAnnotationOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> result) { String nullableAnnotationName= getNullableAnnotationName(compilationUnit.getJavaElement(), false); String nonNullAnnotationName= getNonNullAnnotationName(compilationUnit.getJavaElement(), false); Set<String> handledPositions= new HashSet<String>(); for (int i= 0; i < locations.length; i++) { IProblemLocation problem= locations[i]; if (problem == null) continue; // problem was filtered out by createCleanUp() boolean isArgumentProblem= isComplainingAboutArgument(problem.getCoveredNode(compilationUnit)); String annotationToAdd= nullableAnnotationName; String annotationToRemove= nonNullAnnotationName; // cf. createNullAnnotationInSignatureFix() but changeKind is constantly LOCAL switch (problem.getProblemId()) { case IProblem.IllegalDefinitionToNonNullParameter: case IProblem.IllegalRedefinitionToNonNullParameter: break; case IProblem.ParameterLackingNonNullAnnotation: case IProblem.IllegalReturnNullityRedefinition: annotationToAdd= nonNullAnnotationName; annotationToRemove= nullableAnnotationName; break; case IProblem.RequiredNonNullButProvidedNull: case IProblem.RequiredNonNullButProvidedPotentialNull: case IProblem.RequiredNonNullButProvidedUnknown: case IProblem.RequiredNonNullButProvidedSpecdNullable: if (isArgumentProblem) { annotationToAdd= nonNullAnnotationName; annotationToRemove= nullableAnnotationName; } break; // all others propose to add @Nullable } // when performing multiple changes we can only modify the one CU that the CleanUp infrastructure provides to the operation. SignatureAnnotationRewriteOperation fix= NullAnnotationsRewriteOperations.createAddAnnotationOperation(compilationUnit, problem, annotationToAdd, annotationToRemove, handledPositions, true/*thisUnitOnly*/, false/*allowRemove*/, isArgumentProblem, ChangeKind.LOCAL); if (fix != null) { if (annotationToAdd == nonNullAnnotationName) { fix.fRemoveIfNonNullByDefault= true; fix.fNonNullByDefaultName= getNonNullByDefaultAnnotationName(compilationUnit.getJavaElement(), false); } result.add(fix); } } }