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


Java Snapshot类代码示例

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


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

示例1: convertAndCheck

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

示例2: getOffsetRange

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
@Override
public OffsetRange getOffsetRange(ParserResult result) {
    Snapshot s = result.getSnapshot();

    if(s.getText().length() == 0) {
        return null;
    }

    //check the boundaries bacause of (I)
    int origFrom = from > s.getText().length() ? 0 : s.getOriginalOffset(from);
    int origTo = to > s.getText().length() ? 0 : s.getOriginalOffset(to);

    if(origFrom == -1 || origTo == -1 || origFrom == origTo || origTo == 0) {
        return null;
    }
    
    return new OffsetRange(origFrom, origTo);
            
            
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CssNodeElement.java

示例3: getDocumentOffsetRange

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

示例4: parse

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
    final InnerResult res = new InnerResult(snapshot);
    final CharSequence text = snapshot.getText();
    for (int i=0; i< text.length(); i++) {
        if (text.charAt(i) == 'A') {
            res.setMode(InnerResult.A);
            break;
        } else if (text.charAt(i) == 'B') {
            res.setMode(InnerResult.B);
            break;
        } else if (text.charAt(i) == 'C') {
            res.setMode(InnerResult.C);
            break;
        }
    }
    resultCache = res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:EmbeddedIndexerTest.java

示例5: checkVirtualSource

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
private void checkVirtualSource(String file) throws Exception {
    FileObject fo = getTestFile(file);
    assertNotNull(fo);

    Source source = Source.create(fo);
    assertNotNull(source);

    Snapshot snapshot = source.createSnapshot();
    assertNotNull(snapshot);

    CssEmbeddingProvider provider = new CssEmbeddingProvider();

    List<Embedding> embeddings = provider.getEmbeddings(snapshot);
    assertNotNull(embeddings);
    assertEquals(1, embeddings.size());

    Embedding embedding = embeddings.get(0);
    Snapshot virtualSource = embedding.getSnapshot();
    String virtualSourceText = virtualSource.getText().toString();

    assertDescriptionMatches(file, virtualSourceText, false, ".virtual");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CssEmbeddingProviderTest.java

示例6: CompilationInfoImpl

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
/**
 * Creates a new CompilationInfoImpl for given source file
 * @param parser used to parse the file
 * @param file to be parsed
 * @param root the owner of the parsed file
 * @param javacTask used javac or null if new one should be created
 * @param snapshot rendered content of the file
 * @param detached true if the CompilationInfoImpl is detached from parsing infrastructure.
 * @throws java.io.IOException
 */
CompilationInfoImpl (final JavacParser parser,
                     final FileObject file,
                     final FileObject root,
                     final JavacTaskImpl javacTask,
                     final DiagnosticListener<JavaFileObject> diagnosticListener,
                     final Snapshot snapshot,
                     final boolean detached) throws IOException {
    assert parser != null;
    this.parser = parser;
    this.cpInfo = parser.getClasspathInfo();
    assert cpInfo != null;
    this.file = file;
    this.root = root;
    this.snapshot = snapshot;
    assert file == null || snapshot != null;
    this.jfo = file != null ?
        FileObjects.sourceFileObject(file, root, JavaFileFilterQuery.getFilter(file), snapshot.getText()) :
        null;
    this.javacTask = javacTask;
    this.diagnosticListener = diagnosticListener;
    this.isClassFile = false;
    this.isDetached = detached;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:CompilationInfoImpl.java

示例7: getSemanticHighlightingNodeVisitor

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

示例8: getTrees

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
/**
 * Return the {@link Trees} service of the javac represented by this {@link CompilationInfo}.
 * @return javac Trees service
 */
public synchronized @NonNull Trees getTrees() {
    checkConfinement();
    if (trees == null) {
        //use a working init order:
        com.sun.tools.javac.main.JavaCompiler.instance(impl.getJavacTask().getContext());
        trees = JavacTrees.instance(impl.getJavacTask().getContext());
        Snapshot snapshot = impl.getSnapshot();
        Document doc = snapshot != null ? snapshot.getSource().getDocument(false) : null;
        WrapperFactory factory = doc != null ? (WrapperFactory)doc.getProperty(WrapperFactory.class) : null;
        if (factory != null) {
            trees = factory.wrapTrees(trees);
        }
    }
    return trees;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CompilationInfo.java

示例9: computeSuggestions

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

示例10: create

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
public static CssFileModel create(Source source) throws ParseException {
    final AtomicReference<CssFileModel> model = new AtomicReference<>();
    ParserManager.parse(Collections.singletonList(source), new UserTask() {
        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            ResultIterator cssRi = WebUtils.getResultIterator(resultIterator, CssLanguage.CSS_MIME_TYPE);
            Snapshot topLevelSnapshot = resultIterator.getSnapshot();
            if(cssRi != null) {
                Parser.Result parserResult = cssRi.getParserResult();
                if(parserResult != null) {
                    model.set(new CssFileModel((CssParserResult)parserResult, topLevelSnapshot));
                    return ;
                }
            }
            model.set(new CssFileModel(topLevelSnapshot));
        }
    });
    return model.get();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CssFileModel.java

示例11: CpAlternativeLocation

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
public CpAlternativeLocation(CPCslElementHandle handle, DeclarationLocation location, Snapshot snapshot, Lines lines, boolean currentFile) {
    this.handle = handle;
    this.location = location;
    this.currentFile = currentFile;
    try {
        lineIndex = lines.getLineIndex(location.getOffset());
        //line bounds
        int from = lines.getLineOffset(lineIndex);
        int to = lines.getLinesCount() > (lineIndex + 1)
                ? lines.getLineOffset(lineIndex + 1)
                : snapshot.getText().length();
        lineText = snapshot.getText().subSequence(from, to).toString();
    } catch (BadLocationException ex) {
        Logger.getLogger(CpAlternativeLocation.class.getName()).log(Level.INFO, null, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CPCssEditorModule.java

示例12: createSourceElementHandle

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
/**
 * Resolves the {@link FileObject} and source element path to a parser
 * result and {@link OpenTag}.
 *
 * The returned value is not cached and will run a parsing api task each
 * time is called.
 *
 * @return An instance of {@link  SourceElementHandle}
 * exception is thrown.
 * @throws ParseException
 */
public SourceElementHandle createSourceElementHandle() throws ParseException {
    final AtomicReference<SourceElementHandle> seh_ref = new AtomicReference<>();
    Source source = Source.create(file);
    ParserManager.parse(Collections.singleton(source), new UserTask() {
        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            ResultIterator ri = WebUtils.getResultIterator(resultIterator, "text/html");
            if (ri == null) {
                return;
            }

            HtmlParserResult result = (HtmlParserResult) ri.getParserResult();
            Snapshot snapshot = result.getSnapshot();

            Node root = result.root();
            OpenTag openTag = ElementUtils.query(root, elementPath);

            seh_ref.set(new SourceElementHandle(openTag, snapshot, file));

        }
    });
    return seh_ref.get();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:AbstractSourceElementAction.java

示例13: getEmbeddings

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
@Override
public List<Embedding> getEmbeddings(Snapshot snapshot) {
    if (sourceMimeType.equals(snapshot.getMimeType())) {
        int slen = snapshot.getText().length();
        LOG.fine(String.format("CssEmbeddingProvider.create(snapshot): mimetype: %s, size: %s", snapshot.getMimeType(), slen)); //NOI18N
        if(slen > MAX_SNAPSHOT_SIZE) {
            LOG.fine(String.format("Size %s > maximum (%s) => providing no css embedding", slen, MAX_SNAPSHOT_SIZE)); //NOI18N
            return Collections.<Embedding>emptyList();
        }
        List<Embedding> embeddings = translator.getEmbeddings(snapshot);
        if(embeddings.isEmpty()) {
            return Collections.emptyList();
        } else {
            return Collections.singletonList(Embedding.create(embeddings));
        }
    } else {
        LOG.log(Level.WARNING, "Unexpected snapshot type: ''{0}''; expecting ''{1}''", new Object[]{snapshot.getMimeType(), sourceMimeType}); //NOI18N
        return Collections.<Embedding>emptyList();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:CssEmbeddingProvider.java

示例14: 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

示例15: getEmbeddings

import org.netbeans.modules.parsing.api.Snapshot; //导入依赖的package包/类
@Override
public List<Embedding> getEmbeddings(Snapshot snapshot) {
    TokenSequence<DeclarativeHintTokenId> ts = snapshot.getTokenHierarchy().tokenSequence(DeclarativeHintTokenId.language());

    Result parsed = new DeclarativeHintsParser().parse(snapshot.getSource().getFileObject(), snapshot.getText(), ts);

    if (parsed.blocks.isEmpty()) {
        return Arrays.asList(Embedding.create(rules(snapshot, parsed)));
    } else {
        return Arrays.asList(Embedding.create(rules(snapshot, parsed)), Embedding.create(predicates(snapshot, parsed)));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:EmbeddingProviderImpl.java


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