use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.
the class ExtractConstantRefactoring method checkSource.
private void checkSource(SubProgressMonitor monitor, RefactoringStatus result) throws CoreException {
String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, fCu, true, true, monitor);
IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCuRewrite.getRoot());
for (int i = 0; i < newProblems.length; i++) {
IProblem problem = newProblems[i];
if (problem.isError())
result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
}
}
use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.
the class ModifierCorrectionsQuickFixTest method testAbstractMethodInNonAbstractClass.
@Test
public void testAbstractMethodInNonAbstractClass() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public abstract int foo();\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
IProblem[] problems = astRoot.getProblems();
assertNumberOfProblems(2, problems);
ArrayList proposals = collectCorrections(cu, problems[0], null);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public abstract class E {\n");
buf.append(" public abstract int foo();\n");
buf.append("}\n");
String expectedMakeClassAbstract = buf.toString();
assertEquals(preview1, expectedMakeClassAbstract);
proposals = collectCorrections(cu, problems[1], null);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
proposal = (CUCorrectionProposal) proposals.get(0);
preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public int foo() {\n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(1);
String preview2 = getPreviewContent(proposal);
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expectedMakeClassAbstract });
}
use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.
the class QuickFixTest method collectCorrections2.
protected static final ArrayList collectCorrections2(ICompilationUnit cu, int nProblems) throws CoreException {
final ArrayList problemsList = new ArrayList();
final IProblemRequestor requestor = new IProblemRequestor() {
public void acceptProblem(IProblem problem) {
problemsList.add(problem);
}
public void beginReporting() {
problemsList.clear();
}
public void endReporting() {
}
public boolean isActive() {
return true;
}
};
WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
return requestor;
}
};
ICompilationUnit wc = cu.getWorkingCopy(workingCopyOwner, null);
try {
wc.reconcile(ICompilationUnit.NO_AST, true, true, wc.getOwner(), null);
} finally {
wc.discardWorkingCopy();
}
IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
assertNumberOfProblems(nProblems, problems);
return collectCorrections(cu, problems[0], null);
}
use of org.eclipse.jdt.core.compiler.IProblem 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.core.compiler.IProblem in project che by eclipse.
the class LinkedNodeFinder method getNameNodeProblemKind.
private static int getNameNodeProblemKind(IProblem[] problems, SimpleName nameNode) {
int nameOffset = nameNode.getStartPosition();
int nameInclEnd = nameOffset + nameNode.getLength() - 1;
for (int i = 0; i < problems.length; i++) {
IProblem curr = problems[i];
if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) {
int kind = getProblemKind(curr);
if (kind != 0) {
return kind;
}
}
}
return 0;
}
Aggregations