List of usage examples for org.aspectj.bridge ISourceLocation getColumn
int getColumn();
From source file:org.caesarj.ui.editor.CaesarJContentOutlinePage.java
License:Open Source License
/** * This method is called when the user select a node in the content tree. * It searches the location of this node and opens it in the editor. * /*from w ww . j a v a2 s . c om*/ * @see org.eclipse.jface.viewers.ISelectionChangedListener */ public void selectionChanged(SelectionChangedEvent event) { super.selectionChanged(event); /* ignore the first selection message that comes from initialization */ /* necessary for navigation by crosscutting links */ if (bFirstSelection) { bFirstSelection = false; return; } ISelection selection = event.getSelection(); if (selection.isEmpty()) { } else { Object item = ((IStructuredSelection) selection).getFirstElement(); if (item instanceof LinkNode) { if (((LinkNode) item).getType() == LinkNode.LINK_NODE_RELATIONSHIP) { return; } item = ((LinkNode) item).getTargetElement(); } IProgramElement selectedNode = (IProgramElement) item; ISourceLocation sourceLocation = selectedNode.getSourceLocation(); if (sourceLocation != null) { try { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath path = new Path(sourceLocation.getSourceFile().getAbsolutePath()); IResource resource = root.getFileForLocation(path); IMarker marker; if (resource != null) { marker = resource.createMarker(IMarker.MARKER); marker.setAttribute(IMarker.LINE_NUMBER, sourceLocation.getLine()); marker.setAttribute(IMarker.CHAR_START, sourceLocation.getColumn()); IDE.openEditor( CaesarPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker); } } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java
License:Open Source License
private void showMessages(final IProject project) { // THIS MUST STAY IN A SEPARATE THREAD - This is because we need // to create and setup the marker in an atomic operation. See // AMC or ASC. IWorkspaceRunnable r = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) { try { Iterator<IResource> affectedResourceIterator = affectedResources.iterator(); AJLog.log(AJLog.COMPILER, "Types affected during build = " + affectedResources.size()); //$NON-NLS-1$ IResource ir = null;//from ww w.j a va 2s. c o m while (affectedResourceIterator.hasNext()) { ir = (IResource) affectedResourceIterator.next(); try { if (ir.exists()) { ir.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); ir.deleteMarkers(IAJModelMarker.AJDT_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); ir.deleteMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE); // now removed markers from compilation participants HashSet<String> managedMarkers = JavaModelManager .getJavaModelManager().compilationParticipants.managedMarkerTypes(); for (String managedMarker : managedMarkers) { ir.deleteMarkers(managedMarker, true, IResource.DEPTH_INFINITE); } } } catch (CoreException re) { AJLog.log("Failed marker deletion: resource=" //$NON-NLS-1$ + ir.getLocation()); throw re; } } Iterator<ProblemTracker> problemIterator = problems.iterator(); ProblemTracker p = null; while (problemIterator.hasNext()) { p = (ProblemTracker) problemIterator.next(); ir = null; IMarker marker = null; try { if (p.location != null) { ir = locationToResource(p.location, project); if ((ir != null) && ir.exists()) { // 128803 - only add problems to affected resources if (lastBuildWasFull || affectedResources.contains(ir) || ir.getProject() != project) { int prio = getTaskPriority(p); if (prio != -1) { marker = ir.createMarker(IMarker.TASK); marker.setAttribute(IMarker.PRIORITY, prio); } else { if (p.declaredErrorOrWarning) { marker = ir.createMarker(IAJModelMarker.AJDT_PROBLEM_MARKER); } else { // create Java marker with problem id so // that quick fix is available marker = ir .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttribute(IJavaModelMarker.ID, p.id); } } if ((p.start >= 0) && (p.end >= 0)) { marker.setAttribute(IMarker.CHAR_START, new Integer(p.start)); marker.setAttribute(IMarker.CHAR_END, new Integer(p.end + 1)); } if (!ir.getProject().equals(project)) { addOtherProjectMarker(project, marker); } if (p.location.getLine() > 0) { marker.setAttribute(IMarker.LINE_NUMBER, new Integer(p.location.getLine())); } } else { AJLog.log(AJLog.COMPILER_MESSAGES, "Not adding marker for problem because it's " //$NON-NLS-1$ + "against a resource which is not in the list of affected resources" //$NON-NLS-1$ + " provided by the compiler. Resource=" + ir //$NON-NLS-1$ + " Problem message=" //$NON-NLS-1$ + p.message + " line=" + p.location.getLine()); //$NON-NLS-1$ } } } else { marker = project.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); } if (marker != null) { setSeverity(marker, p.kind); if ((p.extraLocs != null) && (p.extraLocs.size() > 0)) { // multiple // part // message int relCount = 0; for (Iterator<?> iter = p.extraLocs.iterator(); iter.hasNext();) { ISourceLocation sLoc = (ISourceLocation) iter.next(); StringBuffer attrData = new StringBuffer(); attrData.append(sLoc.getSourceFile().getAbsolutePath()); attrData.append(":::"); //$NON-NLS-1$ attrData.append(sLoc.getLine()); attrData.append(":::"); //$NON-NLS-1$ attrData.append(sLoc.getEndLine()); attrData.append(":::"); //$NON-NLS-1$ attrData.append(sLoc.getColumn()); marker.setAttribute( AspectJUIPlugin.RELATED_LOCATIONS_ATTRIBUTE_PREFIX + (relCount++), attrData.toString()); } } setMessage(marker, p.message); } } catch (CoreException re) { AJLog.log("Failed marker creation: resource=" //$NON-NLS-1$ + p.location.getSourceFile().getPath() + " line=" //$NON-NLS-1$ + p.location.getLine() + " message=" + p.message); //$NON-NLS-1$ throw re; } } clearMessages(); } catch (CoreException e) { AJDTErrorHandler.handleAJDTError(UIMessages.CompilerTaskListManager_Error_creating_marker, e); } } }; try { AspectJPlugin.getWorkspace().run(r, null); } catch (CoreException cEx) { AJDTErrorHandler.handleAJDTError(UIMessages.CompilerTaskListManager_Error_adding_problem_markers, cEx); } // Part of the fix for bug 89793 - editor image is not updated Collection<AspectJEditor> activeEditorList = AspectJEditor.getActiveEditorList(); synchronized (activeEditorList) { for (AspectJEditor editor : activeEditorList) { editor.resetTitleImage(); } } }