use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlParser method checkForComment.
private void checkForComment(final List<IErlMember> all, final int i) {
final IErlMember m = all.get(i);
if (m instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) m;
final LinkedList<IErlComment> comments = Lists.newLinkedList();
int j = considerPrevious(i, all, comments, function);
j = considerPrevious(j, all, comments, function);
j = considerPrevious(j, all, comments, function);
if (!comments.isEmpty()) {
function.setComments(comments);
}
}
}
use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlParser method considerPrevious.
private int considerPrevious(final int i, final List<IErlMember> all, final Deque<IErlComment> comments, final IErlFunction function) {
final int j = i - 1;
if (j > 0) {
final IErlMember member = all.get(i);
final IErlMember prevMember = all.get(j);
if (prevMember instanceof IErlComment) {
if (prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
comments.addFirst((IErlComment) prevMember);
}
} else if (prevMember instanceof IErlTypespec) {
final IErlTypespec spec = (IErlTypespec) prevMember;
if (spec.getName().equals(function.getName()) && spec.getArity() == function.getArity() && prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
function.setTypespec(spec);
}
} else {
return -1;
}
}
return j;
}
use of org.erlide.engine.model.erlang.IErlMember in project erlide_eclipse by erlang.
the class ErlangEditor method setSelection.
public void setSelection(final ISourceReference reference, final boolean moveCursor) {
if (getSelectionProvider() == null) {
return;
}
final ISelection selection = getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
final TextSelection textSelection = (TextSelection) selection;
if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) {
markInNavigationHistory();
}
}
if (reference != null) {
StyledText textWidget = null;
final ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer == null) {
return;
}
textWidget = sourceViewer.getTextWidget();
if (textWidget == null) {
return;
}
try {
ISourceRange range = null;
range = reference.getSourceRange();
if (range == null) {
return;
}
int offset = range.getOffset();
int length = range.getLength();
if (offset < 0 || length < 0) {
return;
}
setHighlightRange(offset, length, moveCursor);
if (!moveCursor) {
return;
}
offset = -1;
length = -1;
if (reference instanceof IErlMember) {
range = ((IErlMember) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
} else if (reference instanceof IErlAttribute) {
range = ((IErlAttribute) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
} else if (reference instanceof IErlFunctionClause) {
range = ((IErlFunctionClause) reference).getNameRange();
if (range != null) {
offset = range.getOffset();
length = range.getLength();
}
}
if (offset > -1 && length > 0) {
try {
textWidget.setRedraw(false);
sourceViewer.revealRange(offset, length);
sourceViewer.setSelectedRange(offset, length);
} finally {
textWidget.setRedraw(true);
}
markInNavigationHistory();
}
} catch (final IllegalArgumentException x) {
}
} else if (moveCursor) {
resetHighlightRange();
markInNavigationHistory();
}
}
Aggregations