/** * This method is here for use by the SABER validator's reporter instance ONLY. Do not use. See * defect 260144 for details. */ @SuppressWarnings("unchecked") public static IMarker setPriority(IMarker item, int priority) throws CoreException { Map attrib = item.getAttributes(); attrib.put(IMarker.PRIORITY, new Integer(priority)); item.setAttributes(attrib); return item; }
public void markFile() { if (!markerHandle.exists()) { return; } try { IMarker[] markers = markerHandle.findMarkers(modelMarker.getMarkerId(), true, IResource.DEPTH_ZERO); if (modelMarker.isActive(markers)) { if (markers.length == 0) { IMarker marker = markerHandle.createMarker(modelMarker.getMarkerId()); IResource resource = (IResource) markerHandle.getAdapter(IResource.class); marker.setAttributes( new String[] { MarkerProblem.ATTRIB_DESCRIPTION, MarkerProblem.ATTRIB_PATH, MarkerProblem.ATTRIB_SOURCE_OPENER }, getMarkerAttributes(resource)); } } else { markerHandle.deleteMarkers(modelMarker.getMarkerId(), true, IResource.DEPTH_ZERO); } } catch (CoreException e) { new Logger(CharacterCorePlugin.ID).error(Messages.ResourceModelMarker_ErrorWhileMarking, e); } }
private void addMarker(BuildContext context, IProblem problem) throws CoreException { IMarker marker = context.getFile().createMarker(IAptanaModelMarker.PROBLEM_MARKER); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.CHAR_START, problem.startOffset()); attributes.put(IMarker.CHAR_END, problem.endOffset()); attributes.put(IMarker.MESSAGE, problem.getMessage()); attributes.put(IMarker.SEVERITY, problem.getSeverity()); if (problem.lineNumber() > 0) attributes.put(IMarker.LINE_NUMBER, problem.lineNumber()); attributes.put(IAptanaModelMarker.ID, problem.getId()); marker.setAttributes(attributes); }
private static void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException { try { IMarker marker = file.createMarker(NewSearchUI.SEARCH_MARKER); HashMap attributes = new HashMap(4); attributes.put(IMarker.CHAR_START, new Integer(offset)); attributes.put(IMarker.CHAR_END, new Integer(offset + length)); marker.setAttributes(attributes); IDE.gotoMarker(editor, marker); marker.delete(); } catch (CoreException e) { } }
private void addMarkers( Collection<IProblem> items, String markerType, IFile file, IProgressMonitor monitor) throws CoreException { if (CollectionsUtil.isEmpty(items)) { return; } SubMonitor sub = SubMonitor.convert(monitor, items.size() * 2); for (IProblem item : items) { IMarker marker = file.createMarker(markerType); sub.worked(1); marker.setAttributes(item.createMarkerAttributes()); sub.worked(1); } sub.done(); }
/** * Create marker of missing end brace. * * @param resource Marker target resource. * @param model Block model. */ private void createMissingBraceMarker(IResource resource, BlockModel model) { try { IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); attribute.put(IMarker.MESSAGE, "Missing end brace."); attribute.put(IMarker.LINE_NUMBER, model.getLineNumber()); attribute.put(IMarker.CHAR_START, model.getOffset()); attribute.put(IMarker.CHAR_END, model.getOffset() + model.getStartBrace().length()); marker.setAttributes(attribute); } catch (CoreException e) { // log.error(e.getMessage(), e); } }
/** * Create marker of duplicate Map Entry error. * * @param resource Marker target resource. * @param model Map Entry model. */ private void createDuplicateKeyMarker(IResource resource, NamedModel model) { try { IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); attribute.put( IMarker.MESSAGE, "The value of the key " + model.getNameText() + " is duplicated."); attribute.put(IMarker.LINE_NUMBER, model.getLineNumber()); attribute.put(IMarker.CHAR_START, model.getOffset()); attribute.put(IMarker.CHAR_END, model.getOffset() + model.getNameText().length()); marker.setAttributes(attribute); } catch (CoreException e) { // log.error(e.getMessage(), e); } }
/** * Create marker of statement error. * * @param resource Marker target resource. * @param lineNumber start line number. * @param charStart marker start position. * @param charEnd marker end position. */ private void createStatementErrorMarker( IResource resource, int lineNumber, int charStart, int charEnd) { try { IMarker marker = resource.createMarker(PROBLEM_MARKER_KEY); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); attribute.put(IMarker.MESSAGE, "Position of statement is invalid."); attribute.put(IMarker.LINE_NUMBER, lineNumber); attribute.put(IMarker.CHAR_START, charStart); attribute.put(IMarker.CHAR_END, charEnd); marker.setAttributes(attribute); } catch (CoreException e) { // log.error(e.getMessage(), e); } }
/** * Jump to and highlight a line based on the ApexCodeLocation. * * @param location */ public void highlightLine(ApexCodeLocation location) { if (Utils.isEmpty(location) || location.getFile() == null || !location.getFile().exists()) { Utils.openWarn("Highlight Failed", "Unable to highlight test file - file is unknown."); return; } HashMap<String, Integer> map = new HashMap<>(); map.put(IMarker.LINE_NUMBER, location.getLine()); try { IMarker marker = location.getFile().createMarker(IMarker.TEXT); marker.setAttributes(map); IDE.openEditor(getSite().getWorkbenchWindow().getActivePage(), marker); } catch (Exception e) { logger.error("Unable to highlight line.", e); Utils.openError(new InvocationTargetException(e), true, "Unable to highlight line."); } }
IMarker createMarkerFromSearchMatch(IFile file, SearchMatch match) { IMarker marker = null; try { if (CHOICE_METHOD_DECLARATION.equals(mChoice)) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put(IMarker.CHAR_START, new Integer(match.getOffset())); map.put(IMarker.CHAR_END, new Integer(match.getOffset() + match.getLength())); marker = file.createMarker(IMarker.TEXT); marker.setAttributes(map); } else if (CHOICE_ERROR_LINE.equals(mChoice)) { marker = file.createMarker(IMarker.TEXT); marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber); } } catch (CoreException e) { Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e); DdmsPlugin.getDefault().getLog().log(s); } return marker; }
private void createInconsistentBuildMarker(CoreException coreException) throws CoreException { String message = null; IStatus status = coreException.getStatus(); if (status.isMultiStatus()) { IStatus[] children = status.getChildren(); if (children != null && children.length > 0) message = children[0].getMessage(); } if (message == null) message = coreException.getMessage(); IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID }, new Object[] { Messages.bind(Messages.build_inconsistentProject, message), new Integer(IMarker.SEVERITY_ERROR), new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID }); }
private static void createMarkers(final Map<String, List<Diagnostic>> diagnostics) throws CoreException { for (Map.Entry<String, List<Diagnostic>> entry : diagnostics.entrySet()) { String fileName = entry.getKey(); // ignore the default library if (fileName.equals("lib.d.ts")) { continue; } // create the markers for this file Path path = new Path(fileName); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); List<Diagnostic> fileDiagnostics = entry.getValue(); for (Diagnostic diagnostic : fileDiagnostics) { IMarker marker = file.createMarker(MARKER_TYPE); Map<String, Object> attributes = createMarkerAttributes(diagnostic); marker.setAttributes(attributes); } } }
public void createProblemFor( final IResource resource, final IErlFunction erlElement, final String message, final int problemSeverity) throws CoreException { try { final IMarker marker = resource.createMarker(PROBLEM_MARKER); final int severity = problemSeverity; final ISourceRange range = erlElement == null ? null : erlElement.getNameRange(); final int start = range == null ? 0 : range.getOffset(); final int end = range == null ? 1 : start + range.getLength(); marker.setAttributes( new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END}, new Object[] { message, Integer.valueOf(severity), Integer.valueOf(start), Integer.valueOf(end) }); } catch (final CoreException e) { throw e; } }
/** This method adds a message to a resource in the task list. */ public static IMarker addTask( String pluginId, IResource resource, String location, String messageId, String message, int markerType, String markerName, String targetObjectName, String groupName, int offset, int length) throws CoreException { if ((message == null) || (resource == null) || (!resource.exists())) { return null; } int severity = getSeverity(markerType); // Allow duplicate entries in the task list. // Prior to a full validation, the validation framework will remove all messages owned // by a validator before it is executed. // Prior to an incremental validation, the validation framework will remove all messages, // on each of the changed resources, owned by a validator before it is invoked. // // It is up to the validator to make sure that it is not adding the same message // in more than one place, and also to clear out any old messages which are not cleared // by the validation framework. IMarker item = null; MarkerManager.getDefault().hook(resource); if (markerName != null && markerName.length() > 0) item = resource.createMarker(markerName); // add a validation marker else item = resource.createMarker(VALIDATION_MARKER); // add a validation marker // For performance reasons, replace the multiple setAttribute // calls above with a single setAttributes call. boolean offsetSet = ((offset != IMessage.OFFSET_UNSET) && (length != IMessage.OFFSET_UNSET)); int size = (offsetSet) ? 10 : 8; // add CHAR_START, CHAR_END only if the offset is set. If // the offset is set, it takes precendence over the line // number. (eclipse's rule, not mine.) String[] attribNames = new String[size]; Object[] attribValues = new Object[size]; // Very first thing, add the owner. That way, if the code dies // before things are persisted, hopefully this marker will be persisted. // Hopefully, eclipse WILL persist this field, as requested. attribNames[0] = VALIDATION_MARKER_OWNER; attribValues[0] = pluginId; attribNames[1] = VALIDATION_MARKER_SEVERITY; // this validation severity is stored, in // addition to the marker severity, to enable // more than one severity of message to be // displayed. e.g. ERROR | WARNING (using // binary OR). The IMarker constants are // regular decimal constants. attribValues[1] = new Integer(markerType); attribNames[2] = VALIDATION_MARKER_TARGETOBJECT; // to distinguish between messages which // are registered on an IResource, but // against different target objects attribValues[2] = ((targetObjectName == null) ? "" : targetObjectName); // $NON-NLS-1$ attribNames[3] = VALIDATION_MARKER_GROUP; attribValues[3] = ((groupName == null) ? "" : groupName); // $NON-NLS-1$ attribNames[4] = IMarker.MESSAGE; attribValues[4] = message; attribNames[5] = VALIDATION_MARKER_MESSAGEID; attribValues[5] = messageId; attribNames[6] = IMarker.SEVERITY; // IMarker.SEVERITY_ERROR, IMarker.SEVERITY_WARNING, // IMarker.SEVERITY_INFO attribValues[6] = new Integer(severity); try { // If the location is a line number, store it as a line number Integer lineNumber = Integer.valueOf(location); attribNames[7] = IMarker.LINE_NUMBER; attribValues[7] = lineNumber; } catch (NumberFormatException exc) { // Otherwise, store it as a text location attribNames[7] = IMarker.LOCATION; attribValues[7] = location; } if (offsetSet) { attribNames[8] = IMarker.CHAR_START; attribValues[8] = new Integer(offset); attribNames[9] = IMarker.CHAR_END; attribValues[9] = new Integer(offset + length); } item.setAttributes(attribNames, attribValues); return item; }
private boolean isWorthBuilding() throws CoreException { boolean abortBuilds = JavaCore.ABORT.equals( this.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true)); if (!abortBuilds) { if (DEBUG) System.out.println("JavaBuilder: Ignoring invalid classpath"); // $NON-NLS-1$ return true; } // Abort build only if there are classpath errors if (isClasspathBroken(this.javaProject, true)) { if (DEBUG) System.out.println( "JavaBuilder: Aborted build because project has classpath errors (incomplete or involved in cycle)"); //$NON-NLS-1$ removeProblemsAndTasksFor(this.currentProject); // remove all compilation problems IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID }, new Object[] { Messages.build_abortDueToClasspathProblems, new Integer(IMarker.SEVERITY_ERROR), new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID }); return false; } if (JavaCore.WARNING.equals( this.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true))) return true; // make sure all prereq projects have valid build states... only when aborting builds since // projects in cycles do not have build states // except for projects involved in a 'warning' cycle (see below) IProject[] requiredProjects = getRequiredProjects(false); for (int i = 0, l = requiredProjects.length; i < l; i++) { IProject p = requiredProjects[i]; if (getLastState(p) == null) { // The prereq project has no build state: if this prereq project has a 'warning' cycle // marker then allow build (see bug id 23357) JavaProject prereq = (JavaProject) JavaCore.create(p); if (prereq.hasCycleMarker() && JavaCore.WARNING.equals( this.javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) { if (DEBUG) System.out.println( "JavaBuilder: Continued to build even though prereq project " + p.getName() // $NON-NLS-1$ + " was not built since its part of a cycle"); //$NON-NLS-1$ continue; } if (!hasJavaBuilder(p)) { if (DEBUG) System.out.println( "JavaBuilder: Continued to build even though prereq project " + p.getName() // $NON-NLS-1$ + " is not built by JavaBuilder"); //$NON-NLS-1$ continue; } if (DEBUG) System.out.println( "JavaBuilder: Aborted build because prereq project " + p.getName() // $NON-NLS-1$ + " was not built"); //$NON-NLS-1$ removeProblemsAndTasksFor( this.currentProject); // make this the only problem for this project IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID }, new Object[] { isClasspathBroken(prereq, true) ? Messages.bind(Messages.build_prereqProjectHasClasspathProblems, p.getName()) : Messages.bind(Messages.build_prereqProjectMustBeRebuilt, p.getName()), new Integer(IMarker.SEVERITY_ERROR), new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID }); return false; } } return true; }
protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) throws CoreException { this.currentProject = getProject(); if (this.currentProject == null || !this.currentProject.isAccessible()) return new IProject[0]; if (DEBUG) System.out.println( "\nJavaBuilder: Starting build of " + this.currentProject.getName() // $NON-NLS-1$ + " @ " + new Date(System.currentTimeMillis())); // $NON-NLS-1$ this.notifier = new BuildNotifier(monitor, this.currentProject); this.notifier.begin(); boolean ok = false; try { this.notifier.checkCancel(); kind = initializeBuilder(kind, true); if (isWorthBuilding()) { if (kind == FULL_BUILD) { if (DEBUG) System.out.println("JavaBuilder: Performing full build as requested"); // $NON-NLS-1$ buildAll(); } else { if ((this.lastState = getLastState(this.currentProject)) == null) { if (DEBUG) System.out.println( "JavaBuilder: Performing full build since last saved state was not found"); //$NON-NLS-1$ buildAll(); } else if (hasClasspathChanged()) { // if the output location changes, do not delete the binary files from old location // the user may be trying something if (DEBUG) System.out.println( "JavaBuilder: Performing full build since classpath has changed"); //$NON-NLS-1$ buildAll(); } else if (this.nameEnvironment.sourceLocations.length > 0) { // if there is no source to compile & no classpath changes then we are done SimpleLookupTable deltas = findDeltas(); if (deltas == null) { if (DEBUG) System.out.println( "JavaBuilder: Performing full build since deltas are missing after incremental request"); //$NON-NLS-1$ buildAll(); } else if (deltas.elementSize > 0) { buildDeltas(deltas); } else if (DEBUG) { System.out.println( "JavaBuilder: Nothing to build since deltas were empty"); //$NON-NLS-1$ } } else { if (hasStructuralDelta()) { // double check that a jar file didn't get replaced in a // binary project if (DEBUG) System.out.println( "JavaBuilder: Performing full build since there are structural deltas"); //$NON-NLS-1$ buildAll(); } else { if (DEBUG) System.out.println( "JavaBuilder: Nothing to build since there are no source folders and no deltas"); //$NON-NLS-1$ this.lastState.tagAsNoopBuild(); } } } ok = true; } } catch (CoreException e) { Util.log( e, "JavaBuilder handling CoreException while building: " + this.currentProject.getName()); // $NON-NLS-1$ createInconsistentBuildMarker(e); } catch (ImageBuilderInternalException e) { Util.log( e.getThrowable(), "JavaBuilder handling ImageBuilderInternalException while building: " + this.currentProject.getName()); // $NON-NLS-1$ createInconsistentBuildMarker(e.coreException); } catch (MissingSourceFileException e) { // do not log this exception since its thrown to handle aborted compiles because of missing // source files if (DEBUG) System.out.println(Messages.bind(Messages.build_missingSourceFile, e.missingSourceFile)); removeProblemsAndTasksFor(this.currentProject); // make this the only problem for this project IMarker marker = this.currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttributes( new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.SOURCE_ID}, new Object[] { Messages.bind(Messages.build_missingSourceFile, e.missingSourceFile), new Integer(IMarker.SEVERITY_ERROR), JavaBuilder.SOURCE_ID }); } finally { for (int i = 0, l = this.participants == null ? 0 : this.participants.length; i < l; i++) this.participants[i].buildFinished(this.javaProject); if (!ok) // If the build failed, clear the previously built state, forcing a full build next time. clearLastState(); this.notifier.done(); cleanup(); } IProject[] requiredProjects = getRequiredProjects(true); if (DEBUG) System.out.println( "JavaBuilder: Finished build of " + this.currentProject.getName() // $NON-NLS-1$ + " @ " + new Date(System.currentTimeMillis()) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ return requiredProjects; }