Search in sources :

Example 61 with IErlElement

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

the class SimpleCodeInspectionHandler method handleLargeModulesCall.

private void handleLargeModulesCall(final IErlSelection wranglerSelection, final Shell shell) {
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
    final InputDialog dialog = new InputDialog(shell, "Lines of a large module", "Lines of a large module:", "", new IntegerInputValidator());
    final int ret = dialog.open();
    if (ret == Window.CANCEL) {
        return;
    }
    final int lines = Integer.parseInt(dialog.getValue());
    final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("large_modules_eclipse", "ixi", lines, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
    ArrayList<IErlElement> modules = new ArrayList<>();
    try {
        final OtpErlangObject obj = res.getValue();
        final OtpErlangTuple restuple = (OtpErlangTuple) obj;
        final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
        if ("ok".equals(resindicator.atomValue())) {
            final OtpErlangList modList = (OtpErlangList) restuple.elementAt(1);
            modules = createErlModuleList(modList);
        } else {
            final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
            MessageDialog.openError(shell, "Error", s.stringValue());
            return;
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    if (!modules.isEmpty()) {
        CodeInspectionViewsManager.showErlElements("Large modules", modules, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
    } else {
        MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcResult(org.erlide.runtime.rpc.RpcResult) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) 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) IErlElement(org.erlide.engine.model.IErlElement) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 62 with IErlElement

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

the class SimpleCodeInspectionHandler method handleNonTailRecursiveCall.

private void handleNonTailRecursiveCall(final IErlSelection wranglerSelection, final Shell shell) {
    CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NON_TAIL_RECURSIVE_VIEW_ID);
    try {
        final String inFile = "non_tail_recursive_servers_in_file_eclipse";
        final String inProject = "non_tail_recursive_servers_in_dirs_eclipse";
        final Boolean answer = MessageDialog.openQuestion(shell, "Find non tail recursive servers", "Would you like to run the scan in the whole project?");
        String function = "";
        RpcResult res = null;
        if (!answer) {
            function = inFile;
            res = WranglerBackendManager.getRefactoringBackend().callInspection(function, "sxi", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        } else {
            function = inProject;
            res = WranglerBackendManager.getRefactoringBackend().callInspection(function, "xi", wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        }
        final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
        if (elements == null) {
            return;
        }
        if (!elements.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Non tail recursive servers", elements, SimpleCodeInspectionHandler.NON_TAIL_RECURSIVE_VIEW_ID);
        } else {
            MessageDialog.openInformation(shell, "No result", "Could not found any non tail recursive server!");
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) 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)

Example 63 with IErlElement

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

the class DefaultErlangFoldingStructureProvider method computeAdditions.

private void computeAdditions(final Collection<? extends IErlElement> elements, final Map<ErlangProjectionAnnotation, Position> map) throws ErlModelException {
    if (elements == null) {
        return;
    }
    for (final IErlElement element : elements) {
        computeAdditions(element, map);
        if (element instanceof IParent) {
            final IParent parent = (IParent) element;
            computeAdditions(parent.getChildren(), map);
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IParent(org.erlide.engine.model.IParent)

Example 64 with IErlElement

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

the class EditorUtility method openInEditor.

/**
 * Opens an Erlang editor for an element (IErlElement, IFile, IStorage...)
 *
 * @return the IEditorPart or null if wrong element type or opening failed
 */
public static IEditorPart openInEditor(final Object inputElement, final boolean activate) throws PartInitException {
    final IEditorInput input = EditorUtility.getEditorInput(inputElement);
    if (input == null) {
        return null;
    }
    final IEditorPart editorPart = EditorUtility.openInEditor(input, EditorUtility.getEditorID(input, inputElement), activate);
    if (editorPart != null && inputElement instanceof IErlElement) {
        EditorUtility.revealInEditor(editorPart, (IErlElement) inputElement);
        return editorPart;
    }
    if (inputElement instanceof IFile) {
        return EditorUtility.openInEditor((IFile) inputElement, activate);
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Example 65 with IErlElement

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

the class EditorUtility method getEditorInput.

private static IEditorInput getEditorInput(final IErlElement element0) {
    IErlElement element = element0;
    final IResource resource = element.getResource();
    if (resource instanceof IFile) {
        IFile file = (IFile) resource;
        file = EditorUtility.resolveFile(file);
        return new FileEditorInput(file);
    }
    String filePath = element.getFilePath();
    while (filePath == null) {
        final IParent parent = element.getParent();
        if (parent instanceof IErlElement) {
            element = (IErlElement) parent;
            filePath = element.getFilePath();
        } else {
            break;
        }
    }
    if (filePath != null) {
        final IPath path = new Path(filePath);
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(path.removeLastSegments(1));
        fileStore = fileStore.getChild(path.lastSegment());
        final IFileInfo fetchInfo = fileStore.fetchInfo();
        if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
            if (element instanceof IErlModule && element.getParent() instanceof IErlExternal) {
                return new ErlangExternalEditorInput(fileStore, (IErlModule) element);
            }
            return new FileStoreEditorInput(fileStore);
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IParent(org.erlide.engine.model.IParent) IErlElement(org.erlide.engine.model.IErlElement) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IErlExternal(org.erlide.engine.model.root.IErlExternal) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IErlModule(org.erlide.engine.model.root.IErlModule) IFileStore(org.eclipse.core.filesystem.IFileStore) IResource(org.eclipse.core.resources.IResource) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

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