use of org.erlide.engine.model.IErlElement 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);
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class EditorUtility method isOpenInEditor.
/**
* Tests if a CU is currently shown in an editor
*
* @return the IEditorPart if shown, null if element is not open in an
* editor
*/
public static IEditorPart isOpenInEditor(final Object inputElement) {
final Collection<IEditorPart> allErlangEditors = EditorUtility.getAllErlangEditors();
for (final IEditorPart editorPart : allErlangEditors) {
if (inputElement instanceof IErlElement) {
final IErlElement element = (IErlElement) inputElement;
final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(element);
final AbstractErlangEditor editor = (AbstractErlangEditor) editorPart;
if (module.equals(editor.getModule())) {
return editorPart;
}
}
}
final IEditorInput input = EditorUtility.getEditorInput(inputElement);
if (input != null) {
for (final IEditorPart editorPart : allErlangEditors) {
if (editorPart.getEditorInput().equals(input)) {
return editorPart;
}
}
}
return null;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class SearchUtil method getSelectionScopeDescription.
public static String getSelectionScopeDescription(final ISelection selection) {
if (selection instanceof IStructuredSelection) {
final StringBuilder sb = new StringBuilder();
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
int i = 0;
final List<?> list = structuredSelection.toList();
if (list.isEmpty()) {
return "";
}
for (final Object o : list) {
String name;
if (o instanceof IResource) {
final IResource resource = (IResource) o;
name = resource.getName();
} else if (o instanceof IErlElement) {
final IErlElement element = (IErlElement) o;
name = element.getName();
} else {
continue;
}
sb.append('\'').append(name).append("', ");
i++;
if (i == 2) {
break;
}
}
if (structuredSelection.size() > 2) {
return sb.append("...").toString();
}
return sb.substring(0, sb.length() - 2);
}
return "";
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class WranglerUtils method notifyErlide.
/**
* Notifies Erlide about the changed files.
*
* @param changedFiles
* changed files
*/
public static void notifyErlide(final List<ChangedFile> changedFiles) {
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final ChangedFile f : changedFiles) {
IFile file;
try {
file = WranglerUtils.getFileFromPath(f.getNewPath());
final IErlElement element = model.findElement(file);
final IErlModule m = (IErlModule) element;
m.resourceChanged(null);
final IEditorPart editor = GlobalParameters.getEditor();
if (editor instanceof ErlangEditor) {
((ErlangEditor) editor).resetAndCacheScannerAndParser();
}
model.notifyChange(m);
} catch (final Exception e) {
ErlLogger.error(e);
}
}
}
use of org.erlide.engine.model.IErlElement 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;
}
}
Aggregations