本文整理匯總了Java中org.eclipse.xtext.resource.XtextResource.getParseResult方法的典型用法代碼示例。如果您正苦於以下問題:Java XtextResource.getParseResult方法的具體用法?Java XtextResource.getParseResult怎麽用?Java XtextResource.getParseResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.xtext.resource.XtextResource
的用法示例。
在下文中一共展示了XtextResource.getParseResult方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: provideHighlightingFor
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
if (resource == null)
return;
IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootASTElement() == null)
return;
if (highlightedIdentifiers == null) {
highlightedIdentifiers = initializeHighlightedIdentifiers();
idLengthsToHighlight = new BitSet();
for (String s : highlightedIdentifiers.keySet()) {
idLengthsToHighlight.set(s.length());
}
}
//TODO remove this check when the typesystem works without a java project
if (resource.isValidationDisabled()) {
highlightSpecialIdentifiers(acceptor, parseResult.getRootNode());
return;
}
doProvideHighlightingFor(resource, acceptor, cancelIndicator);
}
示例2: createHyperlinksByOffset
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
final IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootNode() == null) {
return; // Return, no need to call in super.createAdditionalHyperlinks
}
// Check if the current parse tree node represents an override keyword, in which case we want to link
// to the overridden rule
INode node = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if (node != null && isOverrideKeyword(node.getGrammarElement())) {
Rule rule = (Rule) eObjectAtOffsetHelper.resolveElementAt(resource, offset);
Region region = new Region(node.getOffset(), node.getLength());
List<Rule> extendedRules = getExtendedRules(rule);
for (Rule extendedRule : extendedRules) {
createHyperlinksTo(resource, region, extendedRule, acceptor);
}
}
super.createHyperlinksByOffset(resource, offset, acceptor);
}
示例3: md5Hex
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
* Computes an MD5 hash from the given resource's source code (the actual source text), as stored in
* {@link TModule#getAstMD5()}. Will fail with an exception if the given resource does not have a valid
* {@link XtextResource#getParseResult() parse result}, as created by Xtext during parsing.
*/
public static String md5Hex(XtextResource resource) {
final IParseResult parseResult = resource.getParseResult();
final INode rootNode = parseResult != null ? parseResult.getRootNode() : null;
final String source = rootNode != null ? rootNode.getText() : null;
if (source == null) {
throw new IllegalStateException("resource does not have a valid parse result: " + resource.getURI());
}
return Hashing.md5().hashString(source, Charsets.UTF_8).toString();
}
示例4: isValidLineForBreakPoint
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public boolean isValidLineForBreakPoint(XtextResource resource, int line) {
IParseResult parseResult = resource.getParseResult();
if (parseResult == null)
return false;
ICompositeNode node = parseResult.getRootNode();
return isValidLineForBreakpoint(node, line);
}
示例5: getImportSectionOffset
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public int getImportSectionOffset(XtextResource resource) {
if(resource.getParseResult() != null && resource.getParseResult().getRootNode() != null) {
List<EObject> pathToImportSection = findPathToImportSection();
if(pathToImportSection != null) {
INode node = findPreviousNode(resource.getParseResult().getRootNode(), pathToImportSection);
if(node != null)
return node.getTotalEndOffset();
}
}
return 0;
}
示例6: doProvideHighlightingFor
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
protected void doProvideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
IParseResult parseResult = resource.getParseResult();
if (parseResult == null)
throw new IllegalStateException("resource#parseResult may not be null");
ICompositeNode node = parseResult.getRootNode();
highlightSpecialIdentifiers(acceptor, node);
super.doProvideHighlightingFor(resource, acceptor, cancelIndicator);
}
示例7: fillGrammarElementToIdMap
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
protected void fillGrammarElementToIdMap(XtextResource r) {
IParseResult parseResult = r.getParseResult();
if (parseResult != null) {
RootNode it = (RootNode) parseResult.getRootNode();
it.fillGrammarElementToIdMap(grammarElementToIdMap, grammarIdToURIMap);
}
}
示例8: SerializableNodeModel
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
public SerializableNodeModel(XtextResource resource) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
root = (RootNode) rootNode;
}
formatVersion = 1;
date = new Date();
}
示例9: create
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
public ContentAssistContext[] create(String document, ITextRegion selection, int offset, XtextResource resource) {
this.document = document;
this.selection = selection;
this.resource = resource;
//This is called to make sure late initialization is done.
if (resource instanceof DerivedStateAwareResource) {
resource.getContents();
}
this.parseResult = resource.getParseResult();
if (parseResult == null)
throw new NullPointerException("parseResult is null");
return doCreateContexts(offset);
}
示例10: provideHighlightingFor
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
if (resource == null)
return;
IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootASTElement() == null)
return;
doProvideHighlightingFor(resource, acceptor, cancelIndicator);
}
示例11: searchAndHighlightElements
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
protected void searchAndHighlightElements(XtextResource resource, IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
IParseResult parseResult = resource.getParseResult();
if (parseResult == null)
throw new IllegalStateException("resource#parseResult may not be null");
EObject element = parseResult.getRootASTElement();
highlightElementRecursively(element, acceptor, cancelIndicator);
}
示例12: createContext
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
protected HoverContext createContext(final Document document, final XtextResource resource, final int offset) {
final EObject crossLinkedEObject = this._eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
if ((crossLinkedEObject != null)) {
boolean _eIsProxy = crossLinkedEObject.eIsProxy();
if (_eIsProxy) {
return null;
}
final IParseResult parseResult = resource.getParseResult();
if ((parseResult == null)) {
return null;
}
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if ((((leafNode != null) && leafNode.isHidden()) && (leafNode.getOffset() == offset))) {
leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), (offset - 1));
}
if ((leafNode == null)) {
return null;
}
final ITextRegion leafRegion = leafNode.getTextRegion();
return new HoverContext(document, resource, offset, leafRegion, crossLinkedEObject);
}
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if ((element == null)) {
return null;
}
final ITextRegion region = this._iLocationInFileProvider.getSignificantTextRegion(element);
return new HoverContext(document, resource, offset, region, element);
}
示例13: createDocument
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
/**
* Creates a new document with the contents of the given {@link XtextResource}.
*
* @param resource
* the resource to be used as input to the document
* @return the created document
*/
private ICoreXtextDocument createDocument(final XtextResource resource) {
XtextDocument document = documentProvider.get();
if (resource.getParseResult() != null && resource.getParseResult().getRootNode() != null) {
document.set(resource.getParseResult().getRootNode().getText());
}
document.setInput(resource);
return new XtextDocumentAdapter(document);
}
示例14: provideHighlightingFor
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
public void provideHighlightingFor( XtextResource resource, IHighlightedPositionAcceptor acceptor )
{
if ( resource == null || resource.getParseResult() == null ) return;
INode root = resource.getParseResult().getRootNode();
BidiTreeIterator<INode> it = root.getAsTreeIterable().iterator();
while (it.hasNext()) {
INode node = it.next();
if (node == null) continue;
if (node instanceof HiddenLeafNode && node.getGrammarElement() instanceof TerminalRuleImpl) {
TerminalRuleImpl ge = (TerminalRuleImpl) node.getGrammarElement();
if (ge.getName().equalsIgnoreCase("SL_COMMENT"))
setStyle(acceptor, node, COMMENT_SINGLE);
if (ge.getName().equalsIgnoreCase("ML_COMMENT"))
setStyle(acceptor, node, COMMENT_MULTI);
} else if (node.getGrammarElement() != null && node.getGrammarElement() instanceof Keyword) {
Keyword k = (Keyword) node.getGrammarElement();
if (ALL_KEYWORDS.contains(k.getValue())) {
setStyle( acceptor, node, KEYWORD);
} else if (ALL_SYMBOLS.contains(k.getValue())) {
setStyle( acceptor, node, SYMBOL);
} else if (ALL_RESERVED_WORDS.contains(k.getValue())) {
setStyle( acceptor, node, RESERVED_WORD);
}
} else if (node instanceof LeafNode && node.getSemanticElement() != null) {
if (node.getSemanticElement() instanceof ClsDef) {
ClsDef cls = (ClsDef) node.getSemanticElement();
if (cls.getInfrastructure() != null && ALL_PREDEFINED_PARAMS.contains(cls.getInfrastructure())) {
setStyle( acceptor, node, PREDEFINED_PARAM);
}
} else if (node.getGrammarElement() != null) {
if (node.getGrammarElement() instanceof RuleCall) {
RuleCall rc = (RuleCall) node.getGrammarElement();
if (rc.getRule().getName().equals("STRING")) {
setStyle( acceptor, node, STRING);
} else if (rc.getRule().getName().equals("INT_LITERAL")) {
setStyle( acceptor, node, NUMBER);
} else {
//System.out.println("" + node.getOffset() + " " + node.getLength() + node.toString() + " ## " + node.getGrammarElement().toString() + " ## " + node.getSemanticElement().toString() + " // " + rc.getRule().getName());
}
}
}
} else if (node.getGrammarElement() != null && node.getSemanticElement() != null) {
//System.out.println("" + node.getOffset() + " " + node.getLength() + node.toString() + " ## " + node.getGrammarElement().toString() + " ## " + node.getSemanticElement().toString());
}
}
}
示例15: checkNodeModel
import org.eclipse.xtext.resource.XtextResource; //導入方法依賴的package包/類
protected void checkNodeModel(XtextResource resource) {
IParseResult parseResult = resource.getParseResult();
if(parseResult != null)
getInvariantChecker().checkInvariant(parseResult.getRootNode());
}