org.eclipse.core.resources.IMarker Java Examples

The following examples show how to use org.eclipse.core.resources.IMarker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: spotbugs   Author: spotbugs   File: FilterPatternAction.java    License: GNU Lesser General Public License v2.1 7 votes vote down vote up
private String getPatternOrPatternType() {
    if (data instanceof IMarker) {
        BugInstance bug = MarkerUtil.findBugInstanceForMarker((IMarker) data);
        if (bug == null) {
            return null;
        }
        if (useSpecificPattern) {
            // uses specific pattern kind, the naming "Type" is misleading
            return bug.getType();
        }
        // uses pattern type, the naming "Abbrev" is misleading
        return bug.getAbbrev();
    } else if (data instanceof BugPattern) {
        BugPattern pattern = (BugPattern) data;
        if (useSpecificPattern) {
            // uses specific pattern kind, the naming "Type" is misleading
            return pattern.getType();
        }
        // uses pattern type, the naming "Abbrev" is misleading
        return pattern.getAbbrev();
    } else if (data instanceof BugCode) {
        // same as pattern.getAbbrev(): it's pattern type
        return ((BugCode) data).getAbbrev();
    }
    return null;
}
 
Example #2
Source Project: spotbugs   Author: spotbugs   File: PropertyPageAdapterFactory.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == IPropertySheetPage.class) {
        if (adaptableObject instanceof BugExplorerView || adaptableObject instanceof AbstractFindbugsView) {
            return new BugPropertySheetPage();
        }
    }
    if (adapterType == IPropertySource.class) {
        if (adaptableObject instanceof BugPattern || adaptableObject instanceof BugInstance
                || adaptableObject instanceof DetectorFactory || adaptableObject instanceof Plugin
                || adaptableObject instanceof BugGroup
                || adaptableObject instanceof BugAnnotation) {
            return new PropertySource(adaptableObject);
        }
        IMarker marker = Util.getAdapter(IMarker.class, adaptableObject);
        if (!MarkerUtil.isFindBugsMarker(marker)) {
            return null;
        }
        return new MarkerPropertySource(marker);
    }
    return null;
}
 
