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


Java Snapshot.getOriginalOffset方法代码示例

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


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

示例1: createRuleHandle

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
/**
 * Must be called under model's read lock!
 */
public static RuleHandle createRuleHandle(Rule rule) {
    Model model = rule.getModel();
    Lookup lookup = model.getLookup();
    Snapshot snapshot = lookup.lookup(Snapshot.class);
    FileObject file = lookup.lookup(FileObject.class);
    //in case of very erroneous rule the selectorgroup node may not be present,
    //use the rule node itself for getting the rule name.
    SelectorsGroup selectorsGroup = rule.getSelectorsGroup();
    Element element = selectorsGroup == null ? rule : selectorsGroup;
    String img = model.getElementSource(element).toString();
    
    int offset = snapshot.getOriginalOffset(rule.getStartOffset());
    
    return new RuleHandle(file, rule, offset, img);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:RuleHandle.java

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

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

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

示例6: getDocumentOffsetRange

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
/**
 * Gets document {@link OffsetRange} for the given {@link Element}.
 * 
 * @param element
 * @param snapshot
 * @return {@link OffsetRange#NONE} if the offsets pair is erroneous or can't be converted to document offsets.
 */
public static OffsetRange getDocumentOffsetRange(Element element, Snapshot snapshot) {
    int from = element.from();
    int to = element.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,代码行数:28,代码来源:HtmlEditorUtils.java

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

示例8: filterProblemsInVirtualCode

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
private static void filterProblemsInVirtualCode(Snapshot snapshot, List<ProblemDescription> problems) {
    ListIterator<ProblemDescription> listIterator = problems.listIterator();
    while (listIterator.hasNext()) {
        ProblemDescription p = listIterator.next();
        int from = p.getFrom();
        int to = p.getTo();
        if (snapshot.getOriginalOffset(from) == -1 || snapshot.getOriginalOffset(to) == -1) {
            listIterator.remove();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:CssParser.java

示例9: convertToDocumentOffsets

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
public static OffsetRange convertToDocumentOffsets(int astFrom, int astTo, Snapshot snapshot) {
    int from = snapshot.getOriginalOffset(astFrom);
    int to = snapshot.getOriginalOffset(astTo);

    if (from == -1 && to == -1) {
        //completely unknown position, give up
        return OffsetRange.NONE;
    } else if (from == -1 && to != -1) {
        from = to;
    } else if (from != -1 && to == -1) {
        to = from;
    }
    return new OffsetRange(from, to);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:EmbeddingUtil.java

示例10: getOffsetRange

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public OffsetRange getOffsetRange(ParserResult result) {
    OpenTag node = resolve(result);
    if(node == null) {
        return OffsetRange.NONE;
    }
    
    Snapshot snapshot = result.getSnapshot();
    int dfrom = snapshot.getOriginalOffset(node.from());
    int dto = snapshot.getOriginalOffset(node.semanticEnd());
    
    return dfrom != -1 && dto != -1 ? new OffsetRange(dfrom, dto) : OffsetRange.NONE;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:HtmlElementHandle.java

示例11: getLocationPrefix

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
/**
 * Returns the file:line prefix for the tooltip
 */
private CharSequence getLocationPrefix() {
    if (locationPrefix == null) {
        final StringBuilder sb = new StringBuilder();
        sb.append(Bundle.property_set_at_prefix());
        Model model = getModel();
        Lookup lookup = model.getLookup();
        FileObject file = lookup.lookup(FileObject.class);
        if (file == null) {
            sb.append(Bundle.property_no_file());
        } else {
            sb.append(file.getNameExt());
        }
        Snapshot snap = lookup.lookup(Snapshot.class);
        final Document doc = lookup.lookup(Document.class);
        if (snap != null && doc != null) {
            PropertyDeclaration decl = getDeclaration();
            int ast_from = decl.getStartOffset();
            if (ast_from != -1) {
                //source element, not virtual which is not persisted yet
                final int doc_from = snap.getOriginalOffset(ast_from);
                if (doc_from != -1) {
                    doc.render(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                int lineOffset = 1 + Utilities.getLineOffset((BaseDocument) doc, doc_from);
                                sb.append(':');
                                sb.append(lineOffset);
                            } catch (BadLocationException ex) {
                                //no-op
                            }
                        }
                    });
                }
            }
        }
        locationPrefix = sb.toString();
    }

    return locationPrefix;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:RuleEditorNode.java

示例12: runInEDT

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
private void runInEDT(Snapshot snapshot, Model model, final FileObject file, String mimeType, int caretOffset) {
    LOG.log(Level.FINER, "runInEDT(), file: {0}, caret: {1}", new Object[]{file, caretOffset});

    if (cancelled) {
        LOG.log(Level.FINER, "cancelled");
        return;
    }

    if (caretOffset == -1) {
        try {
            //dirty workaround
            DataObject dobj = DataObject.find(file);
            EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
            if (ec != null) {
                JEditorPane pane = NbDocument.findRecentEditorPane(ec);
                if (pane != null) {
                    caretOffset = pane.getCaretPosition();
                }
            }

        } catch (DataObjectNotFoundException ex) {
            //possibly deleted file, give up
            return;

        }
        
        LOG.log(Level.INFO, "workarounded caret offset: {0}", caretOffset);
    }


    //find rule corresponding to the offset
    Rule rule = findRuleAtOffset(snapshot, model, caretOffset);
    //>>hack, remove once the css.lib css grammar gets finalized
    if(rule != null && rule.getSelectorsGroup() == null) {
        rule = null;
    }
    //<<hack
    
    
    if(rule != null) {
        //check whether the rule is virtual
        if(snapshot.getOriginalOffset(rule.getSelectorsGroup().getStartOffset()) == -1) {
            //virtual selector created for html source element with class or id attribute
            LOG.log(Level.FINER, "the found rule is virtual, exiting w/o change of the RuleEditor", caretOffset);
            return ;
        }
    }
    
    if (!mimeType.equals("text/css")) {
        //if not a css file, 
        //update the rule editor only if there's a rule in an embedded css code
        if (rule == null) {
            LOG.log(Level.FINER, "not a css file and rule not found at {0} offset, exiting w/o change of the RuleEditor", caretOffset);
            return;
        }
    }

    final CssStylesTC cssStylesTC = (CssStylesTC) WindowManager.getDefault().findTopComponent(CssStylesTC.ID);
    if (cssStylesTC == null) {
        return;
    }
    
    //update the RuleEditor TC name
    RuleEditorController controller = cssStylesTC.getRuleEditorController();
    LOG.log(Level.FINER, "SourceTask: calling controller.setModel({0})", model);
    controller.setModel(model);
    
    if (rule == null) {
        controller.setNoRuleState();
    } else {
        controller.setRule(rule);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:74,代码来源:CssCaretAwareSourceTask.java

示例13: CssRuleStructureItem

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
CssRuleStructureItem(CharSequence name, CssNodeElement element, Snapshot source) {
    this.name = name;
    this.element = element;
    this.from = source.getOriginalOffset(element.from());
    this.to = source.getOriginalOffset(element.to());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:CssRuleStructureItem.java

示例14: getMarkOccurrencesNodeVisitor

import org.netbeans.modules.parsing.api.Snapshot; //导入方法依赖的package包/类
@Override
public <T extends Set<OffsetRange>> NodeVisitor<T> getMarkOccurrencesNodeVisitor(EditorFeatureContext context, T result) {

    final Snapshot snapshot = context.getSnapshot();

    int astCaretOffset = snapshot.getEmbeddedOffset(context.getCaretOffset());
    if (astCaretOffset == -1) {
        return null;
    }

    Node current = NodeUtil.findNonTokenNodeAtOffset(context.getParseTreeRoot(), astCaretOffset);
    if (current == null) {
        //this may happen if the offset falls to the area outside the selectors rule node.
        //(for example when the stylesheet starts or ends with whitespaces or comment and
        //and the offset falls there).
        //In such case root node (with null parent) is returned from NodeUtil.findNodeAtOffset() 
        return null;
    }

    //process only some interesting nodes
    if (!NodeUtil.isSelectorNode(current)) {
        return null;
    }

    final NodeType nodeType = current.type();
    final CharSequence currentNodeImage = current.image();

    return new NodeVisitor<T>(result) {

        @Override
        public boolean visit(Node node) {
            if (nodeType == node.type()) {
                boolean ignoreCase = nodeType == NodeType.hexColor;
                if (LexerUtils.equals(currentNodeImage, node.image(), ignoreCase, false)) {

                    int[] trimmedNodeRange = NodeUtil.getTrimmedNodeRange(node);
                    int docFrom = snapshot.getOriginalOffset(trimmedNodeRange[0]);

                    //virtual class or id handling - the class and id elements inside
                    //html tag's CLASS or ID attribute has the dot or hash prefix just virtual
                    //so if we want to highlight such occurances we need to increment the
                    //start offset by one
                    if (docFrom == -1 && (node.type() == NodeType.cssClass || node.type() == NodeType.cssId)) {
                        docFrom = snapshot.getOriginalOffset(trimmedNodeRange[0] + 1); //lets try +1 offset
                    }

                    int docTo = snapshot.getOriginalOffset(trimmedNodeRange[1]);

                    if (docFrom != -1 && docTo != -1) {
                        getResult().add(new OffsetRange(docFrom, docTo));
                    }
                }
            }

            return false;

        }
    };

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

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


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