Search in sources :

Example 56 with IErlElement

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

the class ISourceReferenceTest method getSourceRange.

// ISourceRange getSourceRange() throws ErlModelException;
@Test
public void getSourceRange() throws Exception {
    module.open(null);
    final IErlElement element = module.getElementAtLine(0);
    final ISourceReference sourceReference = (ISourceReference) element;
    final ISourceRange sourceRange = sourceReference.getSourceRange();
    final IErlElement element2 = module.getElementAtLine(1);
    final ISourceReference sourceReference2 = (ISourceReference) element2;
    final ISourceRange sourceRange2 = sourceReference2.getSourceRange();
    assertEquals(0, sourceRange.getOffset());
    assertEquals(13, sourceRange2.getOffset());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) Test(org.junit.Test)

Example 57 with IErlElement

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

the class ParsingTest method parseCompileDirective.

@Test
public void parseCompileDirective() throws ErlModelException {
    final String sourceContent = "[inline,{hipe,[{regalloc,linear_scan}]}]";
    final String source = "-compile(" + sourceContent + ").";
    assertTrue(parse(source));
    final IErlElement attribute = TestingSupport.createErlAttribute(module, "compile", null, sourceContent, 0, 50);
    final List<IErlElement> expected = new ArrayList<>(1);
    expected.add(attribute);
    final Collection<IErlElement> actual = module.getChildren();
    // assertEquals(expected, actual);
    assertEquals(expected.toString(), actual.toString());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with IErlElement

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

the class GlobalParameters method setSelection.

/**
 * Stores a selection marked 'current'
 *
 * @param selection
 *            Erlang selection
 */
public static void setSelection(final ISelection selection) throws WranglerException {
    // TODO:: if the module is selected it is not handled
    try {
        if (GlobalParameters.editor == null) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
        }
        if (selection instanceof ITextSelection) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
            GlobalParameters.wranglerSelection = new ErlTextMemberSelection((ITextSelection) selection, (ITextEditor) GlobalParameters.editor);
        } else if (selection instanceof ITreeSelection) {
            final Object firstElement = ((ITreeSelection) selection).getFirstElement();
            if (firstElement instanceof IErlElement) {
                final IErlElement element = (IErlElement) firstElement;
                final IFile file = (IFile) element.getResource();
                GlobalParameters.wranglerSelection = new ErlMemberSelection(element, file, WranglerUtils.getDocument(file));
            } else if (firstElement instanceof IFile) {
                final IFile file = (IFile) firstElement;
                final IErlModule module = ErlangEngine.getInstance().getModel().findModule(file);
                GlobalParameters.wranglerSelection = new ErlModuleSelection(module, file);
            } else {
                GlobalParameters.wranglerSelection = null;
                throw new WranglerException("Please select an Erlang element!");
            }
        } else {
            GlobalParameters.wranglerSelection = null;
            throw new WranglerException("Please select an Erlang element!");
        }
    } catch (final ClassCastException e) {
        ErlLogger.error(e);
    }
/*
         * System.out.println(wranglerSelection.getStartLine() + "," +
         * wranglerSelection.getStartCol() + ";" +
         * wranglerSelection.getEndLine() + "," +
         * wranglerSelection.getEndCol());
         */
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) ErlTextMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection) ErlModuleSelection(org.erlide.wrangler.refactoring.selection.internal.ErlModuleSelection) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) ITextSelection(org.eclipse.jface.text.ITextSelection) IWorkbench(org.eclipse.ui.IWorkbench) IErlElement(org.erlide.engine.model.IErlElement) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ErlMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlMemberSelection) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 59 with IErlElement

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

the class MoveFunctionDropHandler method validateDrop.

@Override
public IStatus validateDrop(final Object target, final int operation, final TransferData transferType) {
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(transferType);
    final TreeSelection s = (TreeSelection) sel;
    final IErlElement e = (IErlElement) s.getFirstElement();
    if (e instanceof IErlFunctionClause) {
        if (target instanceof IErlElement || target instanceof IFile) {
            return Status.OK_STATUS;
        }
    }
    return Status.CANCEL_STATUS;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 60 with IErlElement

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

the class MoveFunctionDropHandler method handleDrop.

@Override
public IStatus handleDrop(final CommonDropAdapter dropAdapter, final DropTargetEvent dropTargetEvent, final Object target) {
    // get the source data
    final TransferData td = dropAdapter.getCurrentTransfer();
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
    final TreeSelection s = (TreeSelection) sel;
    try {
        GlobalParameters.setSelection(s);
    } catch (final WranglerException e1) {
        e1.printStackTrace();
    }
    // get the target data
    String moduleName;
    IFile file;
    if (target instanceof IFile) {
        file = (IFile) target;
    } else {
        file = (IFile) ((IErlElement) target).getResource();
    }
    moduleName = file.getName();
    moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));
    final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
    refactoring.setUserInput(moduleName);
    final RefactoringWizard wizard = new DefaultWranglerRefactoringWizard(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE, new ArrayList<WranglerPage>());
    final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
    try {
        op.run(shell, refactoring.getName());
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    return Status.OK_STATUS;
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveFunctionRefactoring(org.erlide.wrangler.refactoring.core.internal.MoveFunctionRefactoring) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) IErlElement(org.erlide.engine.model.IErlElement) Shell(org.eclipse.swt.widgets.Shell) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) TransferData(org.eclipse.swt.dnd.TransferData) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) WranglerPage(org.erlide.wrangler.refactoring.ui.wizardpages.WranglerPage)

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