use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class NullAnnotationsFix method createRemoveRedundantNullAnnotationsOperations.
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)
// problem was filtered out by createCleanUp()
continue;
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);
}
}
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class NullAnnotationsFix method createAddNullAnnotationOperations.
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)
// problem was filtered out by createCleanUp()
continue;
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;
}
// 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);
}
}
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class NullAnnotationsFix method createCleanUp.
// Entry for NullAnnotationsCleanup:
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] locations, int problemID) {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
return null;
List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
if (locations == null) {
org.eclipse.jdt.core.compiler.IProblem[] problems = compilationUnit.getProblems();
locations = new IProblemLocation[problems.length];
for (int i = 0; i < problems.length; i++) {
if (problems[i].getID() == problemID)
locations[i] = new ProblemLocation(problems[i]);
}
}
createAddNullAnnotationOperations(compilationUnit, locations, operations);
createRemoveRedundantNullAnnotationsOperations(compilationUnit, locations, operations);
if (operations.size() == 0)
return null;
CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
return new NullAnnotationsFix(FixMessages.NullAnnotationsFix_add_annotation_change_name, compilationUnit, operationsArray);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class PotentialProgrammingProblemsFix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addSerialVersionIds) {
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, addSerialVersionIds);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class StringFix method createCleanUp.
private static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addNLSTag, boolean removeNLSTag, IProblemLocation[] problems) throws CoreException, JavaModelException {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!cu.isStructureKnown())
//[clean up] 'Remove unnecessary $NLS-TAGS$' removes necessary ones in case of syntax errors: https://bugs.eclipse.org/bugs/show_bug.cgi?id=285814 :
return null;
List<CategorizedTextEditGroup> result = new ArrayList<CategorizedTextEditGroup>();
List<IProblemLocation> missingNLSProblems = new ArrayList<IProblemLocation>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
if (addNLSTag && problem.getProblemId() == IProblem.NonExternalizedStringLiteral) {
missingNLSProblems.add(problem);
}
if (removeNLSTag && problem.getProblemId() == IProblem.UnnecessaryNLSTag) {
IBuffer buffer = cu.getBuffer();
if (buffer != null) {
TextEdit edit = StringFix.getReplace(problem.getOffset(), problem.getLength(), buffer, false);
if (edit != null) {
String label = FixMessages.StringFix_RemoveNonNls_description;
result.add(new CategorizedTextEditGroup(label, edit, new GroupCategorySet(new GroupCategory(label, label, label))));
}
}
}
}
if (!missingNLSProblems.isEmpty()) {
int[] positions = new int[missingNLSProblems.size()];
int i = 0;
for (Iterator<IProblemLocation> iter = missingNLSProblems.iterator(); iter.hasNext(); ) {
IProblemLocation problem = iter.next();
positions[i] = problem.getOffset();
i++;
}
//TODO nls
//NLSUtil.createNLSEdits(cu, positions);
TextEdit[] edits = null;
if (edits != null) {
for (int j = 0; j < edits.length; j++) {
String label = FixMessages.StringFix_AddNonNls_description;
result.add(new CategorizedTextEditGroup(label, edits[j], new GroupCategorySet(new GroupCategory(label, label, label))));
}
}
}
if (result.isEmpty())
return null;
//$NON-NLS-1$
return new StringFix("", compilationUnit, result.toArray(new TextEditGroup[result.size()]));
}
Aggregations