Search in sources :

Example 66 with IErlElement

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

the class OpenEdocInExternalBrowserAction method run.

/*
     * (non-Javadoc) Method declared on SelectionDispatchAction.
     */
@Override
public void run(final IStructuredSelection selection) {
    if (input != null) {
        final URL url = input.getDocumentationURL();
        if (url != null) {
            open(url);
        }
        return;
    }
    if (!canEnableFor(selection)) {
        return;
    }
    final IErlElement element = (IErlElement) selection.getFirstElement();
    run(element);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) URL(java.net.URL)

Example 67 with IErlElement

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

the class ErlangExternalsContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement0) {
    Object parentElement = parentElement0;
    try {
        if (parentElement instanceof IProject) {
            final IProject project = (IProject) parentElement;
            if (project.isOpen()) {
                parentElement = ErlangEngine.getInstance().getModel().findProject(project);
            }
        }
        if (parentElement instanceof IErlModule) {
            return erlangFileContentProvider.getChildren(parentElement);
        }
        if (parentElement instanceof IParent) {
            if (parentElement instanceof IOpenable) {
                final IOpenable openable = (IOpenable) parentElement;
                openable.open(null);
            }
            final IParent parent = (IParent) parentElement;
            final Collection<IErlElement> children = parent.getChildrenOfKind(ErlElementKind.EXTERNAL_ROOT, ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER);
            return children.toArray();
        }
    } catch (final ErlModelException e) {
    }
    return ErlangExternalsContentProvider.NO_CHILDREN;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IProject(org.eclipse.core.resources.IProject)

Example 68 with IErlElement

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

the class ErlangExternalsContentProvider method getParent.

@Override
public Object getParent(final Object element) {
    if (element instanceof IErlElement) {
        final IErlElement elt = (IErlElement) element;
        IParent parent = elt.getParent();
        final String filePath = elt.getFilePath();
        if (parent == ErlangEngine.getInstance().getModel() && filePath != null) {
            parent = elt.getParent();
        }
        if (parent instanceof IErlModule) {
            final IErlModule mod = (IErlModule) parent;
            final IResource resource = mod.getCorrespondingResource();
            if (resource != null) {
                return resource;
            }
        } else {
            return parent;
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule) IResource(org.eclipse.core.resources.IResource)

Example 69 with IErlElement

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

the class ErlangFileContentProvider method getChildren.

/**
 * Return the model elements for a *.erl IFile or NO_CHILDREN for otherwise.
 */
@Override
public Object[] getChildren(final Object parentElement0) {
    Object parentElement = parentElement0;
    try {
        if (parentElement instanceof IFile) {
            parentElement = ErlangEngine.getInstance().getModel().findModule((IFile) parentElement);
        }
        if (parentElement instanceof IOpenable) {
            final IOpenable openable = (IOpenable) parentElement;
            openable.open(null);
        }
        if (parentElement instanceof IParent) {
            final IParent parent = (IParent) parentElement;
            final Collection<IErlElement> children = parent.getChildren();
            return children.toArray();
        }
    } catch (final ErlModelException e) {
        ErlLogger.warn(e);
    }
    return ErlangFileContentProvider.NO_CHILDREN;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IOpenable(org.erlide.engine.model.root.IOpenable) IFile(org.eclipse.core.resources.IFile) IParent(org.erlide.engine.model.IParent) ErlModelException(org.erlide.engine.model.ErlModelException)

Example 70 with IErlElement

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

the class SearchUtil method getSearchPatternFromOpenResultAndLimitTo.

public static ErlangSearchPattern getSearchPatternFromOpenResultAndLimitTo(final IErlModule module, final int offset, final OpenResult res, final LimitTo limitTo, final boolean matchAnyFunctionDefinition) throws ErlModelException {
    if (res == null) {
        return null;
    }
    if (res.isLocalCall()) {
        String moduleName;
        if (module != null) {
            moduleName = module.getModuleName();
            if (offset != -1) {
                final IErlElement e = module.getElementAt(offset);
                if (new OpenUtils().isTypeDefOrRecordDef(e, res)) {
                    return new TypeRefPattern(moduleName, res.getFun(), limitTo);
                }
            }
        } else {
            moduleName = res.getName();
        }
        return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, true);
    }
    String moduleName = res.getName();
    if (moduleName == null) {
        return null;
    }
    final String unquoted = StringUtils.unquote(moduleName);
    if (res.isExternalCall()) {
        if (module != null && offset != -1) {
            final IErlElement e = module.getElementAt(offset);
            if (e != null && (e.getKind() == ErlElementKind.TYPESPEC || e.getKind() == ErlElementKind.RECORD_DEF)) {
                return new TypeRefPattern(moduleName, res.getFun(), limitTo);
            }
        }
        String oldName;
        moduleName = unquoted;
        do {
            oldName = moduleName;
            moduleName = ErlangEngine.getInstance().getModelFindService().resolveMacroValue(moduleName, module);
        } while (!moduleName.equals(oldName));
        return new FunctionPattern(moduleName, res.getFun(), res.getArity(), limitTo, matchAnyFunctionDefinition, module, false);
    } else if (res.isMacro()) {
        return new MacroPattern(unquoted, limitTo);
    } else if (res.isRecord()) {
        return new RecordPattern(unquoted, limitTo);
    } else if (res.isInclude()) {
        return new IncludePattern(moduleName, limitTo);
    } else if (res.isVariable()) {
        if (module != null) {
            if (offset != -1) {
                final IErlElement e = module.getElementAt(offset);
                if (e instanceof IErlFunctionClause) {
                    final IErlFunctionClause c = (IErlFunctionClause) e;
                    return new VariablePattern(c.getFunctionName(), c.getArity(), c.getHead(), res.getName(), limitTo, module);
                }
            }
        }
    } else if (res.isField()) {
        return new RecordFieldPattern(res.getFun(), unquoted, limitTo);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) TypeRefPattern(org.erlide.engine.services.search.TypeRefPattern) FunctionPattern(org.erlide.engine.services.search.FunctionPattern) VariablePattern(org.erlide.engine.services.search.VariablePattern) IncludePattern(org.erlide.engine.services.search.IncludePattern) OpenUtils(org.erlide.ui.actions.OpenUtils) RecordPattern(org.erlide.engine.services.search.RecordPattern) RecordFieldPattern(org.erlide.engine.services.search.RecordFieldPattern) MacroPattern(org.erlide.engine.services.search.MacroPattern) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlElement (org.erlide.engine.model.IErlElement)123 Test (org.junit.Test)36 IErlModule (org.erlide.engine.model.root.IErlModule)35 ErlModelException (org.erlide.engine.model.ErlModelException)28 IParent (org.erlide.engine.model.IParent)17 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)12 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)11 IResource (org.eclipse.core.resources.IResource)11 IErlProject (org.erlide.engine.model.root.IErlProject)10 IOpenable (org.erlide.engine.model.root.IOpenable)10 IProject (org.eclipse.core.resources.IProject)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 IErlModel (org.erlide.engine.model.root.IErlModel)8 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 IFolder (org.eclipse.core.resources.IFolder)7 CoreException (org.eclipse.core.runtime.CoreException)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)6