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, IProblemLocation[] problems, boolean addThisQualifier, boolean changeNonStaticAccessToStatic, boolean changeIndirectStaticAccessToDirect) {
if (!addThisQualifier && !changeNonStaticAccessToStatic && !changeIndirectStaticAccessToDirect)
return null;
List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
if (addThisQualifier) {
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
if (problem.getProblemId() == IProblem.UnqualifiedFieldAccess) {
AddThisQualifierOperation operation = getUnqualifiedFieldAccessResolveOperation(compilationUnit, problem);
if (operation != null)
operations.add(operation);
}
}
}
addToStaticAccessOperations(compilationUnit, problems, changeNonStaticAccessToStatic, changeIndirectStaticAccessToDirect, operations);
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 CodeStyleFix method addToStaticAccessOperations.
private static void addToStaticAccessOperations(CompilationUnit compilationUnit, IProblemLocation[] problems, boolean changeNonStaticAccessToStatic, boolean changeIndirectStaticAccessToDirect, List<CompilationUnitRewriteOperation> result) {
if (!changeNonStaticAccessToStatic && !changeIndirectStaticAccessToDirect)
return;
HashMap<ASTNode, Block> createdBlocks = new HashMap<ASTNode, Block>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
boolean isNonStaticAccess = changeNonStaticAccessToStatic && isNonStaticAccess(problem);
boolean isIndirectStaticAccess = changeIndirectStaticAccessToDirect && isIndirectStaticAccess(problem);
if (isNonStaticAccess || isIndirectStaticAccess) {
ToStaticAccessOperation[] nonStaticAccessInformation = createToStaticAccessOperations(compilationUnit, createdBlocks, problem, true);
if (nonStaticAccessInformation != null) {
ToStaticAccessOperation op = nonStaticAccessInformation[0];
Expression qualifier = op.fQualifier;
if (!(qualifier instanceof MethodInvocation) || !isMethodArgument(qualifier)) {
for (Iterator<CompilationUnitRewriteOperation> it = result.iterator(); it.hasNext(); ) {
// see bug 346230
CompilationUnitRewriteOperation oper = it.next();
if (oper instanceof CodeStyleFix.AddThisQualifierOperation && ((CodeStyleFix.AddThisQualifierOperation) oper).fName.equals(qualifier)) {
result.remove(oper);
break;
}
}
result.add(op);
}
}
}
}
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class Java50Fix method createCleanUp.
public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addOverrideAnnotation, boolean addOverrideInterfaceAnnotation, boolean addDeprecatedAnnotation, boolean rawTypeReference) {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject()))
return null;
if (!addOverrideAnnotation && !addDeprecatedAnnotation && !rawTypeReference)
return null;
List<CompilationUnitRewriteOperation> operations = new ArrayList<CompilationUnitRewriteOperation>();
IProblem[] problems = compilationUnit.getProblems();
IProblemLocation[] locations = new IProblemLocation[problems.length];
for (int i = 0; i < problems.length; i++) {
locations[i] = new ProblemLocation(problems[i]);
}
if (addOverrideAnnotation)
createAddOverrideAnnotationOperations(compilationUnit, addOverrideInterfaceAnnotation, locations, operations);
if (addDeprecatedAnnotation)
createAddDeprecatedAnnotationOperations(compilationUnit, locations, operations);
if (rawTypeReference)
createRawTypeReferenceOperations(compilationUnit, locations, operations);
if (operations.size() == 0)
return null;
String fixName;
if (rawTypeReference) {
fixName = FixMessages.Java50Fix_add_type_parameters_change_name;
} else {
fixName = FixMessages.Java50Fix_add_annotations_change_name;
}
CompilationUnitRewriteOperation[] operationsArray = operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
return new Java50Fix(fixName, compilationUnit, operationsArray);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class Java50Fix method createAddOverrideAnnotationOperations.
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);
}
}
}
}
}
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class Java50Fix method createRawTypeReferenceOperations.
private static SimpleType createRawTypeReferenceOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> operations) {
if (hasFatalError(compilationUnit))
return null;
List<SimpleType> result = new ArrayList<SimpleType>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation problem = locations[i];
if (isRawTypeReferenceProblem(problem.getProblemId())) {
ASTNode node = problem.getCoveredNode(compilationUnit);
if (node instanceof ClassInstanceCreation) {
Type rawReference = (Type) node.getStructuralProperty(ClassInstanceCreation.TYPE_PROPERTY);
if (isRawTypeReference(rawReference)) {
result.add((SimpleType) rawReference);
}
} else if (node instanceof SimpleName) {
ASTNode rawReference = node.getParent();
if (isRawTypeReference(rawReference)) {
ASTNode parent = rawReference.getParent();
if (!(parent instanceof ArrayType || parent instanceof ParameterizedType))
result.add((SimpleType) rawReference);
}
} else if (node instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) node;
SimpleType rawReference = getRawReference(invocation, compilationUnit);
if (rawReference != null) {
result.add(rawReference);
}
}
}
}
if (result.size() == 0)
return null;
SimpleType[] types = result.toArray(new SimpleType[result.size()]);
operations.add(new AddTypeParametersOperation(types));
return types[0];
}
Aggregations