本文整理汇总了Java中org.netbeans.modules.csl.api.OffsetRange类的典型用法代码示例。如果您正苦于以下问题:Java OffsetRange类的具体用法?Java OffsetRange怎么用?Java OffsetRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OffsetRange类属于org.netbeans.modules.csl.api包,在下文中一共展示了OffsetRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findFwd
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
/**
* Search forwards in the token sequence until a matching closing token is
* found so keeps track of nested pairs of up-down eg (()) is ignored if
* we're searching for a )
*
* @param ts the TokenSequence set to the position after an up
* @param up the opening token eg { or [
* @param down the closing token eg } or ]
* @return the Range of closing token in our case 1 char
*/
public static OffsetRange findFwd(TokenSequence<? extends SQLTokenId> ts, int up, int down) {
int balance = 0;
while (ts.moveNext()) {
Token<? extends SQLTokenId> token = ts.token();
if (token.id().ordinal() == up) {
balance++;
} else if (token.id().ordinal() == down) {
if (balance == 0) {
return new OffsetRange(ts.offset(), ts.offset() + token.length());
}
balance--;
}
}
return OffsetRange.NONE;
}
示例2: assertFolds
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public void assertFolds(String code, int[][] expected) throws BadLocationException, ParseException {
CssParserResult result = TestUtil.parse(code);
// TestUtil.dumpResult(result);
StructureScanner scanner = new CssStructureScanner();
Map<String, List<OffsetRange>> folds = scanner.folds(result);
List<OffsetRange> ranges = folds.get(FOLD_TYPE_NAME);
assertNotNull("No folds found but some were expected!", ranges);
assertEquals(String.format("Returned %s folds but %s were expected!", expected.length, ranges.size()), expected.length, ranges.size());
for(int i = 0; i < expected.length; i++) {
int[] range = expected[i];
OffsetRange exp = ranges.get(i);
String msg = String.format("Expected fold range <%s,%s> but was <%s,%s>", range[0], range[1], exp.getStart(), exp.getEnd());
assertEquals(msg, range[0], exp.getStart());
assertEquals(msg, range[1], exp.getEnd());
}
}
示例3: findLineBoundaries
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
private static OffsetRange findLineBoundaries(CharSequence s, int position) {
int l = s.length();
if (position == -1 || position > l) {
return OffsetRange.NONE;
}
// the position is at the end of file, after a newline.
if (position == l && l >= 1 && s.charAt(l - 1) == '\n') {
return new OffsetRange(l -1, l);
}
int min = position;
while (min > 1 && s.charAt(min - 1) != '\n') {
min--;
}
int max = position;
while (max < l && s.charAt(max) != '\n') {
max++;
}
return new OffsetRange(min, max);
}
示例4: processImpl
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@NonNull
List<OffsetRange> processImpl(ParserResult info, Document doc, int caretPosition) {
OccurrencesFinder finder = language.getOccurrencesFinder();
assert finder != null;
finder.setCaretPosition(caretPosition);
try {
finder.run(info, null);
} catch (Exception ex) {
ErrorManager.getDefault().notify(ex);
}
if (cancel.isCancelled()) {
finder.cancel();
}
Map<OffsetRange, ColoringAttributes> highlights = finder.getOccurrences();
return highlights == null ? null : new ArrayList<OffsetRange>(highlights.keySet());
}
示例5: convertAndCheck
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
private OffsetRange convertAndCheck(int embeddedFrom, int embeddedTo, Snapshot snapshot, Lines lines, int maxLen) throws BadLocationException {
if(embeddedFrom == -1 || embeddedTo == -1) {
return null;
}
if (lines.getLineIndex(embeddedFrom) == lines.getLineIndex(embeddedTo)) { //comparing embedded offsets
//do not create one line folds
//XXX this logic could possibly seat in the GSF folding impl.
return null;
}
int so = snapshot.getOriginalOffset(embeddedFrom);
int eo = snapshot.getOriginalOffset(embeddedTo);
if (so == -1 || eo == -1) {
//cannot be mapped back properly
return null;
}
if (eo > maxLen) {
eo = maxLen;
}
if (so > eo) {
so = eo;
}
return new OffsetRange(so, eo);
}
示例6: testCommentFolds
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public void testCommentFolds() throws ParseException, IOException, org.netbeans.modules.parsing.spi.ParseException {
String code = "<div>"
+ "\n<!-- \n"
+ "comment\n"
+ " -->\n"
+ "</div>";
final HtmlStructureScanner scanner = new HtmlStructureScanner();
final FileObject file = createFile("test.html", code);
Document doc = getDocument(file);
Source source = Source.create(doc);
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
HtmlParserResult result = (HtmlParserResult)resultIterator.getParserResult();
Map<String, List<OffsetRange>> folds = scanner.folds(result);
List<OffsetRange> comments = folds.get(HtmlStructureScanner.TYPE_COMMENT.code());
assertNotNull(comments);
assertEquals(1, comments.size());
OffsetRange comment = comments.get(0);
assertNotNull(comment);
assertEquals(6, comment.getStart());
assertEquals(24, comment.getEnd());
}
});
}
示例7: computeSuggestions
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public void computeSuggestions(HintsProvider.HintsManager manager, RuleContext context, List<Hint> hints, int caretOffset) {
HtmlParserResult result = (HtmlParserResult) context.parserResult;
Node root = result.root(SyntaxAnalyzerResult.FILTERED_CODE_NAMESPACE);
Snapshot snapshot = result.getSnapshot();
int embeddedCaretOffset = snapshot.getEmbeddedOffset(caretOffset);
Element found = ElementUtils.findByPhysicalRange(root, embeddedCaretOffset, false);
if (found != null) {
switch (found.type()) {
case OPEN_TAG:
case CLOSE_TAG:
Named named = (Named) found;
String elementName = named.name().toString();
Configuration conf = Configuration.get(snapshot.getSource().getFileObject());
if (conf.getTagsNames().contains(elementName)) {
//custom element
hints.add(new CustomElementHint(elementName, context, new OffsetRange(snapshot.getOriginalOffset(found.from()), snapshot.getOriginalOffset(found.to()))));
}
//TODO add check + fix for missing required attributes
}
}
}
示例8: createEmbeddedCssSectionsModel
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
private ComboBoxModel createEmbeddedCssSectionsModel() {
List<OffsetRange> ranges = context.getExistingEmbeddedCssSections();
EmbeddedSectionItem[] values = new EmbeddedSectionItem[ranges.size() + 1];
//new embedded section item
values[0] = new CreateNewEmbeddedSectionItem();
//existing sections
for (int i = 0; i < values.length - 1; i++) {
OffsetRange astRange = ranges.get(i);
//recompute to document offset range
OffsetRange range = context.getDocumentRange(astRange);
values[i + 1] = new EmbeddedSectionItem(range,
getRenderStringFromOffsetRange(range));
}
return new DefaultComboBoxModel(values);
}
示例9: findLogicalRanges
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public List<OffsetRange> findLogicalRanges(ParserResult info, int caretOffset) {
YamlParserResult result = (YamlParserResult) info;
if (result == null) {
return Collections.emptyList();
}
List<? extends StructureItem> items = result.getItems();
if (items.isEmpty()) {
return Collections.emptyList();
}
List<OffsetRange> ranges = new ArrayList<OffsetRange>();
for (StructureItem item : items) {
addRanges(ranges, caretOffset, item);
}
Collections.reverse(ranges);
Document doc = info.getSnapshot().getSource().getDocument(false);
if (doc != null) {
ranges.add(new OffsetRange(0, doc.getLength()));
}
return ranges;
}
示例10: getAstRange
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public OffsetRange getAstRange(Range range) {
int start = range.start.offset;
int end = range.end.offset;
if (byteToUtf8 == null) {
return new OffsetRange(start, end);
} else {
int s, e;
if (start >= byteToUtf8.length) {
s = byteToUtf8.length;
} else {
s = byteToUtf8[start];
}
if (end >= byteToUtf8.length) {
e = byteToUtf8.length;
} else {
e = byteToUtf8[end];
}
return new OffsetRange(s, e);
}
}
示例11: addBlocks
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
private void addBlocks(YamlParserResult result, BaseDocument doc, CharSequence text, List<OffsetRange> codeblocks, StructureItem item) throws BadLocationException {
int docLength = doc == null ? text.length() : doc.getLength();
int begin = Math.min((int) item.getPosition(), docLength);
int end = Math.min((int) item.getEndPosition(), docLength);
int firstRowEnd = doc == null ? GsfUtilities.getRowEnd(text, begin) : Utilities.getRowEnd(doc, begin);
int lastRowEnd = doc == null ? GsfUtilities.getRowEnd(text, end) : Utilities.getRowEnd(doc, end);
if (begin < end && firstRowEnd != lastRowEnd) {
codeblocks.add(new OffsetRange(firstRowEnd, end));
} else {
return;
}
for (StructureItem child : item.getNestedItems()) {
int childBegin = (int) child.getPosition();
int childEnd = (int) child.getEndPosition();
if (childBegin >= begin && childEnd <= end) {
addBlocks(result, doc, text, codeblocks, child);
}
}
}
示例12: run
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public void run(Result result, SchedulerEvent event) {
resume();
if (isCancelled()) {
return;
}
YamlParserResult ypr = (YamlParserResult) result;
if (ypr == null || ypr.getRootNodes().isEmpty()) {
this.semanticHighlights = Collections.emptyMap();
return;
}
List<Node> rootNodes = ypr.getRootNodes();
Map<OffsetRange, Set<ColoringAttributes>> highlights =
new HashMap<OffsetRange, Set<ColoringAttributes>>(100);
IdentityHashMap<Object, Boolean> seen = new IdentityHashMap<Object, Boolean>(100);
for (Node root : rootNodes) {
addHighlights(ypr, root, highlights, seen, 0);
}
this.semanticHighlights = highlights;
}
示例13: testEmbeddedCSSSections
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public void testEmbeddedCSSSections() throws Exception {
Document doc = getDocument(getTestFile("testfiles/model/test3.html"));
Source source = Source.create(doc);
HtmlFileModel model = new HtmlFileModel(source);
List<OffsetRange> entries = model.getEmbeddedCssSections();
assertEquals(2, entries.size());
OffsetRange entry = entries.get(0);
//first section
assertNotNull(entry);
assertEquals(221, entry.getStart());
assertEquals(295, entry.getEnd());
//second section
entry = entries.get(1);
assertNotNull(entry);
assertEquals(335, entry.getStart());
assertEquals(411, entry.getEnd());
}
示例14: LazyEntry
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public LazyEntry(Snapshot snapshot, Snapshot topLevelSnapshot, String name, OffsetRange range, OffsetRange bodyRange, boolean isVirtual) {
this.snapshotText = snapshot.getText();
if (topLevelSnapshot != null) {
this.topLevelSnapshotText = topLevelSnapshot.getText();
}
this.name = name;
this.range = range;
this.bodyRange = bodyRange;
this.isVirtual = isVirtual;
documentFrom = snapshot.getOriginalOffset(range.getStart());
documentTo = snapshot.getOriginalOffset(range.getEnd());
if (bodyRange != null) {
bodyDocFrom = snapshot.getOriginalOffset(bodyRange.getStart());
bodyDocTo = snapshot.getOriginalOffset(bodyRange.getEnd());
}
}
示例15: getSemanticHighlightingNodeVisitor
import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public <T extends Map<OffsetRange, Set<ColoringAttributes>>> NodeVisitor<T> getSemanticHighlightingNodeVisitor(FeatureContext context, T result) {
final Snapshot snapshot = context.getSnapshot();
return new NodeVisitor<T>(result) {
@Override
public boolean visit(Node node) {
ColoringAttributes coloring = getColorings().get(node.type());
if (coloring != null) {
int dso = snapshot.getOriginalOffset(node.from());
int deo = snapshot.getOriginalOffset(node.to());
if (dso >= 0 && deo >= 0) { //filter virtual nodes
//check vendor speficic property
OffsetRange range = new OffsetRange(dso, deo);
getResult().put(range, Collections.singleton(coloring));
}
}
return false;
}
};
}