use of org.erlide.engine.model.erlang.ISourceRange in project erlide_eclipse by erlang.
the class ModelFindUtil method findVariable.
@Override
public ISourceRange findVariable(final ISourceRange range, final String variableName, final String elementText) throws OtpErlangRangeException {
final OtpErlangTuple res2 = ErlangEngine.getInstance().getOpenService().findFirstVar(variableName, elementText);
if (res2 != null) {
final int relativePos = ((OtpErlangLong) res2.elementAt(0)).intValue() - 1;
final int length = ((OtpErlangLong) res2.elementAt(1)).intValue();
final int start = relativePos + range.getOffset();
return new SourceRange(start, length);
}
return range;
}
use of org.erlide.engine.model.erlang.ISourceRange in project erlide_eclipse by erlang.
the class MarkerUtils method createProblemMarkerFor.
public void createProblemMarkerFor(final IResource resource, final IErlFunction erlElement, final String message, final int problemSeverity) throws CoreException {
final ISourceRange range = erlElement == null ? null : erlElement.getNameRange();
final IMarker marker = MarkerUtils.createProblemMarker(resource, null, message, 0, problemSeverity);
final int start = range == null ? 0 : range.getOffset();
final int end = range == null ? 1 : start + range.getLength();
marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end);
}
use of org.erlide.engine.model.erlang.ISourceRange in project erlide_eclipse by erlang.
the class ErlNode method createErlNode.
public static ErlNode createErlNode(final ErlNode parent, final IErlElement element, final IDocument doc) {
int start = 0;
int length = 0;
String name = element.toString();
if (element instanceof IErlModule) {
final IErlModule m = (IErlModule) element;
length = doc.getLength();
name = m.getModuleName();
} else if (element instanceof ISourceReference) {
final ISourceReference sourceReference = (ISourceReference) element;
final ISourceRange sr = sourceReference.getSourceRange();
start = sr.getOffset();
length = sr.getLength();
}
return new ErlNode(parent, element.getKind(), name, ErlangCompareUtilities.getErlElementID(element), doc, start, length);
}
use of org.erlide.engine.model.erlang.ISourceRange in project erlide_eclipse by erlang.
the class DefaultErlangFoldingStructureProvider method computeProjectionRanges.
// private boolean isInnerType(IType type) {
// return type.getDeclaringType() != null;
// }
/**
* Computes the projection ranges for a given <code>IErlElement</code>. More
* than one range may be returned if the element has a leading comment which
* gets folded separately. If there are no foldable regions,
* <code>null</code> is returned.
*
* @param element
* the erlang element that can be folded
* @return the regions to be folded, or <code>null</code> if there are none
*/
private IRegion computeProjectionRanges(final IErlElement element) {
if (element instanceof ISourceReference) {
final ISourceReference reference = (ISourceReference) element;
final ISourceRange range = reference.getSourceRange();
return new Region(range.getOffset(), range.getLength());
}
return null;
}
use of org.erlide.engine.model.erlang.ISourceRange 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);
}
Aggregations