Search in sources :

Example 41 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class ErlangEditor method resetAndCacheScannerAndParser.

public void resetAndCacheScannerAndParser() {
    final IErlModule module = getModule();
    if (module == null) {
        return;
    }
    resetReconciler();
    try {
        module.createScanner();
        module.getScanner().dispose();
        module.resetAndCacheScannerAndParser(getDocument().get());
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 42 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class AbstractErlContentAssistProcessor method getBefore.

String getBefore(final ITextViewer viewer, final IDocument doc, final int offset) {
    try {
        if (module != null) {
            try {
                final IErlElement element = module.getElementAt(offset);
                if (element instanceof ISourceReference) {
                    final ISourceReference sr = (ISourceReference) element;
                    final int start = sr.getSourceRange().getOffset();
                    if (start <= offset) {
                        return doc.get(start, offset - start);
                    }
                }
            } catch (final ErlModelException e) {
            }
        }
        for (int n = offset - 1; n >= 0; --n) {
            final char c = doc.getChar(n);
            final int type = Character.getType(c);
            if (type == Character.LINE_SEPARATOR || type == Character.PARAGRAPH_SEPARATOR || type == Character.CONTROL) {
                return doc.get(n + 1, offset - n - 1);
            }
        }
        return doc.get(0, offset);
    } catch (final BadLocationException e) {
        ErlLogger.warn(e);
    }
    return "";
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 43 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class CallHierarchyAction method run.

@Override
public void run() {
    if (module == null) {
        return;
    }
    final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
    IErlFunction f = null;
    if (el instanceof IErlFunction) {
        f = (IErlFunction) el;
    } else if (el instanceof IErlFunctionClause) {
        f = (IErlFunction) el.getParent();
    }
    if (f == null) {
        return;
    }
    String name = module.getName();
    final int i = name.lastIndexOf('.');
    if (i > 0) {
        name = name.substring(0, i);
    }
    final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
    final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    final IWorkbenchPage page = dw.getActivePage();
    final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {

        @Override
        protected CallHierarchyView prepare() {
            try {
                final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
                final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
                if (cvh == null) {
                    return null;
                }
                cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
                return cvh;
            } catch (final PartInitException e) {
                ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
                return null;
            }
        }

        @Override
        protected RpcFuture call() throws BackendException {
            final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
            return result;
        }

        @Override
        protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
            page.activate(context);
            try {
                context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    };
    ac.run();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) IErlElement(org.erlide.engine.model.IErlElement) CallHierarchyView(org.erlide.ui.views.CallHierarchyView) ErlModelException(org.erlide.engine.model.ErlModelException) AsyncCaller(org.erlide.ui.jinterface.AsyncCaller) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RpcFuture(org.erlide.runtime.rpc.RpcFuture) PartInitException(org.eclipse.ui.PartInitException) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 44 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class IndexedErlangValue method getRecordValueString.

private String getRecordValueString(final IErlRecordDef r, final OtpErlangObject o) {
    final StringBuilder b = new StringBuilder();
    List<IErlElement> children;
    try {
        children = r.getChildren();
    } catch (final ErlModelException e) {
        children = IndexedErlangValue.EMPTY_LIST;
    }
    final OtpErlangTuple t = (OtpErlangTuple) o;
    b.append(t.elementAt(0)).append("#{");
    final int n = children.size();
    if (n > 0) {
        for (int i = 0; i < n; i++) {
            final IErlRecordField field = (IErlRecordField) children.get(i);
            b.append(field.getFieldName()).append('=').append(t.elementAt(i + 1).toString()).append(", ");
        }
        b.setLength(b.length() - 2);
    }
    b.append('}');
    return b.toString();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) IErlRecordField(org.erlide.engine.model.erlang.IErlRecordField)

Example 45 with ErlModelException

use of org.erlide.engine.model.ErlModelException in project erlide_eclipse by erlang.

the class ErlangLineBreakpoint method resetClauseHead.

protected void resetClauseHead(final int lineNumber, final IResource resource) {
    clauseHead = "";
    if (resource instanceof IFile) {
        final IFile file = (IFile) resource;
        final IErlModule m = ErlangEngine.getInstance().getModel().findModule(file);
        if (m != null) {
            try {
                m.open(null);
                final IErlElement e = m.getElementAtLine(lineNumber);
                if (e instanceof IErlFunctionClause) {
                    final IErlFunctionClause clause = (IErlFunctionClause) e;
                    clauseHead = clause.getName() + clause.getHead();
                }
            } catch (final ErlModelException e1) {
                ErlLogger.warn(e1);
            }
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

ErlModelException (org.erlide.engine.model.ErlModelException)45 IErlElement (org.erlide.engine.model.IErlElement)21 IErlModule (org.erlide.engine.model.root.IErlModule)21 IErlModel (org.erlide.engine.model.root.IErlModel)9 IErlProject (org.erlide.engine.model.root.IErlProject)9 ArrayList (java.util.ArrayList)8 IOpenable (org.erlide.engine.model.root.IOpenable)7 CoreException (org.eclipse.core.runtime.CoreException)6 IProject (org.eclipse.core.resources.IProject)5 IResource (org.eclipse.core.resources.IResource)5 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)4 IFile (org.eclipse.core.resources.IFile)4 IParent (org.erlide.engine.model.IParent)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 Composite (org.eclipse.swt.widgets.Composite)3 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)3 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2