Java Code Examples for org.eclipse.core.resources.IMarker#setAttribute()

The following examples show how to use org.eclipse.core.resources.IMarker#setAttribute() . 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 File: SVNMarkerListener.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void setMessage(LocalResourceStatus status, IMarker marker)
		throws CoreException {
	int count = 0;
	if (status.isTextConflicted()) count++;
	if (status.isPropConflicted()) count++;
	if (status.hasTreeConflict()) count++;
	StringBuffer message = new StringBuffer(Policy.bind("SVNConflicts") + " ("); //$NON-NLS-1$ //$NON-NLS-2$
	if (status.isTextConflicted()) {
		message.append("Text"); //$NON-NLS-1$
		if (count == 2) message.append(" and "); //$NON-NLS-1$
		if (count == 3) message.append(", "); //$NON-NLS-1$
	}
	if (status.isPropConflicted()) {
		message.append("Property"); //$NON-NLS-1$
		if (count == 3) message.append(" and "); //$NON-NLS-1$
	}
	if (status.hasTreeConflict()) {
		message.append("Tree"); //$NON-NLS-1$
	}
	if (count == 1) message.append(" Conflict"); //$NON-NLS-1$
	else message.append(" Conflicts"); //$NON-NLS-1$
	message.append(")"); //$NON-NLS-1$
	marker.setAttribute(IMarker.MESSAGE, message.toString());
}
 
Example 2
Source File: ProblemMarkerBuilder.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * addMarker Method that adds a Marker to a File, which can then be displayed as an error/warning in the IDE.
 *
 * @param file the IResource of the File to which the Marker is added
 * @param message the message the Marker is supposed to display
 * @param lineNumber the Line to which the Marker is supposed to be added
 * @param start the number of the start character for the Marker
 * @param end the number of the end character for the Marker
 */
