use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class IErlExportTest method hasFunction.
// public boolean hasFunction(final ErlangFunction f);
@Test
public void hasFunction() throws Exception {
module.open(null);
final List<IErlElement> childrenOfKind = module2.getChildrenOfKind(ErlElementKind.EXPORT);
final IErlElement element = childrenOfKind.get(0);
final IErlExport export = (IErlExport) element;
assertTrue(export.hasFunction(functionA.getFunction()));
assertTrue(export.hasFunction(functionB.getFunction()));
assertFalse(export.hasFunction(functionC.getFunction()));
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlangEditor method computeHighlightRangeSourceReference.
protected ISourceReference computeHighlightRangeSourceReference() {
final ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer == null) {
return null;
}
final StyledText styledText = sourceViewer.getTextWidget();
if (styledText == null) {
return null;
}
int caret = 0;
if (sourceViewer instanceof ITextViewerExtension5) {
final ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
} else {
final int offset = sourceViewer.getVisibleRegion().getOffset();
caret = offset + styledText.getCaretOffset();
}
final IErlElement element = getElementAt(caret, false);
if (!(element instanceof ISourceReference)) {
return null;
}
return (ISourceReference) element;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class AutoIndentStrategy method indentAfterNewLine.
protected void indentAfterNewLine(final IDocument d, final DocumentCommand c) throws BadLocationException {
if (editor == null) {
return;
}
final int offset = c.offset;
String txt = null;
editor.reconcileNow();
final IErlElement element = editor.getElementAt(offset, false);
final IErlMember member = (IErlMember) element;
if (member != null) {
final int start = member.getSourceRange().getOffset();
if (offset >= start) {
txt = d.get(start, offset - start);
}
}
if (txt == null) {
txt = "";
}
final int lineN = d.getLineOfOffset(offset);
final int lineOffset = d.getLineOffset(lineN);
final int lineLength = d.getLineLength(lineN);
final String oldLine = d.get(offset, lineLength + lineOffset - offset);
try {
final int indentw = AutoIndentStrategy.getIndentWidthFromPreferences();
final int tabw = EditorsUI.getPreferenceStore().getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
final Map<String, String> prefs = new TreeMap<>();
IndentationPreferencePage.addKeysAndPrefs(prefs);
SmartTypingPreferencePage.addAutoNLKeysAndPrefs(prefs);
final boolean useTabs = AutoIndentStrategy.getUseTabsFromPreferences();
final IndentResult res = ErlangEngine.getInstance().getIndentService().indentLine(oldLine, txt, c.text, indentw, tabw, useTabs, prefs);
if (res.isAddNewLine()) {
c.text += "\n";
}
c.text += res.getText();
c.length += res.getRemoveNext();
} catch (final Exception e) {
ErlLogger.warn(e);
}
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlangElementImageProvider method computeDescriptor.
private ImageDescriptor computeDescriptor(final Object element, final int flags) {
if (element instanceof IErlElement) {
return ErlangElementImageProvider.getErlImageDescriptor((IErlElement) element, flags);
} else if (element instanceof IFile) {
final IFile file = (IFile) element;
if ("erl".equals(file.getFileExtension())) {
// $NON-NLS-1$
return getErlResourceImageDescriptor(file, flags);
// image for a CU not on the build path
}
return getWorkbenchImageDescriptor(file, flags);
} else if (element instanceof IFolder) {
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlFolder ef = (IErlFolder) model.findElement((IResource) element);
if (ef != null && (ef.isOnSourcePath() || ef.isOnIncludePath())) {
return ErlangElementImageProvider.getErlImageDescriptor(ef, flags);
}
} else if (element instanceof IAdaptable) {
return getWorkbenchImageDescriptor((IAdaptable) element, flags);
}
return null;
}
use of org.erlide.engine.model.IErlElement in project erlide_eclipse by erlang.
the class ErlangCompletionService method computeCompletions.
@Override
public List<CompletionData> computeCompletions(final IOtpRpc backend, IErlProject project0, IErlModule module0, String elementBefore0, final int offset, final String before0, final boolean inString) throws CoreException {
// FIXME these should be passed on as parameters, where needed
project = project0;
module = module0;
elementBefore = elementBefore0;
String before = before0;
final int commaPos = before.lastIndexOf(',');
final int colonPos = before.lastIndexOf(':');
final boolean doubleColon = colonPos >= 0 && before.charAt(colonPos - 1) == ':';
final int hashMarkPos = before.lastIndexOf('#');
final int dotPos = before.lastIndexOf('.');
final int parenPos = before.lastIndexOf('(');
final int leftBracketPos = before.lastIndexOf('{');
final int interrogationMarkPos = before.lastIndexOf('?');
final int arrowPos = before.lastIndexOf("->");
final String prefix = getPrefix(before);
List<String> fieldsSoFar = null;
List<CompletionData> result;
EnumSet<CompletionFlag> flags = EnumSet.noneOf(CompletionFlag.class);
int pos;
String moduleOrRecord = null;
IErlElement element = getElementAt(offset);
for (int i = 1; element == null && i <= 15; ++i) {
element = getElementAt(offset - i);
}
RecordCompletion rc = null;
if (hashMarkPos >= 0) {
final IErlProject aproject = project;
if (aproject != null) {
rc = contextAssistService.checkRecordCompletion(backend, before);
}
}
if (rc != null && rc.isNameWanted()) {
flags = EnumSet.of(CompletionFlag.RECORD_DEFS);
pos = hashMarkPos;
before = rc.getPrefix();
} else if (rc != null && rc.isFieldWanted()) {
flags = EnumSet.of(CompletionFlag.RECORD_FIELDS);
pos = hashMarkPos;
if (dotPos > hashMarkPos) {
pos = dotPos;
} else if (leftBracketPos > hashMarkPos) {
pos = leftBracketPos;
} else {
assert false;
}
before = rc.getPrefix();
moduleOrRecord = rc.getName();
fieldsSoFar = rc.getFields();
} else if (colonPos > commaPos && colonPos > parenPos) {
if (doubleColon) {
flags = EnumSet.of(CompletionFlag.TYPES);
pos = colonPos;
before = before.substring(colonPos + 1);
} else {
moduleOrRecord = StringUtils.unquote(getPrefix(before.substring(0, colonPos)));
flags = EnumSet.of(CompletionFlag.EXTERNAL_FUNCTIONS);
pos = colonPos;
before = before.substring(colonPos + 1);
}
} else if (interrogationMarkPos > hashMarkPos && interrogationMarkPos > commaPos && interrogationMarkPos > colonPos && interrogationMarkPos > arrowPos) {
flags = EnumSet.of(CompletionFlag.MACRO_DEFS);
pos = interrogationMarkPos;
before = before.substring(interrogationMarkPos + 1);
} else {
pos = colonPos;
before = prefix;
if (element != null) {
switch(element.getKind()) {
case EXPORT:
flags = EnumSet.of(CompletionFlag.DECLARED_FUNCTIONS, CompletionFlag.ARITY_ONLY, CompletionFlag.UNEXPORTED_ONLY);
break;
case IMPORT:
final IErlImport i = (IErlImport) element;
moduleOrRecord = i.getImportModule();
flags = EnumSet.of(CompletionFlag.EXTERNAL_FUNCTIONS, CompletionFlag.ARITY_ONLY);
break;
case FUNCTION:
case CLAUSE:
flags = EnumSet.of(CompletionFlag.MODULES);
if (module != null) {
flags.addAll(EnumSet.of(CompletionFlag.VARIABLES, CompletionFlag.DECLARED_FUNCTIONS, CompletionFlag.IMPORTED_FUNCTIONS, CompletionFlag.AUTO_IMPORTED_FUNCTIONS));
}
break;
case ATTRIBUTE:
if ("include".equals(element.getName())) {
flags = EnumSet.of(CompletionFlag.INCLUDES);
} else if ("include_lib".equals(element.getName())) {
flags = EnumSet.of(CompletionFlag.INCLUDE_LIBS);
}
break;
default:
break;
}
} else {
if (doubleColon) {
flags = EnumSet.of(CompletionFlag.TYPES);
} else {
flags = EnumSet.of(CompletionFlag.MODULES);
}
}
}
// TODO flags = filterFlags(flags);
result = addCompletions(backend, flags, offset, before, moduleOrRecord, pos, fieldsSoFar, inString);
return result;
}
Aggregations