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());
}
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());
}
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());
*/
}
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;
}
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;
}
Aggregations