Example #3
Source Project: Pydev   Author: fabioz   File: OrganizeImportsFixesUnused.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void findAndDeleteUnusedImports(PySelection ps, PyEdit edit, IDocumentExtension4 doc, IFile f)
        throws Exception {
    Iterator<MarkerAnnotationAndPosition> it;
    if (edit != null) {
        it = edit.getPySourceViewer().getMarkerIterator();
    } else {

        IMarker markers[] = f.findMarkers(IMiscConstants.PYDEV_ANALYSIS_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
        MarkerAnnotationAndPosition maap[] = new MarkerAnnotationAndPosition[markers.length];
        int ix = 0;
        for (IMarker m : markers) {
            int start = (Integer) m.getAttribute(IMarker.CHAR_START);
            int end = (Integer) m.getAttribute(IMarker.CHAR_END);
            maap[ix++] =
                    new MarkerAnnotationAndPosition(new MarkerAnnotation(m), new Position(start, end - start));
        }
        it = Arrays.asList(maap).iterator();
    }
    ArrayList<MarkerAnnotationAndPosition> unusedImportsMarkers = getUnusedImports(it);
    sortInReverseDocumentOrder(unusedImportsMarkers);
    deleteImports(doc, ps, unusedImportsMarkers);

}
 
Example #4
Source Project: xtext-xtend   Author: eclipse   File: RebuildAffectedResourcesTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public void assertHasErrors(final IFile file, final String msgPart) {
  try {
    final IMarker[] findMarkers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
    for (final IMarker iMarker : findMarkers) {
      if (((MarkerUtilities.getSeverity(iMarker) == IMarker.SEVERITY_ERROR) && MarkerUtilities.getMessage(iMarker).contains(msgPart))) {
        return;
      }
    }
    IPath _fullPath = file.getFullPath();
    String _plus = ((("Expected an error marker containing \'" + msgPart) + "\' on ") + _fullPath);
    String _plus_1 = (_plus + " but found ");
    final Function1<IMarker, String> _function = (IMarker it) -> {
      return MarkerUtilities.getMessage(it);
    };
    String _join = IterableExtensions.join(ListExtensions.<IMarker, String>map(((List<IMarker>)Conversions.doWrapArray(findMarkers)), _function), ",");
    String _plus_2 = (_plus_1 + _join);
    Assert.fail(_plus_2);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #5
Source Project: xtext-eclipse   Author: eclipse   File: MarkerCreator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.0
 */
protected void setMarkerAttributes(Issue issue, IResource resource, IMarker marker) throws CoreException {
	String lineNR = "";
	if (issue.getLineNumber() != null) {
		lineNR = "line: " + issue.getLineNumber() + " ";
	}
	marker.setAttribute(IMarker.LOCATION, lineNR + resource.getFullPath().toString());
	marker.setAttribute(Issue.CODE_KEY, issue.getCode());		
	marker.setAttribute(IMarker.SEVERITY, getSeverity(issue));
	marker.setAttribute(IMarker.CHAR_START, issue.getOffset());
	if(issue.getOffset() != null && issue.getLength() != null)
		marker.setAttribute(IMarker.CHAR_END, issue.getOffset()+issue.getLength());
	marker.setAttribute(IMarker.LINE_NUMBER, issue.getLineNumber());
	marker.setAttribute(Issue.COLUMN_KEY, issue.getColumn());
	marker.setAttribute(IMarker.MESSAGE, issue.getMessage());

	if (issue.getUriToProblem()!=null) 
		marker.setAttribute(Issue.URI_KEY, issue.getUriToProblem().toString());
	if(issue.getData() != null && issue.getData().length > 0) {
		marker.setAttribute(Issue.DATA_KEY, Strings.pack(issue.getData()));
	}
	if (resolutionProvider != null && resolutionProvider.hasResolutionFor(issue.getCode())) {
		marker.setAttribute(FIXABLE_KEY, true);
	}
}
 
Example #6
Source Project: eclipse-cs   Author: checkstyle   File: CheckstyleMarkerFilter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Selects marker by matching the message against regular expressions.
 *
 * @param item
 *          the marker
 * @return <code>true</code> if the marker is selected
 */
private boolean selectByRegex(IMarker item) {

  if (mFilterByRegex) {

    int size = mFilterRegex != null ? mFilterRegex.size() : 0;
    for (int i = 0; i < size; i++) {

      String regex = mFilterRegex.get(i);

      String message = item.getAttribute(IMarker.MESSAGE, null);

      if (message != null && message.matches(regex)) {
        return false;
      }
    }
  }
  return true;

}
 
Example #7
Source Project: xtext-eclipse   Author: eclipse   File: BuilderParticipant.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject,
		Collection<OutputConfiguration> outputConfigurations) throws CoreException {
	Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap();
	for (OutputConfiguration config : outputConfigurations) {
		if (config.isCleanUpDerivedResources()) {
			List<IMarker> markers = Lists.newArrayList();
			for (IContainer container : getOutputs(builtProject, config)) {
				Iterables.addAll(
						markers,
						derivedResourceMarkers.findDerivedResourceMarkers(container,
								generatorIdProvider.getGeneratorIdentifier()));
			}
			generatorMarkers.put(config, markers);
		}
	}
	return buildGeneratorMarkersReverseLookupMap(generatorMarkers);
}
 
Example #8
Source Project: eclipse-cs   Author: checkstyle   File: Auditor.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void handleCheckstyleFailure(IProject project, CheckstyleException e)
        throws CheckstylePluginException {
  try {

    CheckstyleLog.log(e);

    // remove pre-existing project level marker
    project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);

    Map<String, Object> attrs = new HashMap<>();
    attrs.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_NORMAL));
    attrs.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_ERROR));
    attrs.put(IMarker.MESSAGE, NLS.bind(Messages.Auditor_msgMsgCheckstyleInternalError, null));

    IMarker projectMarker = project.createMarker(CheckstyleMarker.MARKER_ID);
    projectMarker.setAttributes(attrs);
  } catch (CoreException ce) {
    CheckstylePluginException.rethrow(e);
  }
}
 
