use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.
the class RenameTypeTest method testSimilarElements24.
@Test
public void testSimilarElements24() throws Exception {
// Test transplanter for ICompilationUnit and IFile
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
IType someClass = getType(cu, "SomeClass");
IJavaElement[] someClassMembers = someClass.getChildren();
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, "SomeNewClass");
setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
Refactoring ref = createRefactoring(descriptor);
RefactoringStatus status = performRefactoring(ref);
Assert.assertNull("was supposed to pass", status);
checkResultInClass("SomeNewClass");
checkMappers(ref, someClass, "SomeNewClass.java", someClassMembers);
}
use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.
the class JavaRefactoringDescriptor method createRefactoring.
/**
* {@inheritDoc}
*/
public Refactoring createRefactoring(final RefactoringStatus status) throws CoreException {
Refactoring refactoring = null;
final String id = getID();
final RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(id);
if (contribution != null) {
if (contribution instanceof JavaRefactoringContribution) {
JavaRefactoringContribution javaContribution = (JavaRefactoringContribution) contribution;
refactoring = javaContribution.createRefactoring(this, status);
} else
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, MessageFormat.format(DescriptorMessages.JavaRefactoringDescriptor_no_resulting_descriptor, new Object[] { id }), null));
}
return refactoring;
}
use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.
the class RefactoringManager method createMoveRefactoringSession.
/**
* Create move refactoring session.
*
* @param javaElements
* the java elements
* @return the ID of the refactoring session
*/
public String createMoveRefactoringSession(IJavaElement[] javaElements) throws JavaModelException, RefactoringException {
IReorgPolicy.IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(new IResource[0], javaElements);
if (policy.canEnable()) {
JavaMoveProcessor processor = new JavaMoveProcessor(policy);
//TODO this may overwrite existing sources.
processor.setReorgQueries(new NullReorgQueries());
processor.setCreateTargetQueries(() -> null);
Refactoring refactoring = new MoveRefactoring(processor);
MoveRefactoringSession session = new MoveRefactoringSession(refactoring, processor);
final String id = String.format("move-%s", sessionId.getAndIncrement());
sessions.put(id, session);
return id;
} else {
throw new RefactoringException("Can't create move refactoring session.");
}
}
use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.
the class QuickAssistProcessor method getExtractVariableProposal.
private static boolean getExtractVariableProposal(IInvocationContext context, boolean problemsAtLocation, Collection<ICommandAccess> proposals) throws CoreException {
ASTNode node = context.getCoveredNode();
if (!(node instanceof Expression)) {
if (context.getSelectionLength() != 0) {
return false;
}
node = context.getCoveringNode();
if (!(node instanceof Expression)) {
return false;
}
}
final Expression expression = (Expression) node;
ITypeBinding binding = expression.resolveTypeBinding();
if (binding == null || Bindings.isVoidType(binding)) {
return false;
}
if (proposals == null) {
return true;
}
final ICompilationUnit cu = context.getCompilationUnit();
ExtractTempRefactoring extractTempRefactoring = new ExtractTempRefactoring(context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
if (extractTempRefactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
extractTempRefactoring.setLinkedProposalModel(linkedProposalModel);
extractTempRefactoring.setCheckResultForCompileProblems(false);
String label = CorrectionMessages.QuickAssistProcessor_extract_to_local_all_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
int relevance;
if (context.getSelectionLength() == 0) {
relevance = IProposalRelevance.EXTRACT_LOCAL_ALL_ZERO_SELECTION;
} else if (problemsAtLocation) {
relevance = IProposalRelevance.EXTRACT_LOCAL_ALL_ERROR;
} else {
relevance = IProposalRelevance.EXTRACT_LOCAL_ALL;
}
RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, cu, extractTempRefactoring, relevance, image) {
@Override
protected void init(Refactoring refactoring) throws CoreException {
ExtractTempRefactoring etr = (ExtractTempRefactoring) refactoring;
// expensive
etr.setTempName(etr.guessTempName());
}
};
proposal.setCommandId(EXTRACT_LOCAL_ID);
proposal.setLinkedProposalModel(linkedProposalModel);
proposals.add(proposal);
}
ExtractTempRefactoring extractTempRefactoringSelectedOnly = new ExtractTempRefactoring(context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
extractTempRefactoringSelectedOnly.setReplaceAllOccurrences(false);
if (extractTempRefactoringSelectedOnly.checkInitialConditions(new NullProgressMonitor()).isOK()) {
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
extractTempRefactoringSelectedOnly.setLinkedProposalModel(linkedProposalModel);
extractTempRefactoringSelectedOnly.setCheckResultForCompileProblems(false);
String label = CorrectionMessages.QuickAssistProcessor_extract_to_local_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
int relevance;
if (context.getSelectionLength() == 0) {
relevance = IProposalRelevance.EXTRACT_LOCAL_ZERO_SELECTION;
} else if (problemsAtLocation) {
relevance = IProposalRelevance.EXTRACT_LOCAL_ERROR;
} else {
relevance = IProposalRelevance.EXTRACT_LOCAL;
}
RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, cu, extractTempRefactoringSelectedOnly, relevance, image) {
@Override
protected void init(Refactoring refactoring) throws CoreException {
ExtractTempRefactoring etr = (ExtractTempRefactoring) refactoring;
// expensive
etr.setTempName(etr.guessTempName());
}
};
proposal.setCommandId(EXTRACT_LOCAL_NOT_REPLACE_ID);
proposal.setLinkedProposalModel(linkedProposalModel);
proposals.add(proposal);
}
ExtractConstantRefactoring extractConstRefactoring = new ExtractConstantRefactoring(context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
if (extractConstRefactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
extractConstRefactoring.setLinkedProposalModel(linkedProposalModel);
extractConstRefactoring.setCheckResultForCompileProblems(false);
String label = CorrectionMessages.QuickAssistProcessor_extract_to_constant_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
int relevance;
if (context.getSelectionLength() == 0) {
relevance = IProposalRelevance.EXTRACT_CONSTANT_ZERO_SELECTION;
} else if (problemsAtLocation) {
relevance = IProposalRelevance.EXTRACT_CONSTANT_ERROR;
} else {
relevance = IProposalRelevance.EXTRACT_CONSTANT;
}
RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, cu, extractConstRefactoring, relevance, image) {
@Override
protected void init(Refactoring refactoring) throws CoreException {
ExtractConstantRefactoring etr = (ExtractConstantRefactoring) refactoring;
// expensive
etr.setConstantName(etr.guessConstantName());
}
};
proposal.setCommandId(EXTRACT_CONSTANT_ID);
proposal.setLinkedProposalModel(linkedProposalModel);
proposals.add(proposal);
}
return false;
}
use of org.eclipse.ltk.core.refactoring.Refactoring in project che by eclipse.
the class RenameParametersTest method helper1.
private void helper1(String[] newNames, String[] signature) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), true, true);
IType classA = getType(cu, "A");
IMethod method = classA.getMethod("m", signature);
Assert.assertTrue("refactoring not available", RefactoringAvailabilityTester.isChangeSignatureAvailable(method));
ChangeSignatureProcessor processor = new ChangeSignatureProcessor(method);
Refactoring ref = new ProcessorBasedRefactoring(processor);
//ref.setUpdateReferences(updateReferences);
//ref.setNewParameterNames(newNames);
//ref.setNewNames(createRenamings(method, newNames));
modifyInfos(processor.getParameterInfos(), newNames);
RefactoringStatus result = performRefactoring(ref);
Assert.assertEquals("precondition was supposed to pass", null, result);
IPackageFragment pack = (IPackageFragment) cu.getParent();
String newCuName = getSimpleTestFileName(true, true);
ICompilationUnit newcu = pack.getCompilationUnit(newCuName);
Assert.assertTrue(newCuName + " does not exist", newcu.exists());
Assert.assertEquals("invalid renaming", getFileContents(getTestFileName(true, false)).length(), newcu.getSource().length());
assertEqualLines("invalid renaming", getFileContents(getTestFileName(true, false)), newcu.getSource());
}
Aggregations