Search in sources :

Example 1 with BuildErrorDetailsHandler

use of org.bndtools.build.api.BuildErrorDetailsHandler in project bndtools by bndtools.

the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
    List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
    ISourceViewer viewer = context.getSourceViewer();
    @SuppressWarnings("unused") IDocument document = viewer.getDocument();
    IAnnotationModel model = viewer.getAnnotationModel();
    @SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
    while (iter.hasNext()) {
        Annotation annotation = (Annotation) iter.next();
        if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
            Position position = model.getPosition(annotation);
            if (isAtPosition(context.getOffset(), position)) {
                IMarker marker = ((MarkerAnnotation) annotation).getMarker();
                String errorType = marker.getAttribute("$bndType", null);
                if (errorType != null) {
                    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
                    if (handler != null) {
                        proposals.addAll(handler.getProposals(marker));
                    }
                }
            }
        }
    }
    if (proposals.isEmpty()) {
        proposals.add(new NoCompletionsProposal());
    }
    return proposals.toArray(new ICompletionProposal[0]);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) LinkedList(java.util.LinkedList) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with BuildErrorDetailsHandler

use of org.bndtools.build.api.BuildErrorDetailsHandler in project bndtools by bndtools.

the class ProjectBuildPage method generateFixes.

// look for available quick-fixes from the bnd build error details
private void generateFixes(String message, final IMarker marker) {
    boolean fixable = marker.getAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, false);
    if (!fixable)
        return;
    ITextEditor sourcePage = editor.getSourcePage();
    if (sourcePage == null)
        return;
    String type = marker.getAttribute("$bndType", (String) null);
    if (type == null)
        return;
    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
    if (handler == null)
        return;
    List<IAction> fixes = new LinkedList<>();
    List<ICompletionProposal> proposals = handler.getProposals(marker);
    if (proposals != null) {
        for (ICompletionProposal proposal : proposals) {
            fixes.add(new ApplyCompletionProposalAction(proposal, editor.getSourcePage(), editor, BndEditor.SOURCE_PAGE));
        }
    }
    // If no source completion fixes were found, add the marker resolution actions.
    if (fixes.isEmpty()) {
        List<IMarkerResolution> resolutions = handler.getResolutions(marker);
        for (final IMarkerResolution resolution : resolutions) {
            Action action = new Action(resolution.getLabel()) {

                @Override
                public void run() {
                    resolution.run(marker);
                }
            };
            fixes.add(action);
        }
    }
    messageFixesMap.put(message, fixes.toArray(new IAction[0]));
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IAction(org.eclipse.jface.action.IAction) LinkedList(java.util.LinkedList) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 3 with BuildErrorDetailsHandler

use of org.bndtools.build.api.BuildErrorDetailsHandler in project bndtools by bndtools.

the class BndtoolsMarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    String type = marker.getAttribute("$bndType", (String) null);
    if (type == null)
        return new IMarkerResolution[0];
    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
    if (handler == null)
        return new IMarkerResolution[0];
    List<IMarkerResolution> resolutions = handler.getResolutions(marker);
    return resolutions != null ? resolutions.toArray(new IMarkerResolution[0]) : new IMarkerResolution[0];
}
Also used : BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IMarkerResolution(org.eclipse.ui.IMarkerResolution)

Example 4 with BuildErrorDetailsHandler

use of org.bndtools.build.api.BuildErrorDetailsHandler in project bndtools by bndtools.

the class MarkerSupport method createMarker.

void createMarker(Processor model, int severity, String formatted, String markerType) throws Exception {
    Location location = model != null ? model.getLocation(formatted) : null;
    if (location != null) {
        String type = location.details != null ? location.details.getClass().getName() : null;
        BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
        List<MarkerData> markers = handler.generateMarkerData(project, model, location);
        for (MarkerData markerData : markers) {
            IResource resource = markerData.getResource();
            if (resource != null && resource.exists()) {
                String typeOverride = markerData.getTypeOverride();
                IMarker marker = resource.createMarker(typeOverride != null ? typeOverride : markerType);
                marker.setAttribute(IMarker.SEVERITY, severity);
                marker.setAttribute("$bndType", type);
                // Set location information
                if (location.header != null)
                    marker.setAttribute(BNDTOOLS_MARKER_HEADER_ATTR, location.header);
                if (location.context != null)
                    marker.setAttribute(BNDTOOLS_MARKER_CONTEXT_ATTR, location.context);
                if (location.file != null)
                    marker.setAttribute(BNDTOOLS_MARKER_FILE_ATTR, location.file);
                if (location.reference != null)
                    marker.setAttribute(BNDTOOLS_MARKER_REFERENCE_ATTR, location.reference);
                marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, markerData.hasResolutions());
                for (Entry<String, Object> attrib : markerData.getAttribs().entrySet()) marker.setAttribute(attrib.getKey(), attrib.getValue());
            }
        }
        return;
    }
    String defaultResource = model instanceof Project ? Project.BNDFILE : model instanceof Workspace ? Workspace.BUILDFILE : null;
    IResource resource = DefaultBuildErrorDetailsHandler.getDefaultResource(project, defaultResource);
    if (resource.exists()) {
        IMarker marker = resource.createMarker(markerType);
        marker.setAttribute(IMarker.SEVERITY, severity);
        marker.setAttribute(IMarker.MESSAGE, formatted);
    }
}
Also used : DefaultBuildErrorDetailsHandler(org.bndtools.build.api.DefaultBuildErrorDetailsHandler) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) MarkerData(org.bndtools.build.api.MarkerData) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) SetLocation(aQute.service.reporter.Reporter.SetLocation) Location(aQute.service.reporter.Report.Location) Workspace(aQute.bnd.build.Workspace)

Aggregations

BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)4 LinkedList (java.util.LinkedList)2 IMarker (org.eclipse.core.resources.IMarker)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Location (aQute.service.reporter.Report.Location)1 SetLocation (aQute.service.reporter.Reporter.SetLocation)1 Iterator (java.util.Iterator)1 DefaultBuildErrorDetailsHandler (org.bndtools.build.api.DefaultBuildErrorDetailsHandler)1 MarkerData (org.bndtools.build.api.MarkerData)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 Annotation (org.eclipse.jface.text.source.Annotation)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1