Example #9
Source Project: eclipse.jdt.ls   Author: eclipse   File: EclipseBuildSupportTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUpdateJar() throws Exception {
	importProjects("eclipse/updatejar");
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("updatejar");
	assertIsJavaProject(project);
	List<IMarker> errors = ResourceUtils.getErrorMarkers(project);
	assertEquals("Unexpected errors " + ResourceUtils.toString(errors), 2, errors.size());
	File projectFile = project.getLocation().toFile();
	File validFooJar = new File(projectFile, "foo.jar");
	File destLib = new File(projectFile, "lib");
	FileUtils.copyFileToDirectory(validFooJar, destLib);
	File newJar = new File(destLib, "foo.jar");
	projectsManager.fileChanged(newJar.toPath().toUri().toString(), CHANGE_TYPE.CREATED);
	waitForBackgroundJobs();
	errors = ResourceUtils.getErrorMarkers(project);
	assertEquals("Unexpected errors " + ResourceUtils.toString(errors), 0, errors.size());

}
 
Example #10
Source Project: texlipse   Author: eclipse   File: AbstractProgramRunner.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
    * Create a layout warning marker to the given resource.
    *
    * @param resource the file where the problem occurred
    * @param message error message
    * @param lineNumber line number
    * @param markerType
    * @param severity Severity of the error
    */
   @SuppressWarnings("unchecked")
protected static void createMarker(IResource resource, 
   		Integer lineNumber, String message, String markerType, int severity) {
   	int lineNr = -1;
   	if (lineNumber != null) {
   		lineNr = lineNumber;
   	}
   	IMarker marker = AbstractProgramRunner.findMarker(resource, lineNr, message, markerType);
   	if (marker == null) {
   		try {
   			HashMap map = new HashMap();
   			map.put(IMarker.MESSAGE, message);
   			map.put(IMarker.SEVERITY, new Integer (severity));

   			if (lineNumber != null)
   				map.put(IMarker.LINE_NUMBER, lineNumber);

   			MarkerUtilities.createMarker(resource, map, markerType);
   		} catch (CoreException e) {
   			throw new RuntimeException(e);
   		}
   	}
   }
 
Example #11
Source Project: birt   Author: eclipse   File: BIRTGotoMarker.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void gotoXMLSourcePage( final IMarker marker )
{
	if ( activatePage( MultiPageReportEditor.XMLSourcePage_ID ) == false )
	{
		return;
	}

	final IReportEditorPage reportXMLSourcePage = (IReportEditorPage) editorPart.getActivePageInstance( );
	Display.getCurrent( ).asyncExec( new Runnable( ) {

		public void run( )
		{
			gotoXMLSourceMarker( reportXMLSourcePage, marker );
		}
	} );
}
 
