• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OffsetRange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.netbeans.modules.csl.api.OffsetRange的典型用法代码示例。如果您正苦于以下问题:Java OffsetRange类的具体用法?Java OffsetRange怎么用?Java OffsetRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OffsetRange类属于org.netbeans.modules.csl.api包,在下文中一共展示了OffsetRange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:LexerUtilities.java


示例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());
        }
        
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:CssStructureScannerTest.java


示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SuggestionsTask.java


示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MarkOccurrencesHighlighter.java


示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:HtmlStructureScanner.java


示例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());
       }
   });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:HtmlStructureItemTest.java


示例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
        }
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CustomHtmlExtension.java


示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ExtractInlinedStylePanel.java


示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:YamlKeystrokeHandler.java


示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:YamlParserResult.java


示例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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:YamlScanner.java


示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:YamlSemanticAnalyzer.java


示例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());
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:HtmlFileModelTest.java


示例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());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CssFileModel.java


示例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;
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CPCssEditorModule.java


示例16: getSemanticHighlightingNodeVisitor

import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public <T extends Map<OffsetRange, Set<ColoringAttributes>>> NodeVisitor<T> getSemanticHighlightingNodeVisitor(FeatureContext context, T result) {
    return new NodeVisitor<T>(result) {

        @Override
        public boolean visit(Node node) {
            switch (node.type()) {
                case mediaType:
                    //screen, printer, ...
                    getResult().put(Css3Utils.getOffsetRange(node), ColoringAttributes.CUSTOM3_SET);
                    break;
                    
                case mediaFeature:
                    //max-width, ...
                    getResult().put(Css3Utils.getOffsetRange(node), ColoringAttributes.CUSTOM1_SET);
                    break;
                    
            }
            return false;
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:MediaQueriesModule.java


示例17: testGetDeclarationForURIQuoted

import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public void testGetDeclarationForURIQuoted() {
    BaseDocument document = getDocument("div { background: url(\"hello.png\"); } ");
    //                                   0123456789012345678901 23456789012 34567890123456789
    //                                   0         1         2         3
    DefaultCssEditorModule dm = new DefaultCssEditorModule();
    Pair<OffsetRange, FutureParamTask<DeclarationFinder.DeclarationLocation, EditorFeatureContext>> declaration = dm.getDeclaration(document, 25);
    assertNotNull(declaration);
    OffsetRange range = declaration.first();
    assertNotNull(range);
    assertEquals(23, range.getStart());
    assertEquals(32, range.getEnd());
    
    FutureParamTask<DeclarationFinder.DeclarationLocation, EditorFeatureContext> task = declaration.second();
    assertNotNull(task);
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DefaultCssModuleTest.java


示例18: getDeclarationLocation

import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public static Pair<OffsetRange, FutureParamTask<DeclarationLocation, EditorFeatureContext>> getDeclarationLocation(final Document document, final int caretOffset, final FeatureCancel cancel) {
    final AtomicReference<Pair<OffsetRange, FutureParamTask<DeclarationLocation, EditorFeatureContext>>> result =
            new AtomicReference<>();
    document.render(new Runnable() {

        @Override
        public void run() {
            for (CssEditorModule module : getModules()) {
                if (cancel.isCancelled()) {
                    return ;
                }
                Pair<OffsetRange, FutureParamTask<DeclarationLocation, EditorFeatureContext>> declarationLocation = module.getDeclaration(document, caretOffset);
                if (declarationLocation != null) {
                    result.set(declarationLocation);
                    return ;
                }
            }
        }
        
    });
    return result.get();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CssModuleSupport.java


示例19: run

import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
@Override
public void run(Result result, SchedulerEvent event) {
    cancelled = false; //resume
    final Map<OffsetRange, Set<ColoringAttributes>> highlights = new HashMap<>();
    HtmlParserResult htmlResult = (HtmlParserResult) result;

    String sourceMimetype = Utils.getWebPageMimeType(htmlResult.getSyntaxAnalyzerResult());
    //process extensions
    for (HtmlExtension ext : HtmlExtensions.getRegisteredExtensions(sourceMimetype)) {
        if (cancelled) {
            return;
        }
        highlights.putAll(ext.getHighlights(htmlResult, event));
    }

    semanticHighlights = highlights;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:HtmlSemanticAnalyzer.java


示例20: getDocumentOffsetRange

import org.netbeans.modules.csl.api.OffsetRange; //导入依赖的package包/类
public static OffsetRange getDocumentOffsetRange(Node node, Snapshot snapshot) {
    int from = node.from();
    int to = node.to();
    if(from < 0 || to < 0) {
        return OffsetRange.NONE;
    }
    if(from > to) {
        return OffsetRange.NONE;
    }
    int origFrom = snapshot.getOriginalOffset(from);
    int origTo = snapshot.getOriginalOffset(to);
    if(origFrom < 0 || origTo < 0) {
        return OffsetRange.NONE;
    }
    if(origFrom > origTo) {
        return OffsetRange.NONE;
    }
    
    return new OffsetRange(origFrom, origTo);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:Css3Utils.java



注:本文中的org.netbeans.modules.csl.api.OffsetRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LinkedKeyBinding类代码示例发布时间:2022-05-22
下一篇:
Java ExPropertyEditor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap