Search in sources :

Example 16 with ErlModelException

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

the class CompilerPreferencePage method doLinkActivated.

void doLinkActivated(final Link widget) {
    if (isProjectPreferencePage()) {
        openWorkspacePreferences(null);
    } else {
        final List<IProject> erlProjects = new ArrayList<>();
        final Set<IProject> projectsWithSpecifics = new HashSet<>();
        final IErlModel model = ErlangEngine.getInstance().getModel();
        try {
            for (final IErlProject ep : model.getErlangProjects()) {
                final IProject p = ep.getWorkspaceProject();
                if (hasProjectSpecificOptions(p)) {
                    projectsWithSpecifics.add(p);
                }
                erlProjects.add(p);
            }
        } catch (final ErlModelException e) {
        }
        final ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), erlProjects, projectsWithSpecifics);
        if (dialog.open() == Window.OK) {
            final IProject res = (IProject) dialog.getFirstResult();
            openProjectProperties(res);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlModelException(org.erlide.engine.model.ErlModelException) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 17 with ErlModelException

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

the class ErlangAbstractHandler method getTextSelection.

/**
 * Provide the text selection that is needed to execute the command. Default
 * implementation, extend to Erlang elements selected.
 *
 * @param document
 *            text {@link IDocument}
 * @param selection
 *            selection affected by command (extended by extendSelection)
 * @return new {@link ITextSelection} with all text up to selection
 */
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
    if (editor instanceof ErlangEditor) {
        final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
        final IErlModule module = erlangEditor.getModule();
        if (module != null) {
            final int offset1 = selection.getOffset();
            final int offset2 = offset1 + selection.getLength();
            try {
                final IErlElement e1 = module.getElementAt(offset1);
                final IErlElement e2 = module.getElementAt(offset2);
                if (e1 instanceof ISourceReference) {
                    final ISourceReference ref1 = (ISourceReference) e1;
                    final ISourceRange r1 = ref1.getSourceRange();
                    final int offset = r1.getOffset();
                    int length = r1.getLength();
                    if (e1 == e2) {
                        final int docLength = document.getLength();
                        if (offset + length > docLength) {
                            length = docLength - offset;
                        }
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
                    } else if (e2 == null) {
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
                    } else if (e2 instanceof ISourceReference) {
                        final ISourceReference ref2 = (ISourceReference) e2;
                        final ISourceRange r2 = ref2.getSourceRange();
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
                    }
                }
            } catch (final ErlModelException e) {
            }
        }
    }
    return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 18 with ErlModelException

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

the class ErlangExternalEditorInputFactory method createElement.

@Override
public IAdaptable createElement(final IMemento memento) {
    // Get the file name.
    final String externalModulePath = memento.getString(ErlangExternalEditorInputFactory.TAG_EXTERNAL_MODULE_PATH);
    if (externalModulePath == null) {
        return null;
    }
    IErlModule module;
    try {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        module = ErlangEngine.getInstance().getModelUtilService().getModuleFromExternalModulePath(model, externalModulePath);
    } catch (final ErlModelException e1) {
        return null;
    }
    if (module == null) {
        return null;
    }
    // Get the file name.
    final String uriString = memento.getString(ErlangExternalEditorInputFactory.TAG_URI);
    if (uriString == null) {
        return null;
    }
    URI uri;
    try {
        uri = new URI(uriString);
    } catch (final URISyntaxException e) {
        return null;
    }
    try {
        return new ErlangExternalEditorInput(EFS.getStore(uri), module);
    } catch (final CoreException e) {
        return null;
    }
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 19 with ErlModelException

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

the class RemoteFunctionClauseDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    final Tree functionClausesTree;
    final Label label = new Label(composite, SWT.WRAP);
    label.setText("Please select the function clause which against should fold!");
    final GridData minToksData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    minToksData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    label.setLayoutData(minToksData);
    label.setFont(parent.getFont());
    functionClausesTree = new Tree(composite, SWT.BORDER);
    final GridData treeData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    treeData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
    functionClausesTree.setLayoutData(treeData);
    try {
        final Collection<IErlModule> erlmodules = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getModules();
        for (final IErlModule m : erlmodules) {
            // must refresh the scanner!
            m.open(null);
            final TreeItem moduleName = new TreeItem(functionClausesTree, 0);
            moduleName.setText(m.getModuleName());
            moduleName.setData(m);
            final List<IErlFunction> functions = filterFunctions(m.getChildren());
            for (final IErlFunction f : functions) {
                final TreeItem functionName = new TreeItem(moduleName, 0);
                functionName.setText(f.getNameWithArity());
                final List<IErlFunctionClause> clauses = filterClauses(f.getChildren());
                functionName.setData(f);
                for (final IErlFunctionClause c : clauses) {
                    final TreeItem clauseName = new TreeItem(functionName, 0);
                    clauseName.setText(String.valueOf(c.getName()));
                    clauseName.setData(c);
                }
            }
        }
        // listen to treeitem selection
        functionClausesTree.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent e) {
            }

            // if a function or a function clause is selected, then
            // highlight it
            // and store the selection
            @Override
            public void widgetSelected(final SelectionEvent e) {
                final TreeItem[] selectedItems = functionClausesTree.getSelection();
                if (selectedItems.length > 0) {
                    final TreeItem treeItem = selectedItems[0];
                    final Object data = treeItem.getData();
                    if (data instanceof IErlFunctionClause) {
                        // enable the ok button
                        okButton.setEnabled(true);
                        // highlight
                        WranglerUtils.highlightSelection((IErlFunctionClause) data);
                        // store
                        functionClause = (IErlFunctionClause) data;
                    } else {
                        okButton.setEnabled(false);
                    }
                }
            }
        });
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
    applyDialogFont(composite);
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) Label(org.eclipse.swt.widgets.Label) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) ErlModelException(org.erlide.engine.model.ErlModelException) GridData(org.eclipse.swt.layout.GridData) IErlModule(org.erlide.engine.model.root.IErlModule) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 20 with ErlModelException

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

the class AddRefacHandler method checkType.

// check if the refactoring is elementary or composite
private RefacType checkType(final String callbackModule) {
    try {
        final IErlModule module = ErlangEngine.getInstance().getModel().findModule(callbackModule);
        final ScannerService scanner = module.getScanner();
        try {
            module.resetAndCacheScannerAndParser(null);
        } finally {
            scanner.dispose();
        }
        for (final IErlElement el : module.getChildrenOfKind(ErlElementKind.ATTRIBUTE)) {
            final IErlAttribute attr = (IErlAttribute) el;
            if ("behaviour".equals(attr.getName()) || "behavior".equals(attr.getName())) {
                if (attr.getValue().toString().contains("gen_refac")) {
                    return RefacType.ELEMENTARY;
                } else if (attr.getValue().toString().contains("gen_composite_refac")) {
                    return RefacType.COMPOSITE;
                }
            }
        }
        return null;
    } catch (final ErlModelException e) {
        return null;
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ScannerService(org.erlide.engine.services.parsing.ScannerService)

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