Example #12
Source Project: slr-toolkit   Author: sebastiangoetz   File: QuickFix.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void run(IMarker marker) {
	try {
		String[] path = ((String) marker.getAttribute("PATH")).split("/");
		switch (fixType) {
			case ADD_TO_TAXONOMY:
				addToTaxonomy(path);
				break;
			case DELETE_FROM_FILE:
				deleteFromFile(path, marker.getAttribute(IMarker.LOCATION).toString());
				break;
			case MATCH_TAXONOMY:
				moveTermInFile(path, ((String) marker.getAttribute("PATH2")).split("/"), marker.getAttribute(IMarker.LOCATION).toString());
				break;
		}
		
		marker.delete();
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example #13
Source Project: CogniCrypt   Author: eclipse-cognicrypt   File: IssueReportFix.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run(IMarker curMarker) {
	marker = curMarker;

	Reporter dialog = new Reporter(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), marker.getResource().getName());
	dialog.create();

	if (dialog.open() == Window.OK) {
		try {
			createIssue(dialog.getIssueTitle(), dialog.getIssueText(), dialog.getAttachmentIndex(), getAttachment(dialog.getAttachmentIndex()));
		}
		catch (CoreException e) {
			Activator.getDefault().logError(e);
		}
	}
}
 
Example #14
Source Project: cppcheclipse   Author: kwin   File: SuppressResolution.java    License: Apache License 2.0 6 votes vote down vote up
public void run(IMarker marker) {
	try {
		IResource resource = (IResource)marker.getResource();
		IProject project = resource.getProject();
		String problemId = marker.getAttribute(ProblemReporter.ATTRIBUTE_ID, ""); //$NON-NLS-1$
		int line = marker.getAttribute(ProblemReporter.ATTRIBUTE_ORIGINAL_LINE_NUMBER, 0);
		File file = new File(marker.getAttribute(ProblemReporter.ATTRIBUTE_FILE, "")); //$NON-NLS-1$
		marker.delete();
		SuppressionProfile profile = new SuppressionProfile(CppcheclipsePlugin.getProjectPreferenceStore(project), project);
		suppress(profile, resource, file, problemId, line);
		profile.save();
	} 
	catch (Exception e) {
		CppcheclipsePlugin.logError("Could not save suppression", e);
	}
}
 
Example #15
Source Project: xtext-eclipse   Author: eclipse   File: EclipseBasedShouldGenerate.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
	URI uri = resource.getURI();
	if (uri == null || !uri.isPlatformResource()) {
		return false;
	}

	IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(uri.toPlatformString(true)));
	if (member != null && member.getType() == IResource.FILE) {
		ProjectConfigAdapter projectConfigAdapter = ProjectConfigAdapter.findInEmfObject(resource.getResourceSet());
		if (projectConfigAdapter != null) {
			IProjectConfig projectConfig = projectConfigAdapter.getProjectConfig();
			if (projectConfig != null && Objects.equals(member.getProject().getName(), projectConfig.getName())) {
				try {
					return member.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE) != IMarker.SEVERITY_ERROR;
				} catch (CoreException e) {
					LOG.error("The resource " + member.getName() + " does not exist", e);
					return false;
				}
			}
		}
	}
	return false;
}
 
Example #16
Source Project: spotbugs   Author: spotbugs   File: BugResolutionAssociations.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public IMarkerResolution[] createBugResolutions(String bugType, IMarker marker) {
    Assert.isNotNull(bugType);
    Assert.isNotNull(marker);
    List<QuickFixContribution> classes = quickFixes.get(bugType);
    if (classes == null) {
        return new IMarkerResolution[0];
    }

    Set<BugResolution> fixes = instantiateBugResolutions(classes);
    for (Iterator<BugResolution> iterator = fixes.iterator(); iterator.hasNext();) {
        BugResolution fix = iterator.next();
        if (fix.isApplicable(marker)) {
            fix.setMarker(marker);
        } else {
            iterator.remove();
        }
    }
    return fixes.toArray(new IMarkerResolution[fixes.size()]);
}
 
Example #17
Source Project: scava   Author: crossminer   File: CrossflowMarkerNavigationProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
public static IMarker addMarker(IFile file, String elementId, String location, String message, int statusSeverity) {
	IMarker marker = null;
	try {
		marker = file.createMarker(MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.LOCATION, location);
		marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
		int markerSeverity = IMarker.SEVERITY_INFO;
		if (statusSeverity == IStatus.WARNING) {
			markerSeverity = IMarker.SEVERITY_WARNING;
		} else if (statusSeverity == IStatus.ERROR || statusSeverity == IStatus.CANCEL) {
			markerSeverity = IMarker.SEVERITY_ERROR;
		}
		marker.setAttribute(IMarker.SEVERITY, markerSeverity);
	} catch (CoreException e) {
		CrossflowDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
	}
	return marker;
}
 
Example #18
Source Project: n4js   Author: eclipse   File: BuildInstruction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private boolean shouldGenerate(Resource resource, IProject aProject) {
	try {
		Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
		for (Pair<IStorage, IProject> pair : storages) {
			if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
				IFile file = (IFile) pair.getFirst();
				int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				// If the generator itself placed an error marker on the resource, we have to ignore that error.
				// Easiest way here is to remove that error marker-type and look for other severe errors once more:
				if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
					// clean
					GeneratorMarkerSupport generatorMarkerSupport = injector
							.getInstance(GeneratorMarkerSupport.class);
					generatorMarkerSupport.deleteMarker(resource);
					// and recompute:
					findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
				}
				// the final decision to build:
				return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
			}
		}
		return false;
	} catch (CoreException exc) {
		throw new WrappedException(exc);
	}
}
 