private void addMarker(final IResource file, final String message, int lineNumber, final int start, final int end) {
	try {
		final IMarker marker = file.createMarker(Constants.MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
		if (lineNumber == -1) {
			lineNumber = 1;
		}
		marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
		marker.setAttribute(IMarker.CHAR_START, start);
		marker.setAttribute(IMarker.CHAR_END, end);
		// IJavaModelMarker is important for the Quickfix Processor to work
		// correctly
		marker.setAttribute(IJavaModelMarker.ID, Constants.JDT_PROBLEM_ID);
	}
	catch (final CoreException e) {}
}
 
Example 3
Source File: UnSuppressWarningFix.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run(final IMarker marker) {
	final File warningsFile = new File(marker.getResource().getProject().getLocation().toOSString() + Constants.outerFileSeparator + Constants.SUPPRESSWARNING_FILE);
	this.xmlParser = new XMLParser(warningsFile);
	try {
		if (warningsFile.exists()) {
			this.xmlParser.useDocFromFile();
		} else {
			this.xmlParser.createNewDoc();
			this.xmlParser.createRootElement(Constants.SUPPRESSWARNINGS_ELEMENT);
		}

		this.xmlParser.removeNodeByAttrValue(Constants.SUPPRESSWARNING_ELEMENT, Constants.ID_ATTR, marker.getAttribute(IMarker.SOURCE_ID) + "");
		this.xmlParser.writeXML();
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
		marker.getResource().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
	}
	catch (final CoreException e) {
		Activator.getDefault().logError(e);
	}

}
 
Example 4
Source File: RequestorWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see ICodeSnippetRequestor
 */
public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) {
	try {
		IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaModelMarker.TRANSIENT_PROBLEM);
		marker.setAttribute(IJavaModelMarker.ID, problem.getID());
		marker.setAttribute(IMarker.CHAR_START, problem.getSourceStart());
		marker.setAttribute(IMarker.CHAR_END, problem.getSourceEnd() + 1);
		marker.setAttribute(IMarker.LINE_NUMBER, problem.getSourceLineNumber());
		//marker.setAttribute(IMarker.LOCATION, "#" + problem.getSourceLineNumber());
		marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
		marker.setAttribute(IMarker.SEVERITY, (problem.isWarning() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR));
		marker.setAttribute(IMarker.SOURCE_ID, JavaBuilder.SOURCE_ID);
		this.requestor.acceptProblem(marker, new String(fragmentSource), fragmentKind);
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: AbstractProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testAnnotationOnMultipleLines() throws Exception {
	IMarker warning = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	warning.setAttribute(IMarker.LOCATION, "line: 1 " + file.getFullPath().toString());
	warning.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
	warning.setAttribute(IMarker.CHAR_START, 0);
	warning.setAttribute(IMarker.CHAR_END, 43);
	warning.setAttribute(IMarker.LINE_NUMBER, 1);
	warning.setAttribute(IMarker.MESSAGE, "Foo");
	
	List<Annotation> annotations = hover.getAnnotations(1, 40);
	assertEquals(2, annotations.size());
	// The error is on the same line as the requested position, so it should be returned first
	assertEquals("org.eclipse.xtext.ui.editor.error", annotations.get(0).getType());
	assertEquals("org.eclipse.xtext.ui.editor.warning", annotations.get(1).getType());
	
	warning.delete();
}
 
Example 6
Source File: MarkerCreator.java    From xtext-eclipse with 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 7
Source File: BuildscriptGenerator.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private static void createErrorMarker(IProject project, String message) throws CoreException {
  try {
    IMarker marker = project.createMarker(MARKER_ID);
    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
    marker.setAttribute(IMarker.MESSAGE, message);
    marker.setAttribute(IMarker.LOCATION, BuildscriptGenerator.class.getName());
  } catch (CoreException ex) {
    // resource is not (yet) known by the workbench
    // ignore
  }
}
 
Example 8
Source File: ErrorMarkerGenerator.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds crypto-misuse error marker with message {@link message} into file {@link sourceFile} at Line {@link line}.
 *
 * @param markerType name of the error
 * @param id unique id of the error
 * @param sourceFile File the marker is generated into
 * @param line Line the marker is generated at
 * @param message Error Message
 * @param sev Severities type
 * @return <code>true</code>/<code>false</code> if error marker was (not) added successfully
 */
public boolean addMarker(final String markerType, final int id, final IResource sourceFile, final int line, final String message, final String crySLRuleName, final String jimpleCode, final Severities sev,
		final HashMap<String, String> additionalErrorInfos, boolean isSuppressed) {

	if (!sourceFile.exists() || !sourceFile.isAccessible()) {
		Activator.getDefault().logError(Constants.NO_RES_FOUND);
		return false;
	}

	IMarker marker;
	try {
		marker = sourceFile.createMarker(markerType);
		marker.setAttribute("errorType", markerType);
		marker.setAttribute(IMarker.LINE_NUMBER, line);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute("crySLRuleName", crySLRuleName);
		marker.setAttribute("errorJimpleCode", jimpleCode);
		marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
		if (isSuppressed) {
			marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
		} else {
			marker.setAttribute(IMarker.SEVERITY,
					(sev == Severities.Error) ? IMarker.SEVERITY_ERROR : ((sev == Severities.Warning) ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_INFO));
		}
		marker.setAttribute(IMarker.SOURCE_ID, id);

		if (markerType.equals(Constants.REQUIRED_PREDICATE_MARKER_TYPE)) {
			marker.setAttribute("predicate", additionalErrorInfos.get("predicate"));
			marker.setAttribute("predicateParamCount", additionalErrorInfos.get("predicateParamCount"));
			marker.setAttribute("errorParam", additionalErrorInfos.get("errorParam"));
			marker.setAttribute("errorParamIndex", additionalErrorInfos.get("errorParamIndex"));
		}

	}
	catch (final CoreException e) {
		Activator.getDefault().logError(e);
		return false;
	}
	return this.markers.add(marker);
}
 
Example 9
Source File: RadlValidatingVisitor.java    From RADL with Apache License 2.0 5 votes vote down vote up
private void validateRadl(IResource resource) throws CoreException {
  if ("radl".equals(resource.getFileExtension()) && resource instanceof IFile) {
    IFile file = (IFile)resource;
    Collection<Issue> issues = new ArrayList<>();
    validator.validate(file.getContents(), issues);
    for (Issue issue : issues) {
      IMarker marker = resource.createMarker(MARKER_TYPE);
      marker.setAttribute(IMarker.SEVERITY, levelToSeverity(issue.getLevel()));
      marker.setAttribute(IMarker.LINE_NUMBER, issue.getLine());
      marker.setAttribute(IMarker.MESSAGE, issue.getMessage());
    }
  }
}
 
Example 10
Source File: AddMarkerHandler.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void writeMarkers(IResource resource) {
	try {
		IMarker marker = resource.createMarker(IMarker.TASK);
		marker.setAttribute(IMarker.MESSAGE, "This is a task");
		marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 11
Source File: AbstractProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMultipleAnnotationTypes() throws Exception {
	IMarker warning = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	warning.setAttribute(IMarker.LOCATION, "line: 2 " + file.getFullPath().toString());
	warning.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
	warning.setAttribute(IMarker.CHAR_START, 14);
	warning.setAttribute(IMarker.CHAR_END, 19);
	warning.setAttribute(IMarker.LINE_NUMBER, 2);
	warning.setAttribute(IMarker.MESSAGE, "Foo");
	
	IMarker info = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	info.setAttribute(IMarker.LOCATION, "line: 2 " + file.getFullPath().toString());
	info.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
	info.setAttribute(IMarker.CHAR_START, 20);
	info.setAttribute(IMarker.CHAR_END, 29);
	info.setAttribute(IMarker.LINE_NUMBER, 2);
	info.setAttribute(IMarker.MESSAGE, "Bar");
	
	List<Annotation> annotations = hover.getAnnotations(1, -1);
	List<Annotation> sorted = hover.sortBySeverity(annotations);
	assertEquals(3, sorted.size());
	// First errors, then warnings, then the rest
	assertEquals("org.eclipse.xtext.ui.editor.error", sorted.get(0).getType());
	assertEquals("org.eclipse.xtext.ui.editor.warning", sorted.get(1).getType());
	assertEquals("org.eclipse.xtext.ui.editor.info", sorted.get(2).getType());
	
	warning.delete();
	info.delete();
}
 
Example 12
Source File: CMakeErrorParser.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a basic problem marker which should be enhanced with more problem information (e.g. severity, file name,
 * line number exact message).
 *
 * @param fileName
 *          the file where the problem occurred, relative to the source-root or <code>null</code> to denote just the
 *          current project being build
 * @param severity
 *          the severity of the problem, see {@link IMarker} for acceptable severity values
 * @param fullMessage
 *          the complete message, including the classification
 * @throws CoreException
 */
protected final IMarker createBasicMarker(String fileName, int severity, String fullMessage) throws CoreException {
  IMarker marker;
  if (fileName == null) {
    marker = srcPath.createMarker(CMAKE_PROBLEM_MARKER_ID);
  } else {
    // NOTE normally, cmake reports the file name relative to source root.
    // BUT some messages give an absolute file-system path which is problematic when the build
    // runs in a docker container
    // So we do some heuristics here...
    IPath path = new Path(fileName);
    try {
      // normal case: file is rel. to source root
      marker = srcPath.getFile(path).createMarker(CMAKE_PROBLEM_MARKER_ID);
    } catch (CoreException ign) {
      // try abs. path
      IPath srcLocation = srcPath.getLocation();
      if (srcLocation.isPrefixOf(path)) {
        // can resolve the cmake file
        int segmentsToRemove = srcLocation.segmentCount();
        path = path.removeFirstSegments(segmentsToRemove);
        marker = srcPath.getFile(path).createMarker(CMAKE_PROBLEM_MARKER_ID);
      } else {
        // possibly a build in docker container. we would reach this if the source-dir path inside
        // the container is NOT the same as the one in the host/IDE.
        // for now, just add the markers to the source dir and lets users file issues:-)
        marker = srcPath.createMarker(CMAKE_PROBLEM_MARKER_ID);
        Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
            "Could not map " + fileName + " to a workspace resource. Did the build run in a container?"));
        // Extra case: IDE runs on Linux, build runs on Windows, or vice versa...
      }
    }
  }
  marker.setAttribute(IMarker.MESSAGE, fullMessage);
  marker.setAttribute(IMarker.SEVERITY, severity);
  marker.setAttribute(IMarker.LOCATION, CMakeErrorParser.class.getName());
  return marker;
}
 
Example 13
Source File: DerivedResourceMarkerCopier.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void copyProblemMarker(IFile javaFile, IEclipseTrace traceToSource, Set<IMarker> problemsInJava, IFile srcFile)
		throws CoreException {
	String sourceMarkerType = null;
	for (IMarker marker : problemsInJava) {
		String message = (String) marker.getAttribute(IMarker.MESSAGE);
		if (message == null) {
			continue;
		}
		Integer charStart = marker.getAttribute(IMarker.CHAR_START, 0);
		Integer charEnd = marker.getAttribute(IMarker.CHAR_END, 0);
		int severity = MarkerUtilities.getSeverity(marker);

		ILocationInEclipseResource associatedLocation = traceToSource.getBestAssociatedLocation(new TextRegion(charStart,
				charEnd - charStart));
		if (associatedLocation != null) {
			if (sourceMarkerType == null) {
				sourceMarkerType = determinateMarkerTypeByURI(associatedLocation.getSrcRelativeResourceURI());
			}
			if (!srcFile.equals(findIFile(associatedLocation, srcFile.getWorkspace()))) {
				LOG.error("File in associated location is not the same as main source file.");
			}
			IMarker xtendMarker = srcFile.createMarker(sourceMarkerType);
			xtendMarker.setAttribute(IMarker.MESSAGE, "Java problem: " + message);
			xtendMarker.setAttribute(IMarker.SEVERITY, severity);
			ITextRegionWithLineInformation region = associatedLocation.getTextRegion();
			xtendMarker.setAttribute(IMarker.LINE_NUMBER, region.getLineNumber());
			xtendMarker.setAttribute(IMarker.CHAR_START, region.getOffset());
			xtendMarker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength());
			xtendMarker.setAttribute(COPIED_FROM_FILE, javaFile.getFullPath().toString());
		}
	}

}
 
