Search in sources :

Example 11 with IMarker

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]);
}
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 12 with IMarker

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 13 with IMarker

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);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource)

Example 14 with IMarker

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;
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IMarker(org.eclipse.core.resources.IMarker)

Example 15 with IMarker

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PlatformObject(org.eclipse.core.runtime.PlatformObject) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5