Example usage for org.aspectj.bridge ISourceLocation getEndLine

List of usage examples for org.aspectj.bridge ISourceLocation getEndLine

Introduction

In this page you can find the example usage for org.aspectj.bridge ISourceLocation getEndLine.

Prototype

int getEndLine();

Source Link

Usage

From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java

License:Open Source License

/**
 * find out what java elements are on a particular line
 *///from  w  ww  .  ja v a2  s . c o m
public List/*IJavaElement*/<IJavaElement> getJavaElementsForLine(ICompilationUnit icu, final int line) {
    IProgramElement ipe = javaElementToProgramElement(icu);
    final List/*IProgramElement*/<IProgramElement> elementsOnLine = new LinkedList<IProgramElement>();

    // walk the program element to get all ipes on the source line
    ipe.walk(new CancellableHierarchyWalker() {
        protected void preProcess(IProgramElement node) {
            ISourceLocation sourceLocation = node.getSourceLocation();
            if (sourceLocation != null) {
                if (sourceLocation.getEndLine() < line) {
                    // we don't need to explore the rest of this branch
                    cancel();
                } else if (sourceLocation.getLine() == line) {
                    elementsOnLine.add(node);
                }
            }
        }
    });
    // now convert to IJavaElements
    List /*IJavaElement*/<IJavaElement> javaElements = new ArrayList<IJavaElement>(elementsOnLine.size());
    for (Iterator<IProgramElement> ipeIter = elementsOnLine.iterator(); ipeIter.hasNext();) {
        IProgramElement ipeOnLine = ipeIter.next();
        javaElements.add(programElementToJavaElement(ipeOnLine));
    }
    return javaElements;
}

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 w  w w  .ja v  a 2 s. co 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();
        }
    }
}