Example 14
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
public static IMarker addTscMarker(IResource resource, String message, int severity, int lineNumber)
		throws CoreException {
	IMarker marker = resource.createMarker(TSC_MARKER_TYPE);
	marker.setAttribute(IMarker.MESSAGE, message);
	marker.setAttribute(IMarker.SEVERITY, severity);
	marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
	return marker;
}
 
Example 15
Source File: ReviewMarkerManager.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a marker for the given comment, assuming it has a location attached.
 */
private void markComment(
    TaskRepository taskRepository, TaskAttribute commentAttr, String taskId) {
  IProject project = AppraisePluginUtils.getProjectForRepository(taskRepository);

  String filePath = getFilePath(commentAttr);
  IResource resource = project;
  if (filePath != null) {
    resource = project.getFile(filePath);
    if (resource == null || !resource.exists()) {
      return;
    }
  }

  try {
    IMarker marker = resource.createMarker(AppraiseUiPlugin.REVIEW_TASK_MARKER_ID);
    marker.setAttribute(IMarker.MESSAGE, getMessage(commentAttr));
    marker.setAttribute(IMarker.TRANSIENT, true);
    if (filePath != null) {
      marker.setAttribute(IMarker.LINE_NUMBER, getLineNumber(commentAttr));
    }
    marker.setAttribute(IMarker.USER_EDITABLE, false);
    TaskAttribute authorAttribute = commentAttr.getMappedAttribute(TaskAttribute.COMMENT_AUTHOR);
    if (authorAttribute != null) {
      marker.setAttribute(
          ReviewMarkerAttributes.REVIEW_AUTHOR_MARKER_ATTRIBUTE, authorAttribute.getValue());
    }
    marker.setAttribute(
        ReviewMarkerAttributes.REVIEW_DATETIME_MARKER_ATTRIBUTE,
        commentAttr.getMappedAttribute(TaskAttribute.COMMENT_DATE).getValue());
    marker.setAttribute(
        ReviewMarkerAttributes.REVIEW_ID_MARKER_ATTRIBUTE, getCommentId(commentAttr));
    marker.setAttribute(
        ReviewMarkerAttributes.REVIEW_RESOLVED_MARKER_ATTRIBUTE,
        getResolvedDisplayText(commentAttr));
    marker.setAttribute("TaskId", taskId);
  } catch (CoreException e) {
    AppraiseUiPlugin.logError("Failed to create marker at " + filePath, e);
  }
}
 
