use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class CodeStyleFix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addThisQualifier, boolean changeNonStaticAccessToStatic, boolean qualifyStaticFieldAccess, boolean changeIndirectStaticAccessToDirect, boolean qualifyMethodAccess, boolean qualifyStaticMethodAccess, boolean removeFieldQualifier, boolean removeMethodQualifier) {
if (!addThisQualifier && !changeNonStaticAccessToStatic && !qualifyStaticFieldAccess && !changeIndirectStaticAccessToDirect && !qualifyMethodAccess && !qualifyStaticMethodAccess && !removeFieldQualifier && !removeMethodQualifier)
return null;
List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
if (addThisQualifier || qualifyStaticFieldAccess || qualifyMethodAccess || qualifyStaticMethodAccess) {
CodeStyleVisitor codeStyleVisitor = new CodeStyleVisitor(compilationUnit, addThisQualifier, qualifyStaticFieldAccess, qualifyMethodAccess, qualifyStaticMethodAccess, operations);
compilationUnit.accept(codeStyleVisitor);
}
IProblem[] problems = compilationUnit.getProblems();
IProblemLocation[] locations = new IProblemLocation[problems.length];
for (int i = 0; i < problems.length; i++) {
locations[i] = new ProblemLocation(problems[i]);
}
addToStaticAccessOperations(compilationUnit, locations, changeNonStaticAccessToStatic, changeIndirectStaticAccessToDirect, operations);
if (removeFieldQualifier || removeMethodQualifier) {
ThisQualifierVisitor visitor = new ThisQualifierVisitor(removeFieldQualifier, removeMethodQualifier, compilationUnit, operations);
compilationUnit.accept(visitor);
}
if (operations.isEmpty())
return null;
CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
return new CodeStyleFix(FixMessages.CodeStyleFix_change_name, compilationUnit, operationsArray);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class StringFix method createCleanUp.
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);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class Java50Fix method createAddDeprecatedAnnotationOperations.
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);
}
}
}
}
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class UnusedCodeFix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, IProblemLocation[] problems, boolean removeUnusedPrivateMethods, boolean removeUnusedPrivateConstructors, boolean removeUnusedPrivateFields, boolean removeUnusedPrivateTypes, boolean removeUnusedLocalVariables, boolean removeUnusedImports, boolean removeUnusedCast) {
List<CompilationUnitRewriteOperation> result = new ArrayList<CompilationUnitRewriteOperation>();
Hashtable<ASTNode, List<SimpleName>> variableDeclarations = new Hashtable<ASTNode, List<SimpleName>>();
LinkedHashSet<CastExpression> unnecessaryCasts = new LinkedHashSet<CastExpression>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
int id = problem.getProblemId();
if (removeUnusedImports && (id == IProblem.UnusedImport || id == IProblem.DuplicateImport || id == IProblem.ConflictingImport || id == IProblem.CannotImportPackage || id == IProblem.ImportNotFound)) {
ImportDeclaration node = UnusedCodeFix.getImportDeclaration(problem, compilationUnit);
if (node != null) {
result.add(new RemoveImportOperation(node));
}
}
if ((removeUnusedPrivateMethods && id == IProblem.UnusedPrivateMethod) || (removeUnusedPrivateConstructors && id == IProblem.UnusedPrivateConstructor) || (removeUnusedPrivateTypes && id == IProblem.UnusedPrivateType)) {
SimpleName name = getUnusedName(compilationUnit, problem);
if (name != null) {
IBinding binding = name.resolveBinding();
if (binding != null) {
result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
}
}
}
if ((removeUnusedLocalVariables && id == IProblem.LocalVariableIsNeverUsed) || (removeUnusedPrivateFields && id == IProblem.UnusedPrivateField)) {
SimpleName name = getUnusedName(compilationUnit, problem);
if (name != null) {
IBinding binding = name.resolveBinding();
if (binding instanceof IVariableBinding && !isFormalParameterInEnhancedForStatement(name) && (!((IVariableBinding) binding).isField() || isSideEffectFree(name, compilationUnit))) {
VariableDeclarationFragment parent = (VariableDeclarationFragment) ASTNodes.getParent(name, VariableDeclarationFragment.class);
if (parent != null) {
ASTNode varDecl = parent.getParent();
if (!variableDeclarations.containsKey(varDecl)) {
variableDeclarations.put(varDecl, new ArrayList<SimpleName>());
}
variableDeclarations.get(varDecl).add(name);
} else {
result.add(new RemoveUnusedMemberOperation(new SimpleName[] { name }, false));
}
}
}
}
if (removeUnusedCast && id == IProblem.UnnecessaryCast) {
ASTNode selectedNode = problem.getCoveringNode(compilationUnit);
ASTNode curr = selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr = ((ParenthesizedExpression) curr).getExpression();
}
if (curr instanceof CastExpression) {
unnecessaryCasts.add((CastExpression) curr);
}
}
}
for (Iterator<ASTNode> iter = variableDeclarations.keySet().iterator(); iter.hasNext(); ) {
ASTNode node = iter.next();
List<SimpleName> names = variableDeclarations.get(node);
result.add(new RemoveUnusedMemberOperation(names.toArray(new SimpleName[names.size()]), false));
}
if (unnecessaryCasts.size() > 0)
result.add(new RemoveAllCastOperation(unnecessaryCasts));
if (result.size() == 0)
return null;
return new UnusedCodeFix(FixMessages.UnusedCodeFix_change_name, compilationUnit, result.toArray(new CompilationUnitRewriteOperation[result.size()]));
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withMissingArgs_returnsNullGracefully.
@Test
public void getCorrections_forIsClassPath_withMissingArgs_returnsNullGracefully() {
List<IProblemLocation> locs = getProblems("public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, null, true, JDT_PROBLEM));
assertThat(proposalsFor(locs)).isNull();
}
Aggregations