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]);
}
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]));
}
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];
}
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);
}
}
Aggregations