Search in sources :

Example 6 with IJavaCompletionProposal

use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal 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

IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)6 ArrayList (java.util.ArrayList)3 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 HashSet (java.util.HashSet)1 Extension (lombok.eclipse.agent.PatchExtensionMethod.Extension)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 CompletionContext (org.eclipse.jdt.core.CompletionContext)1 CompletionProposal (org.eclipse.jdt.core.CompletionProposal)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)1 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)1 DocumentAdapter (org.eclipse.jdt.internal.core.DocumentAdapter)1