Search in sources :

Example 1 with ErlModelException

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

the class IndexedErlangValue method getVariable.

@Override
public IVariable getVariable(final int offset) throws DebugException {
    String name;
    if (record != null) {
        try {
            final IErlRecordField recordField = (IErlRecordField) record.getChildren().get(offset);
            name = recordField.getFieldName();
        } catch (final ErlModelException e) {
            name = varName + ":" + offset;
        }
    } else {
        name = varName + ":" + offset;
    }
    return new ErlangVariable(getDebugTarget(), name, true, getElementAt(offset), process, moduleName, -1);
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlRecordField(org.erlide.engine.model.erlang.IErlRecordField)

Example 2 with ErlModelException

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

the class ErlProject method buildStructure.

@Override
public boolean buildStructure(final IProgressMonitor pm) throws ErlModelException {
    final IResource r = getCorrespondingResource();
    // check whether the Erlang project can be opened
    if (!(r instanceof IContainer) || !r.isAccessible()) {
        ErlLogger.warn("Project %s has no resources: res:%s acc:%s cont:%s", getName(), r, r == null ? "?" : r.isAccessible(), r instanceof IContainer);
        throw new ErlModelException(new ErlModelStatus(ErlModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
    }
    addConfigurationChangeListeners();
    try {
        final IContainer c = (IContainer) r;
        final IResource[] elems = c.members();
        final List<IErlElement> children = new ArrayList<>(elems.length + 1);
        // ErlLogger.debug(">>adding externals");
        addExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        // ErlLogger.debug(">>adding otp");
        addOtpExternals(children);
        // ErlLogger.debug("childcount %d", children.size());
        final IErlModel model = ErlangEngine.getInstance().getModel();
        for (final IResource element : elems) {
            if (element instanceof IFolder) {
                final IFolder folder = (IFolder) element;
                final IErlFolder erlFolder = (IErlFolder) model.create(folder);
                children.add(erlFolder);
            } else if (element instanceof IFile) {
                final IFile file = (IFile) element;
                if (CommonUtils.isErlangFileContentFileName(file.getName())) {
                    final IErlModule m = (IErlModule) model.create(file);
                    children.add(m);
                }
            }
        }
        setChildren(children);
    } catch (final CoreException e) {
        ErlLogger.error(e);
        setChildren(new ArrayList<IErlModule>());
        return false;
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelStatus(org.erlide.engine.model.ErlModelStatus) ArrayList(java.util.ArrayList) IErlFolder(org.erlide.engine.model.root.IErlFolder) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with ErlModelException

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

the class ErlProject method dispose.

@Override
public void dispose() {
    removeConfigurationChangeListeners();
    clearCaches();
    try {
        accept(new IErlElementVisitor() {

            @Override
            public boolean visit(final IErlElement element) throws ErlModelException {
                element.dispose();
                return false;
            }
        }, EnumSet.of(AcceptFlags.CHILDREN_FIRST, AcceptFlags.LEAFS_ONLY), ErlElementKind.MODULE);
    } catch (final ErlModelException e) {
    }
    super.dispose();
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 4 with ErlModelException

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

the class ErlProject method getExternalModules.

@Override
public Collection<IErlModule> getExternalModules() throws ErlModelException {
    final List<IErlModule> result = Lists.newArrayList();
    accept(new IErlElementVisitor() {

        @Override
        public boolean visit(final IErlElement element) throws ErlModelException {
            final boolean isExternalOrProject = element.getKind() == ErlElementKind.EXTERNAL_ROOT || element.getKind() == ErlElementKind.EXTERNAL_APP || element.getKind() == ErlElementKind.EXTERNAL_FOLDER || element.getKind() == ErlElementKind.PROJECT;
            if (element instanceof IErlModule) {
                final IErlModule module = (IErlModule) element;
                if (module.getAncestorOfKind(ErlElementKind.PROJECT) == ErlProject.this) {
                    result.add(module);
                }
                return false;
            } else if (isExternalOrProject && element instanceof IOpenable) {
                final IOpenable openable = (IOpenable) element;
                openable.open(null);
            }
            return isExternalOrProject;
        }
    }, EnumSet.noneOf(AcceptFlags.class), ErlElementKind.MODULE);
    return result;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementVisitor(org.erlide.engine.model.IErlElementVisitor)

Example 5 with ErlModelException

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

the class SimpleCodeInspectionHandler method processFunctionResult.

private ArrayList<IErlElement> processFunctionResult(final Shell shell, final RpcResult result) throws OtpErlangRangeException {
    final ArrayList<IErlElement> elements = new ArrayList<>();
    final OtpErlangObject obj = result.getValue();
    final OtpErlangTuple restuple = (OtpErlangTuple) obj;
    final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
    if ("ok".equals(resindicator.atomValue())) {
        final OtpErlangList erlangFunctionList = (OtpErlangList) restuple.elementAt(1);
        for (int i = 0; i < erlangFunctionList.arity(); ++i) {
            final OtpErlangTuple fTuple = (OtpErlangTuple) erlangFunctionList.elementAt(i);
            IErlFunctionClause f;
            try {
                f = extractFunction(fTuple);
                elements.add(f);
            } catch (final ErlModelException e) {
            }
        }
    } else {
        final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
        MessageDialog.openError(shell, "Error", s.stringValue());
        return null;
    }
    return elements;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ErlModelException(org.erlide.engine.model.ErlModelException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

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