use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class UnimplementedCodeFix method createAddUnimplementedMethodsFix.
public static IProposableFix createAddUnimplementedMethodsFix(final CompilationUnit root, IProblemLocation problem) {
ASTNode typeNode = getSelectedTypeNode(root, problem);
if (typeNode == null)
return null;
if (isTypeBindingNull(typeNode))
return null;
AddUnimplementedMethodsOperation operation = new AddUnimplementedMethodsOperation(typeNode);
if (operation.getMethodsToImplement().length > 0) {
return new UnimplementedCodeFix(CorrectionMessages.UnimplementedMethodsCorrectionProposal_description, root, new CompilationUnitRewriteOperation[] { operation });
} else {
return new IProposableFix() {
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitChange change = new CompilationUnitChange(CorrectionMessages.UnimplementedMethodsCorrectionProposal_description, (ICompilationUnit) root.getJavaElement()) {
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
//TODO
return new NullChange();
}
};
change.setEdit(new MultiTextEdit());
return change;
}
public String getAdditionalProposalInfo() {
return new String();
}
public String getDisplayString() {
return CorrectionMessages.UnimplementedMethodsCorrectionProposal_description;
}
public IStatus getStatus() {
return new Status(IStatus.ERROR, JavaPlugin.ID_PLUGIN, CorrectionMessages.UnimplementedCodeFix_DependenciesStatusMessage);
}
};
}
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class InlineTempRefactoring method createChange.
//----- changes
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask(RefactoringCoreMessages.InlineTempRefactoring_preview, 2);
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fCu.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
final IVariableBinding binding = getVariableDeclaration().resolveBinding();
String text = null;
final IMethodBinding method = binding.getDeclaringMethod();
if (method != null)
text = BindingLabelProvider.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED);
else
text = BasicElementLabels.getJavaElementName('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
final String description = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
final String header = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), text });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.InlineTempRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
final InlineLocalVariableDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInlineLocalVariableDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.NONE);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, String.valueOf(fSelectionStart) + ' ' + String.valueOf(fSelectionLength));
CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite(fCu, fASTRoot);
inlineTemp(cuRewrite);
removeTemp(cuRewrite);
final CompilationUnitChange result = cuRewrite.createChange(RefactoringCoreMessages.InlineTempRefactoring_inline, false, new SubProgressMonitor(pm, 1));
result.setDescriptor(new RefactoringChangeDescriptor(descriptor));
return result;
} finally {
pm.done();
}
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class RenameLocalVariableProcessor method createEdits.
private void createEdits() {
TextEdit declarationEdit = createRenameEdit(fTempDeclarationNode.getName().getStartPosition());
TextEdit[] allRenameEdits = getAllRenameEdits(declarationEdit);
TextEdit[] allUnparentedRenameEdits = new TextEdit[allRenameEdits.length];
TextEdit unparentedDeclarationEdit = null;
fChange = new CompilationUnitChange(RefactoringCoreMessages.RenameTempRefactoring_rename, fCu);
MultiTextEdit rootEdit = new MultiTextEdit();
fChange.setEdit(rootEdit);
fChange.setKeepPreviewEdits(true);
for (int i = 0; i < allRenameEdits.length; i++) {
if (fIsComposite) {
// Add a copy of the text edit (text edit may only have one
// parent) to keep problem reporting code clean
TextChangeCompatibility.addTextEdit(fChangeManager.get(fCu), RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i].copy(), fCategorySet);
// Add a separate copy for problem reporting
allUnparentedRenameEdits[i] = allRenameEdits[i].copy();
if (allRenameEdits[i].equals(declarationEdit))
unparentedDeclarationEdit = allUnparentedRenameEdits[i];
}
rootEdit.addChild(allRenameEdits[i]);
fChange.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i]));
}
// store information for analysis
if (fIsComposite) {
fLocalAnalyzePackage = new RenameAnalyzeUtil.LocalAnalyzePackage(unparentedDeclarationEdit, allUnparentedRenameEdits);
} else
fLocalAnalyzePackage = new RenameAnalyzeUtil.LocalAnalyzePackage(declarationEdit, allRenameEdits);
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class UnresolvedElementsSubProcessor method createAddImportChange.
// private static void addCopyAnnotationsJarProposal(final ICompilationUnit cu, final Name name, final String fullyQualifiedName, Bundle annotationsBundle, Collection<ICommandAccess> proposals) {
// final IJavaProject javaProject= cu.getJavaProject();
// final File bundleFile;
// try {
// bundleFile= FileLocator.getBundleFile(annotationsBundle);
// } catch (IOException e) {
// JavaPlugin.log(e);
// return;
// }
// if (!bundleFile.isFile() || !bundleFile.canRead())
// return; // we only support a JAR'd bundle, so this won't work in the runtime if you have org.eclipse.jdt.annotation in source.
//
// final String changeName= CorrectionMessages.UnresolvedElementsSubProcessor_copy_annotation_jar_description;
// ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(changeName, null, IProposalRelevance.COPY_ANNOTATION_JAR) {
// @Override
// protected Change createChange() throws CoreException {
// final IFile file= javaProject.getProject().getFile(bundleFile.getName());
// ResourceChange copyFileChange= new ResourceChange() {
// @Override
// public Change perform(IProgressMonitor pm) throws CoreException {
// try {
// if (file.exists())
// file.delete(false, pm);
// file.create(new BufferedInputStream(new FileInputStream(bundleFile)), false, pm);
// return new DeleteResourceChange(file.getFullPath(), false);
// } catch (FileNotFoundException e) {
// throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), e.getMessage()));
// }
// }
// @Override
// public String getName() {
// return changeName;
// }
// @Override
// protected IResource getModifiedResource() {
// return javaProject.getProject();
// }
// };
// ClasspathChange addEntryChange= ClasspathChange.addEntryChange(javaProject, JavaCore
// .newLibraryEntry(file.getFullPath(), null, null));
// CompilationUnitChange addImportChange= createAddImportChange(cu, name, fullyQualifiedName);
// return new CompositeChange(changeName, new Change[] { copyFileChange, addEntryChange, addImportChange});
// }
//
// @Override
// public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
// return CorrectionMessages.UnresolvedElementsSubProcessor_copy_annotation_jar_info;
// }
// };
// proposals.add(proposal);
// }
static CompilationUnitChange createAddImportChange(ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
String[] args = { BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)), BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName)) };
String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
ImportRewrite importRewrite = StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
importRewrite.addImport(fullyQualifiedName);
cuChange.setEdit(importRewrite.rewriteImports(null));
return cuChange;
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project eclipse.jdt.ls by eclipse.
the class CompilationUnitRewriteOperationsFix method createChange.
@Override
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite((ICompilationUnit) fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
for (int i = 0; i < fOperations.length; i++) {
CompilationUnitRewriteOperation operation = fOperations[i];
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
CompilationUnitChange result = cuRewrite.createChange(getDisplayString(), true, null);
if (result == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
}
return result;
}
Aggregations