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


Java ParseResult类代码示例

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


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

示例1: replaceOldSemanticElement

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void replaceOldSemanticElement(EObject oldElement, IParseResult previousParseResult,
		IParseResult newParseResult) {
	EObject oldSemanticParentElement = oldElement.eContainer();
	if (oldSemanticParentElement != null) {
		EStructuralFeature feature = oldElement.eContainingFeature();
		if (feature.isMany()) {
			List featureValueList = (List) oldSemanticParentElement.eGet(feature);
			int index = featureValueList.indexOf(oldElement);
			unloadSemanticObject(oldElement);
			featureValueList.set(index, newParseResult.getRootASTElement());
		} else {
			unloadSemanticObject(oldElement);
			oldSemanticParentElement.eSet(feature, newParseResult.getRootASTElement());
		}
		((ParseResult) newParseResult).setRootASTElement(previousParseResult.getRootASTElement());
	} else {
		unloadSemanticObject(oldElement);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:TokenSequencePreservingPartialParsingHelper.java

示例2: readNodeModel

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
protected void readNodeModel(final StorageAwareResource resource, final InputStream inputStream) throws IOException {
  final SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource);
  boolean _exists = resource.getResourceSet().getURIConverter().exists(resource.getURI(), resource.getResourceSet().getLoadOptions());
  boolean _not = (!_exists);
  if (_not) {
    URI _uRI = resource.getURI();
    String _plus = ("Skipping loading node model for synthetic resource " + _uRI);
    ResourceStorageLoadable.LOG.info(_plus);
    return;
  }
  final InputStream stream = resource.getResourceSet().getURIConverter().createInputStream(resource.getURI());
  String _encoding = resource.getEncoding();
  final InputStreamReader in = new InputStreamReader(stream, _encoding);
  final String completeContent = CharStreams.toString(in);
  final DeserializationConversionContext deserializationContext = new DeserializationConversionContext(resource, completeContent);
  final DataInputStream dataIn = new DataInputStream(inputStream);
  serializableNodeModel.readObjectData(dataIn, deserializationContext);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  boolean _hasErrors = deserializationContext.hasErrors();
  ParseResult _parseResult = new ParseResult(_head, serializableNodeModel.root, _hasErrors);
  resource.setParseResult(_parseResult);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:23,代码来源:ResourceStorageLoadable.java

示例3: insertProxyModel

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void insertProxyModel() {
  // Node model can be accessed by:
  // 1. checking the adapters of an EObject
  ICompositeNode rootNode = null;
  TreeIterator<EObject> iterator = EcoreUtil.getAllProperContents(resource, false);
  while (iterator.hasNext()) {
    EObject eObject = iterator.next();
    LazyLoadingCompositeNode node = new LazyLoadingCompositeNode();
    eObject.eAdapters().add(node);
    if (rootNode == null) {
      rootNode = node;
    }
  }

  // 2. fetching the ParseResult instance of the Resource
  EObject emfRootObject = resource.getContents().isEmpty() ? null : resource.getContents().get(0);
  resource.setParseResult(new ParseResult(emfRootObject, rootNode, false));

  // Add cache now, otherwise it will trigger model inference later.
  IResourceScopeCache cache = resource.getCache();
  if (cache instanceof OnChangeEvictingCache) {
    ((OnChangeEvictingCache) cache).getOrCreate(resource);
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:NodeModelHandler.java

示例4: readNodeModel

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
/**
 * Read the node model from the given input stream.
 *
 * @param resource
 *          target resource, must not be {@code null}
 * @param inputStream
 *          input stream, must not be {@code null}
 * @param content
 *          corresponding source content as required by node model, must not be {@code null}
 */
protected void readNodeModel(final StorageAwareResource resource, final InputStream inputStream, final String content) {
  try {
    // if this is a synthetic resource (i.e. tests or so, don't load the node model)
    if (!resource.getResourceSet().getURIConverter().exists(resource.getURI(), resource.getResourceSet().getLoadOptions())) {
      LOG.info("Skipping loading node model for synthetic resource " + resource.getURI()); //$NON-NLS-1$
      return;
    }
    DeserializationConversionContext deserializationContext = new FixedDeserializationConversionContext(resource, content);
    DataInputStream dataIn = new DataInputStream(inputStream);
    SerializableNodeModel serializableNodeModel = new SerializableNodeModel(resource);
    serializableNodeModel.readObjectData(dataIn, deserializationContext);
    resource.setParseResult(new ParseResult(resource.getContents().get(0), serializableNodeModel.root, deserializationContext.hasErrors()));
  } catch (IOException e) {
    LOG.error(e.getMessage(), e);
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:DirectLinkingResourceStorageLoadable.java

示例5: insertModel

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void insertModel(final byte[] modelData) throws IOException {
  ZippedByteArrayInputStream modelInputStream = new ZippedByteArrayInputStream(modelData);
  String completeSourceContent = resource.getSourceText();
  DeserializationConversionContext deserializationContext = new DeserializationConversionContext((XtextResource) resource, completeSourceContent);
  SerializableNodeModel nodeModel = new SerializableNodeModel();
  nodeModel.readObjectData(new DataInputStream(modelInputStream), deserializationContext);
  EObject emfRootObject = resource.getContents().isEmpty() ? null : resource.getContents().get(0);
  resource.setParseResult(new ParseResult(emfRootObject, nodeModel.root, deserializationContext.hasErrors()), true);
  modelInputStream.close();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:13,代码来源:NodeModelHandler.java

示例6: reparse

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
@Override
public IParseResult reparse(IParser parser, IParseResult previousParseResult, ReplaceRegion changedRegion) {
	if (isBrokenPreviousState(previousParseResult, changedRegion.getOffset())) {
		return fullyReparse(parser, previousParseResult, changedRegion);
	}
	ICompositeNode oldRootNode = previousParseResult.getRootNode();
	Iterator<ILeafNode> leafNodes = oldRootNode.getLeafNodes().iterator();
	ILeafNode leftNode = getLeftNode(leafNodes, changedRegion.getOffset());
	if (leftNode == null) {
		return fullyReparse(parser, previousParseResult, changedRegion);
	}
	ILeafNode rightNode = getRightNode(leafNodes, changedRegion.getEndOffset());
	if (rightNode == null) {
		return fullyReparse(parser, previousParseResult, changedRegion);
	}
	while(leafNodes.hasNext()) {
		if (leafNodes.next().getSyntaxErrorMessage() != null) {
			return fullyReparse(parser, previousParseResult, changedRegion);
		}
	}
	String originalText = oldRootNode.getText().substring(leftNode.getTotalOffset());
	StringBuilder newTextBuilder = new StringBuilder(originalText);
	changedRegion.shiftBy(-leftNode.getTotalOffset()).applyTo(newTextBuilder);
	String newText = newTextBuilder.toString();
	if (originalText.equals(newText)) {
		// nothing to do
		return previousParseResult;
	}
	int originalLength = rightNode.getTotalEndOffset() - leftNode.getTotalOffset();
	int expectedLength = originalLength - changedRegion.getLength() + changedRegion.getText().length();
	if (!isSameTokenSequence(originalText.substring(0, originalLength), newText, expectedLength)) {
		// different token sequence, cannot perform a partial parse run
		return fullyReparse(parser, previousParseResult, changedRegion);
	}
	
	PartialParsingPointers parsingPointers = calculatePartialParsingPointers(oldRootNode, leftNode, rightNode);
	ICompositeNode replaceMe = getReplacedNode(parsingPointers);
	if (replaceMe == null || replaceMe == oldRootNode || replaceMe.getOffset() == 0 && replaceMe.getEndOffset() == oldRootNode.getLength()) {
		return fullyReparse(parser, previousParseResult, changedRegion);
	}
	String reparseRegion = insertChangeIntoReplaceRegion(replaceMe, changedRegion);
	
	EObject oldSemanticElement = getOldSemanticElement(replaceMe, parsingPointers);
	if (oldSemanticElement == null)
		return fullyReparse(parser, previousParseResult, changedRegion);
	if (oldSemanticElement == replaceMe.getParent().getSemanticElement()) {
		throw new IllegalStateException("oldParent == oldElement");
	}
	
	IParseResult newParseResult = doParseRegion(parser, parsingPointers, replaceMe, reparseRegion);
	if (newParseResult == null) {
		throw new IllegalStateException("Could not perform a partial parse operation");
	}
	
	replaceOldSemanticElement(oldSemanticElement, previousParseResult, newParseResult);
	nodeModelBuilder.replaceAndTransferLookAhead(replaceMe, newParseResult.getRootNode());
	((ParseResult) newParseResult).setRootNode(oldRootNode);
	StringBuilder builder = new StringBuilder(oldRootNode.getText());
	changedRegion.applyTo(builder);
	nodeModelBuilder.setCompleteContent(oldRootNode, builder.toString());
	return newParseResult;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:63,代码来源:TokenSequencePreservingPartialParsingHelper.java

示例7: setParseResult

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
/**
 * Sets the parse result for this resource.
 *
 * @param parseResult
 *          the parse result containing the EMF and Node model, must not be {@code null}
 * @param refreshSyntaxErrors
 *          whether diagnostics should be created for syntax errors
 */
@Override
public void setParseResult(final ParseResult parseResult, final boolean refreshSyntaxErrors) {
  setParseResult(parseResult);
  if (refreshSyntaxErrors) {
    addSyntaxErrors();
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:16,代码来源:LazyLinkingResource2.java

示例8: setParseResult

import org.eclipse.xtext.parser.ParseResult; //导入依赖的package包/类
/**
 * Sets the parse result for this resource.
 * 
 * @param parseResult
 *          the parse result containing the EMF and Node model, must not be {@code null}
 * @param refreshSyntaxErrors
 *          whether diagnostics should be created for syntax errors
 */
void setParseResult(final ParseResult parseResult, final boolean refreshSyntaxErrors);
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:10,代码来源:ILazyLinkingResource2.java


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