Search in sources :

Example 21 with CompilationUnitChange

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;
}
Also used : GroupCategorySet(org.eclipse.ltk.core.refactoring.GroupCategorySet) GroupCategory(org.eclipse.ltk.core.refactoring.GroupCategory) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)

Example 22 with CompilationUnitChange

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);
            }
        };
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ASTNode(org.eclipse.jdt.core.dom.ASTNode) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 23 with CompilationUnitChange

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();
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) InlineLocalVariableDescriptor(org.eclipse.jdt.core.refactoring.descriptors.InlineLocalVariableDescriptor) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 24 with CompilationUnitChange

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) IMarker(org.eclipse.core.resources.IMarker) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) IResource(org.eclipse.core.resources.IResource) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Aggregations

CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)24 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)9 TextEdit (org.eclipse.text.edits.TextEdit)9 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)8 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 TextEditGroup (org.eclipse.text.edits.TextEditGroup)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)3 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)3 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)3 TextChange (org.eclipse.ltk.core.refactoring.TextChange)3 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2