Example 16
Source File: Animator.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private void addAnimationMarker(EObject eobject) {
	IResource resource = null;
	IWorkspace workspace = ResourcesPlugin.getWorkspace(); 
	if (workspace != null) {
		URI uri = eobject.eResource().getURI();
		if (uri.isPlatform()) {
			resource = workspace.getRoot().getFile(new Path(uri.toPlatformString(true)));
		} else {
			IPath fs = new Path(uri.toFileString());
			for (IProject proj : workspace.getRoot().getProjects()) {
				if (proj.getLocation().isPrefixOf(fs)) {
					IPath relative = fs.makeRelativeTo(proj.getLocation());
					resource = proj.findMember(relative);
				}
			}
		}
	}
	if (resource != null && resource.exists()) {
		IMarker imarker = null;
		try {
			imarker = resource.createMarker(AnimationConfig.TXTUML_ANIMATION_MARKER_ID);
			imarker.setAttribute(EValidator.URI_ATTRIBUTE, URI.createPlatformResourceURI(resource.getFullPath().toString(), true) + "#" + EcoreUtil.getURI(eobject).fragment());
		} catch (CoreException e) {
			e.printStackTrace();
		}
		if (imarker != null) {
			IPapyrusMarker marker = PapyrusMarkerAdapter.wrap(eobject.eResource(), imarker);
			eobjectToMarker.put(eobject, marker);
		}
	}
}
 
