use of org.eclipse.core.resources.IMarker 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.eclipse.core.resources.IMarker in project bndtools by bndtools.
the class AbstractNewBndProjectWizard method performFinish.
@Override
public boolean performFinish() {
boolean result = super.performFinish();
if (result) {
final IJavaProject javaProj = (IJavaProject) getCreatedElement();
final IProject project = javaProj.getProject();
final Map<String, String> templateParams = getProjectTemplateParams();
try {
// Run using the progress bar from the wizard dialog
getContainer().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
// Make changes to the project
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
generateProjectContent(project, monitor, templateParams);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating project content from template", e));
}
}
};
javaProj.getProject().getWorkspace().run(op, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
result = true;
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
final IStatus status;
if (targetException instanceof CoreException) {
status = ((CoreException) targetException).getStatus();
} else {
status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error creating bnd project contents", targetException);
}
logger.logStatus(status);
ErrorDialog.openError(getShell(), "Error", "Error creating bnd project", status);
result = false;
} catch (InterruptedException e) {
// Shouldn't happen
}
// get bnd.bnd file
IFile bndFile = javaProj.getProject().getFile(Project.BNDFILE);
// check to see if we need to add marker about missing workspace
try {
if (!Central.hasWorkspaceDirectory()) {
IResource markerTarget = bndFile;
if (markerTarget == null || markerTarget.getType() != IResource.FILE || !markerTarget.exists())
markerTarget = project;
IMarker marker = markerTarget.createMarker(BndtoolsConstants.MARKER_BND_MISSING_WORKSPACE);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.MESSAGE, "Missing Bnd Workspace. Create a new workspace with the 'New Bnd OSGi Workspace' wizard.");
marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, true);
marker.setAttribute("$bndType", BndtoolsConstants.MARKER_BND_MISSING_WORKSPACE);
}
} catch (Exception e1) {
// ignore exceptions, this is best effort to help new users
}
// Open the bnd.bnd file in the editor
try {
if (bndFile.exists())
IDE.openEditor(getWorkbench().getActiveWorkbenchWindow().getActivePage(), bndFile);
} catch (PartInitException e) {
ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Failed to open project descriptor file {0} in the editor.", bndFile.getFullPath().toString()), e));
}
}
return result;
}
use of org.eclipse.core.resources.IMarker in project bndtools by bndtools.
the class ProjectBuildPage method loadProblems.
void loadProblems() {
IResource resource = ResourceUtil.getResource(getEditorInput());
problemSeverity = 0;
messageSeverityMap.clear();
if (resource != null) {
try {
IMarker[] markers;
markers = resource.findMarkers(BndtoolsConstants.MARKER_BND_PROBLEM, true, 0);
loadMarkers(markers);
markers = resource.findMarkers(BndtoolsConstants.MARKER_BND_PATH_PROBLEM, true, 0);
loadMarkers(markers);
markers = resource.findMarkers(BndtoolsConstants.MARKER_BND_MISSING_WORKSPACE, true, 0);
loadMarkers(markers);
} catch (CoreException e) {
logger.logError("Error retrieving problem markers", e);
}
}
ImageDescriptor editorImgOverlay;
if (problemSeverity >= IMarker.SEVERITY_ERROR) {
pageImage = imgError;
editorImgOverlay = imgErrorOverlay;
} else if (problemSeverity >= IMarker.SEVERITY_WARNING) {
pageImage = imgWarning;
editorImgOverlay = imgWarningOverlay;
} else {
pageImage = null;
editorImgOverlay = null;
}
editor.updatePageTitle(this);
editor.setOverlayTitleImage(editorImgOverlay);
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class MarkerHighlighter method createMarker.
private IMarker createMarker(Match match) throws CoreException {
Position position = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(match);
if (position == null) {
if (match.getOffset() < 0 || match.getLength() < 0)
return null;
position = new Position(match.getOffset(), match.getLength());
} else {
// need to clone position, can't have it twice in a document.
position = new Position(position.getOffset(), position.getLength());
}
IMarker marker = match.isFiltered() ? fFile.createMarker(SearchPlugin.FILTERED_SEARCH_MARKER) : fFile.createMarker(NewSearchUI.SEARCH_MARKER);
HashMap<String, Integer> attributes = new HashMap<>(4);
if (match.getBaseUnit() == Match.UNIT_CHARACTER) {
attributes.put(IMarker.CHAR_START, Integer.valueOf(position.getOffset()));
attributes.put(IMarker.CHAR_END, Integer.valueOf(position.getOffset() + position.getLength()));
} else {
attributes.put(IMarker.LINE_NUMBER, Integer.valueOf(position.getOffset()));
}
marker.setAttributes(attributes);
return marker;
}
use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.
the class SearchResultViewEntry method backupMarkers.
void backupMarkers() {
if (fResource != null)
fModificationStamp = fResource.getModificationStamp();
List<IMarker> markers = getMarkers();
fAttributes = new ArrayList<>(markers.size());
Iterator<IMarker> iter = markers.iterator();
while (iter.hasNext()) {
IMarker marker = iter.next();
Map<String, Object> attributes = null;
try {
attributes = marker.getAttributes();
} catch (CoreException ex) {
// don't backup corrupt marker
continue;
}
fAttributes.add(attributes);
}
}
Aggregations