Search in sources :

Example 1 with JimpleEditor

use of ca.mcgill.sable.soot.editors.JimpleEditor in project soot by Sable.

the class SootAttributeSelectAction method handleSelection.

public void handleSelection(String selected, ArrayList links) {
    if (selected == null)
        return;
    try {
        int toShow = 0;
        String className;
        Iterator it = links.iterator();
        while (it.hasNext()) {
            LinkAttribute la = (LinkAttribute) it.next();
            if (la.getLabel().equals(selected)) {
                // .getJimpleLink() - 1;
                toShow = getLinkLine(la) - 1;
                className = la.getClassName();
                findClass(className);
            }
        }
        int selOffset = getLinkToEditor().getDocumentProvider().getDocument(getLinkToEditor().getEditorInput()).getLineOffset(toShow);
        if ((selOffset != -1) && (selOffset != 0)) {
            if (getLinkToEditor() instanceof JimpleEditor) {
                ((JimpleEditor) getLinkToEditor()).getViewer().setRangeIndication(selOffset, 1, true);
                SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(getLinkToEditor());
            } else {
                SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(getLinkToEditor());
                ((AbstractTextEditor) SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).selectAndReveal(selOffset, 0);
                ((AbstractTextEditor) SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).setHighlightRange(selOffset, 1, true);
            }
        }
    } catch (BadLocationException e) {
        System.out.println(e.getMessage());
    }
}
Also used : Iterator(java.util.Iterator) JimpleEditor(ca.mcgill.sable.soot.editors.JimpleEditor)

Example 2 with JimpleEditor

use of ca.mcgill.sable.soot.editors.JimpleEditor in project soot by Sable.

the class SootAttributeSelectAction method run.

public void run() {
    // need to get list of texts
    IAnnotationModel model = getEditor().getDocumentProvider().getAnnotationModel(getEditor().getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel) {
        setModel((AbstractMarkerAnnotationModel) model);
    }
    int markerLine = getRulerInfo().getLineOfLastMouseButtonActivity();
    IResource rec = getResource(getEditor());
    try {
        IMarker[] markers = rec.findMarkers("ca.mcgill.sable.soot.sootattributemarker", true, IResource.DEPTH_INFINITE);
        for (int i = 0; i < markers.length; i++) {
            if (getModel().getMarkerPosition(markers[i]) == null)
                continue;
            setLineNumber(getDocument().getLineOfOffset(getModel().getMarkerPosition(markers[i]).getOffset()));
            if (getLineNumber() == markerLine) {
                ArrayList links = getMarkerLinks();
                Iterator lit = links.iterator();
                String[] list = getMarkerLabels(links);
                if ((list == null) || (list.length == 0)) {
                // show no links
                } else {
                    IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getWorkbenchWindow();
                    PopupListSelector popup = new PopupListSelector(window.getShell());
                    popup.setItems(list);
                    int listWidth = getListWidth(list);
                    if (getEditor() instanceof JimpleEditor) {
                        int topIndex = ((JimpleEditor) getEditor()).getViewer().getTopIndex();
                        Rectangle rect = new Rectangle(320, (getLineNumber() + 1 - topIndex), listWidth, 45);
                        popup.open(rect);
                    } else {
                        int topIndex = ((ITextViewer) ((AbstractTextEditor) getEditor()).getAdapter(ITextOperationTarget.class)).getTopIndex();
                        int pos = getModel().getMarkerPosition(markers[i]).getOffset();
                        pos = pos / getLineNumber();
                        Rectangle rect = new Rectangle(320, getLineNumber() + 1 - topIndex, listWidth, 45);
                        popup.open(rect);
                    }
                    handleSelection(popup.getSelected(), links);
                }
            }
        }
    } catch (CoreException e) {
    } catch (BadLocationException e1) {
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PopupListSelector(ca.mcgill.sable.soot.ui.PopupListSelector) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) JimpleEditor(ca.mcgill.sable.soot.editors.JimpleEditor) Iterator(java.util.Iterator)

Example 3 with JimpleEditor

use of ca.mcgill.sable.soot.editors.JimpleEditor in project soot by Sable.

the class SootPartManager method updatePart.

public void updatePart(IEditorPart part) {
    if (part == null)
        return;
    if (part instanceof JimpleEditor) {
        AbstractAttributesComputer aac = new JimpleAttributesComputer();
        SootAttributesJimpleColorer sajc = new SootAttributesJimpleColorer();
        SootAttrJimpleIconGenerator saji = new SootAttrJimpleIconGenerator();
        SourceViewer viewer = (SourceViewer) ((AbstractTextEditor) part).getAdapter(ITextOperationTarget.class);
        SootAttributesHandler handler = aac.getAttributesHandler((AbstractTextEditor) part);
        if (handler != null) {
            if (isUpdateForOpen() || handler.isUpdate()) {
                sajc.setEditorPart(part);
                sajc.setViewer(viewer);
                sajc.setHandler(handler);
                Thread cThread = new Thread(sajc);
                cThread.start();
                saji.setHandler(handler);
                saji.setRec((IFile) aac.getRec());
                Thread iThread = new Thread(saji);
                iThread.start();
                handler.setUpdate(false);
            }
        }
        handleKeys(handler);
        handleTypes(handler, (IFile) aac.getRec());
    } else if (part instanceof AbstractTextEditor) {
        IEditorInput input = ((AbstractTextEditor) part).getEditorInput();
        IJavaElement jElem = (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class);
        if (!(jElem instanceof ICompilationUnit))
            return;
        AbstractAttributesComputer aac = new JavaAttributesComputer();
        SootAttributesJavaColorer sajc = new SootAttributesJavaColorer();
        SootAttrJavaIconGenerator saji = new SootAttrJavaIconGenerator();
        SourceViewer viewer = (SourceViewer) ((AbstractTextEditor) part).getAdapter(ITextOperationTarget.class);
        SootAttributesHandler handler = aac.getAttributesHandler((AbstractTextEditor) part);
        if (handler != null) {
            if (isUpdateForOpen() || handler.isUpdate()) {
                sajc.setEditorPart(part);
                sajc.setViewer(viewer);
                sajc.setHandler(handler);
                Thread cThread = new Thread(sajc);
                cThread.start();
                saji.setHandler(handler);
                saji.setRec((IFile) aac.getRec());
                Thread iThread = new Thread(saji);
                iThread.start();
                handler.setUpdate(false);
            }
        }
        handleKeys(handler);
        handleTypes(handler, (IFile) aac.getRec());
    }
    setUpdateForOpen(false);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) SourceViewer(org.eclipse.jface.text.source.SourceViewer) JimpleEditor(ca.mcgill.sable.soot.editors.JimpleEditor) ITextOperationTarget(org.eclipse.jface.text.ITextOperationTarget) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor)

Aggregations

JimpleEditor (ca.mcgill.sable.soot.editors.JimpleEditor)3 Iterator (java.util.Iterator)2 PopupListSelector (ca.mcgill.sable.soot.ui.PopupListSelector)1 ArrayList (java.util.ArrayList)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ITextOperationTarget (org.eclipse.jface.text.ITextOperationTarget)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)1