當前位置: 首頁>>代碼示例>>Java>>正文


Java XtextResource.getParseResult方法代碼示例

本文整理匯總了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);
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:23,代碼來源:XbaseHighlightingCalculator.java

示例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);
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:22,代碼來源:FormatHyperlinkHelper.java

示例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();
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:15,代碼來源:N4JSASTUtils.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:9,代碼來源:XbaseStratumBreakpointSupport.java

示例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;
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:13,代碼來源:DefaultImportsConfiguration.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:11,代碼來源:XbaseHighlightingCalculator.java

示例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);
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:8,代碼來源:SerializationConversionContext.java

示例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();
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:10,代碼來源:SerializableNodeModel.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:14,代碼來源:ContentAssistContextFactory.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:11,代碼來源:DefaultSemanticHighlightingCalculator.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:9,代碼來源:DefaultSemanticHighlightingCalculator.java

示例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);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:29,代碼來源:HoverService.java

示例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);
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:16,代碼來源:ModificationContextRegistry.java

示例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());
		}
	}
}
 
開發者ID:jason-lang,項目名稱:jason-eclipse-plugin,代碼行數:52,代碼來源:Mas2jHighlightingCalculator.java

示例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());
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:6,代碼來源:AbstractXtextTests.java


注:本文中的org.eclipse.xtext.resource.XtextResource.getParseResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。