当前位置: 首页>>代码示例>>Java>>正文


Java Snapshot.getText方法代码示例

本文整理汇总了Java中org.netbeans.modules.parsing.api.Snapshot.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Snapshot.getText方法的具体用法?Java Snapshot.getText怎么用?Java Snapshot.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.modules.parsing.api.Snapshot的用法示例。


在下文中一共展示了Snapshot.getText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LazyEntry

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的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

示例2: parse

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
    final CharSequence toParse = snapshot.getText();
    boolean valid = true;
    int embStart = -1;
    for (int i=0; i< toParse.length(); i++) {
        if (toParse.charAt(i) == '<') {         //NOI18N
            if (embStart != -1) {
                valid = false;
                break;
            }
            embStart = i+1;
        } else if (toParse.charAt(i) == '>') {  //NOI18N
            if (embStart == -1 || embStart == i) {
                valid = false;
                break;
            }
            embStart = -1;
        }
    }
    resultCache = new TopResult(snapshot, valid);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:EmbeddedIndexerTest.java

示例3: ElementsIterator

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
public ElementsIterator(Snapshot snapshot) {
    if(!"text/html".equals(snapshot.getMimeType())) {
        throw new IllegalStateException();
    }
    
    CharSequence source = snapshot.getText();
    TokenSequence<HTMLTokenId> tokenSequence = snapshot.getTokenHierarchy().tokenSequence(HTMLTokenId.language());
    
    this.wrapped = ElementsParser.forTokenIndex(source, tokenSequence, 0);
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ElementsIterator.java

示例4: getFoldsNodeVisitor

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public <T extends Map<String, List<OffsetRange>>> NodeVisitor<T> getFoldsNodeVisitor(FeatureContext context, T result) {
    final Snapshot snapshot = context.getSnapshot();
    final Lines lines = new Lines(snapshot.getText());

    return new NodeVisitor<T>(result) {
        @Override
        public boolean visit(Node node) {
            switch (node.type()) {
                case sass_control_block:
                case cp_mixin_block:
                case sass_map:
                case sass_function_declaration:
                    //find the ruleSet curly brackets and create the fold between them inclusive
                    int from = node.from();
                    int to = node.to();
                    try {
                        //do not creare one line folds
                        if (lines.getLineIndex(from) < lines.getLineIndex(to)) {
                            List<OffsetRange> codeblocks = getResult().get("codeblocks"); //NOI18N
                            if (codeblocks == null) {
                                codeblocks = new ArrayList<>();
                                getResult().put("codeblocks", codeblocks); //NOI18N
                            }

                            codeblocks.add(new OffsetRange(from, to));
                        }
                    } catch (BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
            }
            return false;
        }
    };

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

示例5: getEmbeddings

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public List<Embedding> getEmbeddings(@NonNull final Snapshot snapshot) {
    final List<Embedding> embs = new ArrayList<Embedding>();
    final CharSequence toParse = snapshot.getText();
    int embStart = -1;
    for (int i=0; i< toParse.length(); i++) {
        if (toParse.charAt(i) == '<') {         //NOI18N
            embStart = i+1;
        } else if (toParse.charAt(i) == '>') {  //NOI18N
            embs.add(snapshot.create(embStart, i-embStart, MIME_INNER));
        }
    }
    return embs;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:EmbeddedIndexerTest.java

示例6: R

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
public R(@NonNull final Snapshot snapshot) {
    super(snapshot);
    embs = new ArrayList<CharSequence>();
    int embStart = -1;
    final CharSequence text = snapshot.getText();
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        if (c == '{') {
            embStart = i+1;
        } else if (c == '}' && embStart >= 0) {
            CharSequence emb = text.subSequence(embStart, i);
            embs.add(emb);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:QuerySupportLifeLock230220Test.java

示例7: parse

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
    cancelled.set(false);
    if (snapshot == null) {
        return;
    }
    
    this.snapshot = snapshot;
    FileObject fo = snapshot.getSource().getFileObject();
    String fileName = fo == null ? "no file" : fo.getPath(); //NOI18N
    String mimeType = topLevelSnapshotMimetype != null ? topLevelSnapshotMimetype : (fo == null ? null : fo.getMIMEType());
    LOG.log(Level.FINE, "Parsing {0} ", fileName); //NOI18N
    long start = System.currentTimeMillis();
    try {
        boolean tooLargeSnapshot = snapshot.getText().length() > MAX_SNAPSHOT_SIZE;
        
        //parse just an empty string in case of an oversize snapshot
        CharSequence source = tooLargeSnapshot ? "" : snapshot.getText();
        
        ExtCss3Lexer lexer = new ExtCss3Lexer(source, mimeType);
        TokenStream tokenstream = new CommonTokenStream(lexer);
        NbParseTreeBuilder builder = new NbParseTreeBuilder(source);
        ExtCss3Parser parser = new ExtCss3Parser(tokenstream, builder, mimeType);

        if (cancelled.get()) {
            return;
        }
        parser.styleSheet();

        if (cancelled.get()) {
            return;
        }

        AbstractParseTreeNode tree_local = builder.getTree();
        List<ProblemDescription> problems_local = new ArrayList<>();
        //add lexer issues
        problems_local.addAll(lexer.getProblems());
        //add parser issues
        problems_local.addAll(builder.getProblems());

        filterProblemsInVirtualCode(snapshot, problems_local);
        filterTemplatingProblems(snapshot, problems_local);

        if(tooLargeSnapshot) {
            //add a problem description informing the user there's something 'wrong' with the file
            problems_local.add(new ProblemDescription(0, 0, 
                    Bundle.too_large_snapshot(), ProblemDescription.Keys.PARSING.name(), ProblemDescription.Type.WARNING ));
        }
        
        if (cancelled.get()) {
            return;
        }

        this.tree = tree_local;
        this.problems = problems_local;

    } catch (RecognitionException ex) {
        throw new ParseException(String.format("Error parsing %s snapshot.", snapshot), ex); //NOI18N
    } finally {
        long end = System.currentTimeMillis();
        LOG.log(Level.FINE, "Parsing of {0} took {1} ms.", new Object[]{fileName, (end - start)}); //NOI18N
    }

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

示例8: getFoldsNodeVisitor

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public <T extends Map<String, List<OffsetRange>>> NodeVisitor<T> getFoldsNodeVisitor(FeatureContext context, T result) {
    final Snapshot snapshot = context.getSnapshot();
    final Lines lines = new Lines(snapshot.getText());

    return new NodeVisitor<T>(result) {

        @Override
        public boolean visit(Node node) {
            int from = -1, to = -1;
            switch (node.type()) {
                case rule:
                case media:
                case page:
                case webkitKeyframes:
                case generic_at_rule:
                case vendorAtRule:
                    //find the ruleSet curly brackets and create the fold between them inclusive
                    Node[] tokenNodes = NodeUtil.getChildrenByType(node, NodeType.token);
                    for (Node leafNode : tokenNodes) {
                        if (CharSequenceUtilities.equals("{", leafNode.image())) {
                            from = leafNode.from();
                        } else if (CharSequenceUtilities.equals("}", leafNode.image())) {
                            to = leafNode.to();
                        }
                    }

                    if (from != -1 && to != -1) {
                        int doc_from = snapshot.getOriginalOffset(from);
                        int doc_to = snapshot.getOriginalOffset(to);

                        try {
                            //check the boundaries a bit
                            if (doc_from >= 0 && doc_to >= 0) {
                                //do not creare one line folds
                                if (lines.getLineIndex(from) < lines.getLineIndex(to)) {

                                    List<OffsetRange> codeblocks = getResult().get("codeblocks"); //NOI18N
                                    if (codeblocks == null) {
                                        codeblocks = new ArrayList<>();
                                        getResult().put("codeblocks", codeblocks); //NOI18N
                                    }

                                    codeblocks.add(new OffsetRange(doc_from, doc_to));
                                }
                            }
                        } catch (BadLocationException ex) {
                            //ignore
                        }
                    }

            }
            return false;
        }
    };

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

示例9: getEmbeddings

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public List<Embedding> getEmbeddings(Snapshot snapshot) {
    Document doc = snapshot.getSource().getDocument(true);
    try {
        LanguagePath path = LanguagePath.get(MimeLookup.getLookup(snapshot.getMimeType()).lookup(Language.class));
        InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class);
        Document baseDoc = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N
        FileObject baseFile = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N
        int offset = (Integer)attributes.getValue(path, "dialogBinding.offset"); //NOI18N
        int line = (Integer)attributes.getValue(path, "dialogBinding.line"); //NOI18N
        int column = (Integer)attributes.getValue(path, "dialogBinding.column"); //NOI18N
        int length = (Integer)attributes.getValue(path, "dialogBinding.length"); //NOI18N

        final Source base;
        if (baseDoc != null) {
            base = Source.create(baseDoc);
        } else if (baseFile != null) {
            base = Source.create(baseFile);
        } else {
            base = null;
        }
        if (base == null) {
            return Collections.<Embedding>emptyList();
        }
        Snapshot baseSnapshot = SourceAccessor.getINSTANCE().getCache(base).getSnapshot();
        if (offset == -1) {
            int lso = SourceAccessor.getINSTANCE().getLineStartOffset(baseSnapshot, line);
            int nextLso = SourceAccessor.getINSTANCE().getLineStartOffset(baseSnapshot, line + 1);
            if (lso + column < nextLso) {
                offset = lso + column;
            } else {
                offset = nextLso - 1;
                length = 0;
                LOG.log(Level.INFO, "Column={0} not on the line={1}; dialog's content will be bound to the line's boundary", new Object [] { column, line}); //NOI18N
            }
        }

        String baseMimeType = base.getMimeType();
        CharSequence part1 = baseSnapshot.getText().subSequence(0, offset);
        CharSequence part2 = snapshot.getText();
        CharSequence part3 = baseSnapshot.getText().subSequence(offset + length, baseSnapshot.getText().length());

        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "\nsnapshot={0}\nbaseSnapshot={1}\ndoc={2}\nfile={3}\noffset={4}\nline={5}\ncolumn={6}\nlength={7}\n" + //NOI18N
                    "part1={8}\npart2={9}\npart3={10}\n", //NOI18N
                new Object [] {
                    snapshot, baseSnapshot,
                    baseDoc, baseFile,
                    offset, line, column, length,
                    part1.toString(), part2.toString(), part3.toString(),
            });
        }
        
        ArrayList<Embedding> ret = new ArrayList<Embedding>(3);
        ret.add(snapshot.create(part1, baseMimeType));
        ret.add(snapshot.create(0, snapshot.getText().length(), baseMimeType));
        ret.add(snapshot.create(part3, baseMimeType));
        return Collections.singletonList(Embedding.create(ret));
    } catch (Exception e) {
        LOG.log(Level.WARNING, null, e);
    }
    return Collections.emptyList();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:DialogBindingEmbeddingProvider.java


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