Example 17
Source File: MarkerUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a marker with the given markerID on a resource. The marker will be
 * determined by the severity. The <code>problemType.getProblemId()</code> and
 * <code>problemTypeData</code> are stored as attributes on the marker.
 * 
 * @return the generated marker, or <code>null</code> if the severity for the
 *         problem type is {@link GdtProblemSeverity#IGNORE}.
 */
public static IMarker createQuickFixMarker(String markerID,
    IGdtProblemType problemType, String problemTypeData, IResource resource,
    String... messageArgs) throws CoreException {
  IMarker marker = createMarker(markerID, problemType, resource, messageArgs);
  if (marker != null) {
    marker.setAttribute(PROBLEM_TYPE_ID, problemType.getProblemId());
    marker.setAttribute(PROBLEM_TYPE_DATA, problemTypeData);
    return marker;
  }
  return null;
}
 
Example 18
Source File: AbstractLiveValidationMarkerConstraint.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addMarker(final DiagramEditor editor, final EditPartViewer viewer, final IFile target,
        final String elementId, final String location, final String message,
        final int statusSeverity) {
    if (target == null) {
        return;
    }
    IMarker marker = null;
    try {
        marker = target.createMarker(getMarkerType(editor));
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.LOCATION, location);
        marker.setAttribute(
                org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
                elementId);
        marker.setAttribute(CONSTRAINT_ID, getConstraintId());
        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 (final CoreException e) {
        ProcessDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
    }
}
 
Example 19
Source File: ToolMarkersHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public void addErrorMarker(IResource resource, ToolSourceMessage toolMessage, String markerType)
		throws CoreException {
	if(!resource.exists())
		return;
	
	// TODO: check if marker already exists?
	IMarker marker = resource.createMarker(markerType);
	
	marker.setAttribute(IMarker.SEVERITY, markerSeverityFrom(toolMessage.getSeverity()));
	marker.setAttribute(IMarker.MESSAGE, toolMessage.getMessage());
	
	if(!(resource instanceof IFile)) {
		return;
	}
	
	IFile file = (IFile) resource;
	
	int line = toolMessage.getFileLineNumber();
	if(line >= 0) {
		marker.setAttribute(IMarker.LINE_NUMBER, line);
	}
	
	SourceLineColumnRange range = toolMessage.range;
	
	SourceRange messageSR;
	
	try {
		Document doc = getDocumentForLocation(file);
		messageSR = getMessageRangeUsingDocInfo(range, doc);
	} catch(IOException e) {
		return;
	}
	
	if(messageSR != null) {
		try {
			marker.setAttribute(IMarker.CHAR_START, messageSR.getStartPos());
			marker.setAttribute(IMarker.CHAR_END, messageSR.getEndPos());
		} catch (CoreException ce) {
			EclipseCore.logStatus(ce);
		}
	}
	
}
 
Example 20
Source File: CompilerBuiltinsDetector.java    From cmake4eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private void createMarker(String message) throws CoreException {
  IMarker marker = cfgDescription.getProjectDescription().getProject().createMarker(MARKER_ID);
  marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
  marker.setAttribute(IMarker.MESSAGE, message);
}