use of org.erlide.engine.model.erlang.IErlMember 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.erlang.IErlMember in project erlide_eclipse by erlang.
the class DefaultErlangFoldingStructureProvider method match.
/**
* Matches deleted annotations to changed or added ones. A deleted
* annotation/position tuple that has a matching addition / change is
* updated and marked as changed. The matching tuple is not added (for
* additions) or marked as deletion instead (for changes). The result is
* that more annotations are changed and fewer get deleted/re-added.
*/
private void match(final List<ErlangProjectionAnnotation> deletions, final Map<ErlangProjectionAnnotation, Position> additions, final List<ErlangProjectionAnnotation> changes) {
if (deletions.isEmpty() || additions.isEmpty() && changes.isEmpty()) {
return;
}
final List<ErlangProjectionAnnotation> newDeletions = new ArrayList<>();
final List<ErlangProjectionAnnotation> newChanges = new ArrayList<>();
final Iterator<ErlangProjectionAnnotation> deletionIterator = deletions.iterator();
while (deletionIterator.hasNext()) {
final ErlangProjectionAnnotation deleted = deletionIterator.next();
final Position deletedPosition = fCachedModel.getPosition(deleted);
if (deletedPosition == null) {
continue;
}
final Tuple deletedTuple = new Tuple(deleted, deletedPosition);
Tuple match = findMatch(deletedTuple, changes, null);
boolean addToDeletions = true;
if (match == null) {
match = findMatch(deletedTuple, additions.keySet(), additions);
addToDeletions = false;
}
if (match != null) {
final IErlElement element = match.annotation.getElement();
deleted.setElement(element);
deletedPosition.setLength(match.position.getLength());
if (deletedPosition instanceof ErlangElementPosition && element instanceof IErlMember) {
final ErlangElementPosition eep = (ErlangElementPosition) deletedPosition;
eep.setMember((IErlMember) element);
}
deletionIterator.remove();
newChanges.add(deleted);
if (addToDeletions) {
newDeletions.add(match.annotation);
}
}
}
deletions.addAll(newDeletions);
changes.addAll(newChanges);
}
use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlTextMemberSelection method getMemberRange.
@Override
public IErlRange getMemberRange() {
if (getErlElement() instanceof IErlMember) {
IErlRange range = null;
final IErlMember member = (IErlMember) getErlElement();
int sL;
int sC;
int eL;
int eC;
sL = member.getLineStart() + 1;
eL = member.getLineEnd() + 1;
sC = WranglerUtils.calculateColumnFromOffset(member.getSourceRange().getOffset(), sL - 1, document);
eC = WranglerUtils.calculateColumnFromOffset(member.getSourceRange().getOffset() + member.getSourceRange().getLength(), eL - 1, document);
range = new ErlRange(sL, sC, eL, eC, member.getSourceRange().getOffset(), member.getSourceRange().getLength());
return range;
}
return getSelectionRange();
}
use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlParser method attachFunctionComments.
/**
* attach local function documentation with heuristics: if a comment is within 3 lines
* before function, or a sequence of comment, -spec, comment, then they should be
* added to function documentation
*
* If any typespec is available for the function (wherever it is located), then it
* should be attached too.
*
* @param module
*/
private void attachFunctionComments(final IErlModule module) {
// TODO rewrite in Erlang? would be so much less code...
try {
final Collection<IErlComment> comments = module.getComments();
final List<IErlElement> children = module.getChildren();
final List<IErlMember> all = Lists.newArrayListWithCapacity(children.size() + comments.size());
all.addAll(comments);
for (final IErlElement element : children) {
if (element instanceof IErlMember) {
all.add((IErlMember) element);
}
}
all.sort(new SourceOffsetComparator());
for (int i = 1; i < all.size(); i++) {
checkForComment(all, i);
}
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlParser method addMacroDef.
private IErlMember addMacroDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra, final String nameS) {
if (val instanceof OtpErlangAtom) {
final String s = Util.stringValue(extra);
final ErlMember r = new ErlMacroDef(module, ((OtpErlangAtom) val).atomValue(), s);
setPos(r, pos);
// r.setParseTree(val);
return r;
} else if (val instanceof OtpErlangList) {
final OtpErlangList macroList = (OtpErlangList) val;
if (macroList.elementAt(0) instanceof OtpErlangTuple) {
final OtpErlangTuple macroNameTuple = (OtpErlangTuple) macroList.elementAt(0);
OtpErlangObject o = macroNameTuple.elementAt(2);
if (o instanceof OtpErlangTuple) {
o = ((OtpErlangTuple) o).elementAt(2);
}
ErlMember r;
if (o instanceof OtpErlangAtom) {
final String macroName = ((OtpErlangAtom) o).atomValue();
r = new ErlMacroDef(module, macroName, null);
} else {
// what do we do here? the define isn't correct
// Erlang...
ErlLogger.warn("Strange macro definition in %s: %s", module.getName(), o.toString());
r = new ErlMacroDef(module, o.toString(), null);
}
setPos(r, pos);
// r.setParseTree(val);
return r;
}
}
return addOtherAttribute(module, pos, val, extra, nameS);
}
Aggregations