use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class TextEditFix method createChange.
/**
* {@inheritDoc}
*/
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
String label = fChangeDescription;
CompilationUnitChange result = new CompilationUnitChange(label, fUnit);
result.setEdit(fEdit);
result.addTextEditGroup(new CategorizedTextEditGroup(label, new GroupCategorySet(new GroupCategory(label, label, label))));
return result;
}
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 bndtools by bndtools.
the class PackageInfoBaselineQuickFixProcessor method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
ICompilationUnit compUnit = context.getCompilationUnit();
IResource resource = compUnit.getResource();
IMarker[] markers = resource.findMarkers(BndtoolsConstants.MARKER_JAVA_BASELINE, false, 1);
for (IProblemLocation location : locations) {
for (IMarker marker : markers) {
int markerStart = marker.getAttribute(IMarker.CHAR_START, -1);
int markerEnd = marker.getAttribute(IMarker.CHAR_END, -1);
int markerLength = markerEnd - markerStart;
if (location.getOffset() <= markerStart && markerStart < location.getOffset() + location.getLength()) {
String newVersion = marker.getAttribute("suggestedVersion", null);
if (newVersion != null) {
StringBuilder quotedVersion = new StringBuilder(newVersion.trim());
if (quotedVersion.charAt(0) != '"')
quotedVersion.insert(0, '"');
if (quotedVersion.charAt(quotedVersion.length() - 1) != '"')
quotedVersion.append('"');
CompilationUnitChange change = new CompilationUnitChange("Change package-info.java", compUnit);
change.setEdit(new ReplaceEdit(markerStart, markerLength, quotedVersion.toString()));
return new IJavaCompletionProposal[] { new ChangeCorrectionProposal("Change package version to " + newVersion, change, 1000) };
}
}
}
}
return null;
}
Aggregations