use of org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal in project che by eclipse.
the class ReorgQuickFixTest method testWrongPackageStatement.
@Test
public void testWrongPackageStatement() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
boolean hasRename = true, hasMove = true;
for (int i = 0; i < proposals.size(); i++) {
ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
if (curr instanceof CorrectPackageDeclarationProposal) {
assertTrue("Duplicated proposal", hasRename);
hasRename = false;
CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
} else {
assertTrue("Duplicated proposal", hasMove);
hasMove = false;
curr.apply(null);
IPackageFragment pack2 = fSourceFolder.getPackageFragment("test2");
ICompilationUnit cu2 = pack2.getCompilationUnit("E.java");
assertTrue("CU does not exist", cu2.exists());
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
}
}
}
use of org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal in project che by eclipse.
the class ReorgQuickFixTest method testWrongPackageStatementFromDefault.
@Test
public void testWrongPackageStatementFromDefault() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
boolean hasRename = true, hasMove = true;
for (int i = 0; i < proposals.size(); i++) {
ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
if (curr instanceof CorrectPackageDeclarationProposal) {
assertTrue("Duplicated proposal", hasRename);
hasRename = false;
CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
} else {
assertTrue("Duplicated proposal", hasMove);
hasMove = false;
curr.apply(null);
IPackageFragment pack2 = fSourceFolder.getPackageFragment("test2");
ICompilationUnit cu2 = pack2.getCompilationUnit("E.java");
assertTrue("CU does not exist", cu2.exists());
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
}
}
}
use of org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal in project che by eclipse.
the class ReorgQuickFixTest method testWrongTypeName_bug180330.
@Test
public void testWrongTypeName_bug180330() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("p", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package p;\n");
buf.append("public class \\u0042 {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertCorrectLabels(proposals);
assertNumberOfProposals(proposals, 2);
boolean hasRename = true, hasMove = true;
for (int i = 0; i < proposals.size(); i++) {
ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
if (curr instanceof CorrectMainTypeNameProposal) {
assertTrue("Duplicated proposal", hasRename);
hasRename = false;
CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package p;\n");
buf.append("public class C {\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
} else {
assertTrue("Duplicated proposal", hasMove);
hasMove = false;
curr.apply(null);
ICompilationUnit cu2 = pack1.getCompilationUnit("B.java");
assertTrue("CU does not exist", cu2.exists());
buf = new StringBuffer();
buf.append("package p;\n");
buf.append("public class \\u0042 {\n");
buf.append("}\n");
assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
}
}
}
use of org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal in project che by eclipse.
the class ReorgQuickFixTest method testWrongDefaultPackageStatement.
@Test
public void testWrongDefaultPackageStatement() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("public class E {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
CompilationUnit astRoot = getASTRoot(cu);
ArrayList proposals = collectCorrections(cu, astRoot);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
boolean hasRename = true, hasMove = true;
for (int i = 0; i < proposals.size(); i++) {
ChangeCorrectionProposal curr = (ChangeCorrectionProposal) proposals.get(i);
if (curr instanceof CorrectPackageDeclarationProposal) {
assertTrue("Duplicated proposal", hasRename);
hasRename = false;
CUCorrectionProposal proposal = (CUCorrectionProposal) curr;
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
} else {
assertTrue("Duplicated proposal", hasMove);
hasMove = false;
curr.apply(null);
IPackageFragment pack2 = fSourceFolder.getPackageFragment("");
ICompilationUnit cu2 = pack2.getCompilationUnit("E.java");
assertTrue("CU does not exist", cu2.exists());
buf = new StringBuffer();
buf.append("public class E {\n");
buf.append("}\n");
assertEqualStringIgnoreDelim(cu2.getSource(), buf.toString());
}
}
}
use of org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal in project che by eclipse.
the class ReorgCorrectionsSubProcessor method getWrongPackageDeclNameProposals.
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
boolean isLinked = cu.getResource().isLinked();
// correct package declaration
// bug 38357
int relevance = cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION;
proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
// move to package
IPackageDeclaration[] packDecls = cu.getPackageDeclarations();
//$NON-NLS-1$
String newPackName = packDecls.length > 0 ? packDecls[0].getElementName() : "";
IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(cu);
IPackageFragment newPack = root.getPackageFragment(newPackName);
ICompilationUnit newCU = newPack.getCompilationUnit(cu.getElementName());
if (!newCU.exists() && !isLinked) {
String label;
if (newPack.isDefaultPackage()) {
label = Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
} else {
String packageLabel = JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
label = Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
}
CompositeChange composite = new CompositeChange(label);
composite.add(new CreatePackageChange(newPack));
composite.add(new MoveCompilationUnitChange(cu, newPack));
proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
}
}
Aggregations