Search in sources :

Example 26 with IErlElement

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

the class SimpleCodeInspectionHandler method handleNotFlushUnknownMessages.

private void handleNotFlushUnknownMessages(final IErlSelection wranglerSelection, final Shell shell) {
    final String inFile = "not_flush_unknown_messages_in_file_eclipse";
    final String inProject = "not_flush_unknown_messages_in_dirs_eclipse";
    CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NOT_FLUSH_UNKNOWN_MESSAGES);
    final Boolean answer = MessageDialog.openQuestion(shell, "Find incomplete receive patterns", "Would you like to run the scan in the whole project?");
    try {
        RpcResult result = null;
        String function = "";
        if (answer) {
            function = inProject;
            result = WranglerBackendManager.getRefactoringBackend().callInspection(function, "xi", wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        } else {
            function = inFile;
            result = WranglerBackendManager.getRefactoringBackend().callInspection(function, "sxi", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        }
        final ArrayList<IErlElement> elements = processFunctionResult(shell, result);
        if (elements == null) {
            return;
        }
        if (!elements.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Incomplete receive patterns", elements, SimpleCodeInspectionHandler.NOT_FLUSH_UNKNOWN_MESSAGES);
        } else {
            MessageDialog.openInformation(shell, "No result", "Could not found any incomplete receive patterns!");
        }
    } 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 27 with IErlElement

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

the class SimpleCodeInspectionHandler method handleDepenenciesCall.

private void handleDepenenciesCall(final IErlSelection wranglerSelection, final Shell shell) {
    // hiding the views
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.DEPENECIES_1_VIEW_ID);
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.DEPENECIES_2_VIEW_ID);
    // run the rpc
    try {
        final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("dependencies_of_a_module_eclipse", "sx", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath());
        ArrayList<IErlElement> modules1 = new ArrayList<>();
        ArrayList<IErlElement> modules2 = new ArrayList<>();
        final OtpErlangObject obj = res.getValue();
        final OtpErlangTuple restuple = (OtpErlangTuple) obj;
        final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
        if ("ok".equals(resindicator.atomValue())) {
            final OtpErlangTuple listtuple = (OtpErlangTuple) restuple.elementAt(1);
            final OtpErlangList modList1 = (OtpErlangList) listtuple.elementAt(0);
            final OtpErlangList modList2 = (OtpErlangList) listtuple.elementAt(1);
            modules1 = createErlModuleList(modList1);
            modules2 = createErlModuleList(modList2);
        } else {
            final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
            MessageDialog.openError(shell, "Error", s.stringValue());
            return;
        }
        if (!modules1.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Modules which depends on " + wranglerSelection.getErlElement().getAncestorOfKind(ErlElementKind.MODULE).getName(), modules1, SimpleCodeInspectionHandler.DEPENECIES_1_VIEW_ID);
        }
        if (!modules2.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Modules, on which " + wranglerSelection.getErlElement().getAncestorOfKind(ErlElementKind.MODULE).getName() + " depends", modules2, SimpleCodeInspectionHandler.DEPENECIES_2_VIEW_ID);
        } else {
            MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcResult(org.erlide.runtime.rpc.RpcResult) ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) 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) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 28 with IErlElement

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

the class SimpleCodeInspectionHandler method handleNested.

private void handleNested(final IErlSelection wranglerSelection, final Shell shell, final String type) {
    try {
        CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NESTED_EXPRESSIONS + type);
        // call inputdialog
        final InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(shell, "Search for nested expression", "Nest level:", "Search in the project", "", new IntegerInputValidator());
        if (Window.OK == dialog.open()) {
            final int nestedVal = Integer.parseInt(dialog.getValue());
            final boolean inProject = dialog.isCheckBoxChecked();
            RpcResult res = null;
            if (inProject) {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("nested_exprs_in_dirs_eclipse", "iaxi", nestedVal, type, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            } else {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("nested_exprs_in_file_eclipse", "siaxi", wranglerSelection.getFilePath(), nestedVal, type, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            }
            // handle rpc
            final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
            if (elements == null) {
                return;
            }
            // show result
            if (!elements.isEmpty()) {
                CodeInspectionViewsManager.showErlElements("Nested " + type + " expressions", elements, SimpleCodeInspectionHandler.NESTED_EXPRESSIONS + type);
            } else {
                MessageDialog.openInformation(shell, "No result", "Could not found any " + nestedVal + " levels nested " + type + " expression!");
            }
        }
    } 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)

Example 29 with IErlElement

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

the class BreakpointUtils method getElement.

public static IErlElement getElement(final ILineBreakpoint breakpoint) {
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlElement element = model.findElement(breakpoint.getMarker().getResource());
    if (element instanceof IErlModule) {
        final IErlModule m = (IErlModule) element;
        try {
            m.open(null);
            final int lineNumber = breakpoint.getLineNumber();
            return m.getElementAtLine(lineNumber - 1);
        } catch (final Exception e) {
            ErlLogger.warn(e);
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint)

Example 30 with IErlElement

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

the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.

public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
    if (element instanceof IErlFunction) {
        final IErlFunction function = (IErlFunction) element;
        final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
        return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
    } else if (element instanceof IErlMacroDef) {
        final IErlMacroDef m = (IErlMacroDef) element;
        final String unquoted = StringUtils.unquote(m.getDefinedName());
        return new MacroPattern(unquoted, limitTo);
    } else if (element instanceof IErlRecordDef) {
        final IErlRecordDef r = (IErlRecordDef) element;
        final String unquoted = StringUtils.unquote(r.getDefinedName());
        return new RecordPattern(unquoted, limitTo);
    } else if (element instanceof IErlFunctionClause) {
        final IErlFunctionClause clause = (IErlFunctionClause) element;
        return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
    } else if (element instanceof IErlAttribute) {
        final IErlAttribute a = (IErlAttribute) element;
        if (a.getName().startsWith("include")) {
            final String s = Util.stringValue(a.getValue());
            return new IncludePattern(s, limitTo);
        }
    }
    return null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlMacroDef(org.erlide.engine.model.erlang.IErlMacroDef) 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