Search in sources :

Example 21 with IErlElement

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

the class ModelInternalUtils method getExternalModulePath.

@Override
public String getExternalModulePath(final IErlElementLocator model, final IErlModule module) {
    final List<String> result = Lists.newArrayList();
    IErlElement element = module;
    while (element != model) {
        if (element instanceof IErlExternal) {
            final IErlExternal external = (IErlExternal) element;
            result.add(external.getName());
        } else {
            result.add(element.getName());
        }
        element = (IErlElement) element.getParent();
    }
    return Joiner.on(ModelInternalUtils.DELIMITER).join(Lists.reverse(result));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlExternal(org.erlide.engine.model.root.IErlExternal)

Example 22 with IErlElement

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

the class ErlElement method closing.

/**
 * This element is being closed. Do any necessary cleanup.
 *
 * @throws ErlModelException
 */
protected void closing(final Object info) throws ErlModelException {
    for (final IErlElement e : getChildren()) {
        if (e instanceof ErlElement) {
            final ErlElement ee = (ErlElement) e;
            ee.closing(info);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlElement(org.erlide.engine.model.IErlElement)

Example 23 with IErlElement

use of org.erlide.engine.model.IErlElement 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)

Example 24 with IErlElement

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

the class SimpleCodeInspectionHandler method createErlModuleList.

private ArrayList<IErlElement> createErlModuleList(final OtpErlangList modList) {
    final ArrayList<IErlElement> modules = new ArrayList<>();
    for (int i = 0; i < modList.arity(); ++i) {
        IErlModule m;
        try {
            m = extractModule(modList.elementAt(i));
            modules.add(m);
        } catch (final ErlModelException e) {
        }
    }
    return modules;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 25 with IErlElement

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

the class SimpleCodeInspectionHandler method handleLongFunctions.

private void handleLongFunctions(final IErlSelection wranglerSelection, final Shell shell) {
    try {
        CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.LONG_FUNCTIONS);
        // call inputdialog
        final InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(shell, "Search for long functions", "Number of lines:", "Search in the project", "", new IntegerInputValidator());
        if (Window.OK == dialog.open()) {
            final int linesVal = Integer.parseInt(dialog.getValue());
            final boolean inProject = dialog.isCheckBoxChecked();
            RpcResult res = null;
            if (inProject) {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("long_functions_in_dirs_eclipse", "ixi", linesVal, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            } else {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("long_functions_in_file_eclipse", "sixi", wranglerSelection.getFilePath(), linesVal, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            }
            // handle rpc
            final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
            if (elements == null) {
                return;
            }
            // show result
            if (!elements.isEmpty()) {
                CodeInspectionViewsManager.showErlElements("Long functions", elements, SimpleCodeInspectionHandler.LONG_FUNCTIONS);
            } else {
                MessageDialog.openInformation(shell, "No result", "Could not found any function which is longer, than " + linesVal + " lines.");
            }
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : InputDialogWithCheckbox(org.erlide.wrangler.refactoring.codeinspection.ui.InputDialogWithCheckbox) IErlElement(org.erlide.engine.model.IErlElement) RpcResult(org.erlide.runtime.rpc.RpcResult) ErlModelException(org.erlide.engine.model.ErlModelException) ExecutionException(org.eclipse.core.commands.ExecutionException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException)

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