Example usage for org.eclipse.jdt.core JavaCore addJavaElementMarkerAttributes

List of usage examples for org.eclipse.jdt.core JavaCore addJavaElementMarkerAttributes

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore addJavaElementMarkerAttributes.

Prototype

public static void addJavaElementMarkerAttributes(Map attributes, IJavaElement element) 

Source Link

Document

Configures the given marker attribute map for the given Java element.

Usage

From source file:ca.uvic.chisel.javasketch.ui.internal.MarkTypeJob.java

License:Open Source License

@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
    try {//  ww  w.  j a v a2s.  c  o  m
        monitor.beginTask("Marking Touched Locations", IProgressMonitor.UNKNOWN);

        IResource resource = typeRoot.getCorrespondingResource();
        if (resource == null) {
            IType type = typeRoot.findPrimaryType();
            if (type != null) {
                ICompilationUnit unit = type.getCompilationUnit();
                if (unit != null) {
                    resource = unit.getResource();
                }
            }
        }
        if (resource == null) {
            resource = ResourcesPlugin.getWorkspace().getRoot();
        }
        deleteMarkers(resource, typeRoot);

        IProgramSketch active = SketchPlugin.getDefault().getActiveSketch();
        if (active == null) {
            return Status.OK_STATUS;
        }

        if (resource.getLocalTimeStamp() > active.getTraceData().getTraceTime().getTime()) {
            //no point in trying to look it up if it has changed recently.
            return Status.OK_STATUS;
        }
        PreparedStatement s = active.getPortal().prepareStatement(
                "SELECT * FROM Activation LEFT OUTER JOIN Message ON Message.activation_id = Activation.model_id WHERE Activation.type_name LIKE ? AND "
                        + "(Message.kind IN ('CALL', 'REPLY', 'THROW'))");
        for (IJavaElement child : typeRoot.getChildren()) {
            if (!(child instanceof IType)) {
                continue;
            }
            IType type = (IType) child;
            String qualifiedName = type.getFullyQualifiedName() + '%';
            s.setString(1, qualifiedName);
            ResultSet results = s.executeQuery();
            TreeSet<Integer> codeLines = new TreeSet<Integer>();
            while (results.next()) {
                //create a new marker
                Object codeLine = results.getObject("CODE_LINE");
                if (codeLine instanceof Integer) {
                    codeLines.add((Integer) codeLine);
                }

            }
            for (Integer line : codeLines) {
                if (line > 0) {
                    Map<Object, Object> attributes = new HashMap<Object, Object>();
                    JavaCore.addJavaElementMarkerAttributes(attributes, typeRoot);
                    attributes.put(IMarker.LINE_NUMBER, line);
                    MarkerUtilities.createMarker(resource, attributes,
                            "ca.uvic.chisel.javasketch.markers.touched");
                }
            }
        }
    } catch (Exception e) {
        SketchPlugin.getDefault().log(e);
        return SketchPlugin.getDefault().createStatus(e);

    } finally {
        monitor.done();
    }
    return Status.OK_STATUS;
}

From source file:com.android.ide.eclipse.cheatsheets.actions.SetBreakpoint.java

License:Open Source License

public void run(final String[] params, ICheatSheetManager manager) {
    // param1 - project
    // param2 - path
    // param3 - type name
    // param4 - line number
    if (params == null || params[0] == null || params[1] == null || params[2] == null || params[3] == null) {
        return;//from w ww. ja  v  a2s.c  o m
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    IProject project = workspaceRoot.getProject(params[0]);
    if (project == null || !project.isOpen()) {
        Activator.log("Invalid the project " + params[0] + ".");
        return;
    }
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null || !javaProject.isOpen()) {
        Activator.log("Invalid the project: " + params[0] + ".");
        return;
    }
    IJavaElement element;
    try {
        element = javaProject.findElement(new Path(params[1]));

        if (element == null) {
            Activator.log("Invalid the path: " + params[1] + ".");
            return;
        }
        resource = element.getCorrespondingResource();
        if (resource == null || resource.getType() != IResource.FILE) {
            Activator.log("Invalid the path: " + params[1] + ".");
            return;
        }
    } catch (JavaModelException e1) {
        Activator.log("Invalid the " + params[1] + " path.");
        return;
    }
    String tname = params[2];
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            editor = openEditor(params, (IFile) resource);
        }
    });
    if (editor == null) {
        Activator.log("Cannot open the " + " " + params[0] + "file.");
        return;
    }
    try {
        //String markerType = "org.eclipse.jdt.debug.javaLineBreakpointMarker";
        int lnumber;
        try {
            lnumber = new Integer(params[3]).intValue();
        } catch (NumberFormatException e) {
            Activator.log("Invalid line number " + params[1]);
            return;
        }
        Map attributes = new HashMap(10);
        IDocumentProvider documentProvider = editor.getDocumentProvider();
        if (documentProvider == null) {
            return;
        }
        IDocument document = documentProvider.getDocument(editor.getEditorInput());
        int charstart = -1, charend = -1;
        try {
            IRegion line = document.getLineInformation(lnumber - 1);
            charstart = line.getOffset();
            charend = charstart + line.getLength();
        } catch (BadLocationException e) {
            Activator.log(e);
        }
        //BreakpointUtils.addJavaBreakpointAttributes(attributes, type);

        String handleId = element.getHandleIdentifier();
        attributes.put(HANDLE_ID, handleId);
        JavaCore.addJavaElementMarkerAttributes(attributes, element);
        IJavaLineBreakpoint breakpoint = JDIDebugModel.createLineBreakpoint(resource, tname, lnumber, charstart,
                charend, 0, true, attributes);

        IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
        breakpointManager.addBreakpoint(breakpoint);
    } catch (CoreException e) {
        Activator.log(e);
    }
}