Example #19
Source Project: eclipse.jdt.ls   Author: eclipse   File: WorkspaceDiagnosticsHandler.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static Diagnostic toDiagnostic(IDocument document, IMarker marker, boolean isDiagnosticTagSupported) {
	if (marker == null || !marker.exists()) {
		return null;
	}
	Diagnostic d = new Diagnostic();
	d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
	d.setMessage(marker.getAttribute(IMarker.MESSAGE, ""));
	int problemId = marker.getAttribute(IJavaModelMarker.ID, 0);
	d.setCode(String.valueOf(problemId));
	d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
	d.setRange(convertRange(document, marker));
	if (isDiagnosticTagSupported) {
		d.setTags(DiagnosticsHandler.getDiagnosticTag(problemId));
	}
	return d;
}
 
Example #20
Source Project: Pydev   Author: fabioz   File: TddTestWorkbench.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Callback that'll check if there are error markers in the mod1.py resource
 */
private ICallback<Boolean, Object> getHasBothErrorMarkersCondition(final IFile file) {
    return new ICallback<Boolean, Object>() {

        @Override
        public Boolean call(Object arg) {
            try {
                //must have both problems: syntax and analysis error!!
                IMarker[] markers = file.findMarkers(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER, false,
                        IResource.DEPTH_ZERO);
                return markers.length > 0;
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }
    };
}
 
Example #21
Source Project: xtext-eclipse   Author: eclipse   File: ProfilerAbstractBuilderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testFullBuildBigProjectWithLinkingErrors() throws Exception {
	IJavaProject project =  workspace.createJavaProject("foo");
	workspace.addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	int NUM_FILES = 200;
	IFile[] files = new IFile[NUM_FILES];
	StopWatch timer = new StopWatch();
	for (int i = 0; i < NUM_FILES; i++) {
		IFile file = folder.getFile("Test_" + i + "_" + F_EXT);
		files[i] = file;
		String contents = "object Foo" + i + " references Foo" + (i * 1000);
		if (i == NUM_FILES)
			contents = "object Foo" + i;
		file.create(new StringInputStream(contents), true, workspace.monitor());
	}
	logAndReset("Creating files", timer);
	workspace.build();
	logAndReset("Auto build", timer);
	IMarker[] iMarkers = folder.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE);
	assertEquals(NUM_FILES-1,iMarkers.length);
}
 
Example #22
Source Project: spotbugs   Author: spotbugs   File: MarkerUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public static @CheckForNull BugCode findBugCodeForMarker(IMarker marker) {
    try {
        Object bugCode = marker.getAttribute(FindBugsMarker.PATTERN_TYPE);
        if (bugCode instanceof String) {
            return DetectorFactoryCollection.instance().getBugCode((String) bugCode);
        }
    } catch (CoreException e) {
        FindbugsPlugin.getDefault().logException(e, "Marker does not contain bug code");
        return null;
    }
    return null;
}
 
Example #23
Source Project: spotbugs   Author: spotbugs   File: AbstractQuickfixTest.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private void applySpecificResolutionForAllMarkers(IMarker[] markers, Class<? extends IMarkerResolution> resolutionClass) {
    for (int i = 0; i < markers.length; i++) {
        IMarkerResolution[] resolutions = getResolutionGenerator().getResolutions(markers[i]);
        for (int j = 0; j < resolutions.length; j++) {
            if (resolutionClass.isInstance(resolutions[j])) {
                resolutions[j].run(markers[i]);
                return;
            }
        }
    }
    Assert.fail("No resolution of class " + resolutionClass);
}
 
Example #24
Source Project: google-cloud-eclipse   Author: GoogleCloudPlatform   File: XmlValidatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testValidate_badXml() throws IOException, CoreException {
  XmlValidator validator = new XmlValidator();
  validator.setHelper(new AppEngineWebXmlValidator());

  // This method should not apply any markers for invalid XML
  IFile file = createBogusProjectFile();
  byte[] badXml = BAD_XML.getBytes(StandardCharsets.UTF_8);
  validator.validate(file, badXml);

  IMarker[] emptyMarkers = ProjectUtils.waitUntilNoMarkersFound(file, IMarker.PROBLEM,
      true /* includeSubtypes */, IResource.DEPTH_ZERO);
  ArrayAssertions.assertIsEmpty(emptyMarkers);
}
 
Example #25
Source Project: KaiZen-OpenAPI-Editor   Author: RepreZen   File: JsonSchemaValidator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static int getLevel(JsonNode message) {
    if (message == null || !message.has("level")) {
        return IMarker.SEVERITY_INFO;
    }

    switch (message.get("level").asText()) {
    case "error":
    case "fatal":
        return IMarker.SEVERITY_ERROR;
    case "warning":
        return IMarker.SEVERITY_WARNING;
    default:
        return IMarker.SEVERITY_INFO;
    }
}
 
Example #26
Source Project: Pydev   Author: fabioz   File: PyEditBreakpointSync.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void updateAnnotations() {
    if (edit == null) {
        return;
    }
    IDocumentProvider provider = edit.getDocumentProvider();
    if (provider == null) {
        return;
    }
    IAnnotationModel model = provider.getAnnotationModel(edit.getEditorInput());
    if (model == null) {
        return;
    }

    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) model;

    List<Annotation> existing = new ArrayList<Annotation>();
    Iterator<Annotation> it = model.getAnnotationIterator();
    if (it == null) {
        return;
    }
    while (it.hasNext()) {
        existing.add(it.next());
    }

    IDocument doc = edit.getDocument();
    IResource resource = PyMarkerUIUtils.getResourceForTextEditor(edit);
    IEditorInput externalFileEditorInput = AbstractBreakpointRulerAction.getExternalFileEditorInput(edit);
    List<IMarker> markers = AbstractBreakpointRulerAction.getMarkersFromEditorResource(resource, doc,
            externalFileEditorInput, 0, false, model);

    Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>();
    for (IMarker m : markers) {
        Position pos = PyMarkerUIUtils.getMarkerPosition(doc, m, model);
        MarkerAnnotation newAnnotation = new MarkerAnnotation(m);
        annotationsToAdd.put(newAnnotation, pos);
    }

    //update all in a single step
    modelExtension.replaceAnnotations(existing.toArray(new Annotation[0]), annotationsToAdd);
}
 
Example #27
Source Project: eclipse.jdt.ls   Author: eclipse   File: WorkspaceDiagnosticsHandlerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private IMarker createMavenMarker(int severity, String msg, int line, int start, int end) throws Exception {
	IMarker m = createMarker(severity, msg, line, start, end);
	when(m.isSubtypeOf(IMavenConstants.MARKER_ID)).thenReturn(true);
	when(m.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1)).thenReturn(start);
	when(m.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1)).thenReturn(end);
	return m;
}
 
Example #28
Source Project: gama   Author: gama-platform   File: WrappedResource.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public int findMaxProblemSeverity() {
	if (severity == NOT_COMPUTED) {
		if (isOpen()) {
			try {
				severity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
			} catch (final CoreException e) {}
		} else {
			severity = CLOSED;
		}
	}
	return severity;
}
 
Example #29
Source Project: xds-ide   Author: excelsior-oss   File: XdsSourceBuilder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Report the specified problem to the user.
 * Returns null when this message si duplicated so no need to create new marker and it may be
 * reason to don't print it again to the console
 */
private IMarker reportProblem(Location loc) {
    loc.message = filterChars(loc.message); // KIDE-294
    IMarker marker = null;
       String toString = String.format("%s [%d:%d]: %s", loc.resource.toString(), loc.lineNumber, loc.posInLine, loc.message); //$NON-NLS-1$
       if (problemSet.add(toString)) { // KIDE-155: inline may cause duplicated messages, reject them
   		try {
   		    marker = markerMaker.makeMarker(loc);
   		} catch (CoreException e) {
   			LogHelper.logError(e);
   		}
       }
       return marker;
}
 
Example #30
@Override
public void selectionChanged(IAction action, ISelection selection) {
    bugInstance = null;
    // TODO learn to deal with ALL elements
    IMarker marker = MarkerUtil.getMarkerFromSingleSelection(selection);
    if (marker == null) {
        return;
    }
    bugInstance = MarkerUtil.findBugInstanceForMarker(marker);
}