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


Java NodeModelUtils.getTokenText方法代码示例

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


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

示例1: validateReferencedMetamodel

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected void validateReferencedMetamodel(final ReferencedMetamodel ref) {
  if (((ref.getEPackage() != null) && (!ref.getEPackage().eIsProxy()))) {
    return;
  }
  final EReference eref = XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE;
  final List<INode> nodes = NodeModelUtils.findNodesForFeature(ref, eref);
  String _xifexpression = null;
  boolean _isEmpty = nodes.isEmpty();
  if (_isEmpty) {
    _xifexpression = "(unknown)";
  } else {
    _xifexpression = NodeModelUtils.getTokenText(nodes.get(0));
  }
  final String refName = _xifexpression;
  final String grammarName = GrammarUtil.getGrammar(ref).getName();
  final String msg = ((((("The EPackage " + refName) + " in grammar ") + grammarName) + " could not be found. ") + "You might want to register that EPackage in your workflow file.");
  throw new IllegalStateException(msg);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:XtextGeneratorLanguage.java

示例2: getConstant

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Tries to find {@link Constant} that my be defined in the same formatter or in any formatter that is extended by the current formatter.
 * An appropriate constant should be matched by comparing its name with the desired one.
 *
 * @param resourceSet
 *          to be used for loading
 * @param node
 *          parse subtree for the reference
 * @return A singleton list containing the desired constant, or an empty list if not found.
 */
private List<EObject> getConstant(final ResourceSet resourceSet, final INode node) {
  String constantFullyQualifiedName = NodeModelUtils.getTokenText(node);
  String formatName = URI.createURI(constantFullyQualifiedName).trimFileExtension().toString();
  if (formatName != null) {
    FormatConfiguration result = loadExtendedFormatConfiguration(formatName, resourceSet);
    if (result != null) {
      EList<Constant> constants = result.getConstants();
      for (Constant constant : constants) {
        if (constantFullyQualifiedName.equals(formatName + "." + constant.getName())) {
          return Collections.<EObject> singletonList(constant);
        }
      }
    }
  }
  return Collections.emptyList();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:FormatLinkingService.java

示例3: getParsedStringUnchecked

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns the source text assigned to the given feature of the given object. Does not work for multi-valued features. Optionally also converts the source
 * text using the corresponding value converter. Conversion is only performed for keywords, rule call or cross reference grammar rules.
 * <p>
 * This method does not perform a check to make sure the feature matches the given object.
 *
 * @param object
 *          the semantic object
 * @param feature
 *          the feature to be considered when parsing the parse tree model
 * @param convert
 *          {@code true} if the parsed string needs conversion using its value converter
 * @return the parsed string from the node model
 */
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
  INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
  if (node != null) {
    if (convert) {
      final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
      EObject grammarElement = node.getGrammarElement();
      if (res != null && (grammarElement instanceof Keyword || grammarElement instanceof RuleCall || grammarElement instanceof CrossReference)) {
        final DefaultLinkingService linkingService = (DefaultLinkingService) res.getLinkingService();
        return linkingService.getCrossRefNodeAsString(node);
      }
    }
    // result may contain escape sequences or quotes
    return NodeModelUtils.getTokenText(node);
  }
  return null;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:31,代码来源:ParseTreeUtil.java

示例4: getMessageWithLocation

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Returns this error's message with a suffix explaining where the error occurred if {@link #astNode} is given. This
 * method ignores field {@link #feature}.
 */
public String getMessageWithLocation() {
	if (astNode == null) {
		return message;
	}
	final INode node = NodeModelUtils.findActualNodeFor(astNode);
	final String tokenText = node != null ? NodeModelUtils.getTokenText(node) : null;
	if (tokenText == null) {
		return message;
	}
	return message + " at \"" + tokenText + "\"";
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:CompileTimeEvaluationError.java

示例5: getFirstNameSegment

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private String getFirstNameSegment(EObject owner, EReference reference) {
	List<INode> nodes = NodeModelUtils.findNodesForFeature(owner, reference);
	if (nodes.size() == 1) {
		String text = NodeModelUtils.getTokenText(nodes.get(0));
		return getFirstNameSegment(text);
	}
	throw new IllegalStateException("Cannot find node for feature");
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:TypeUsageCollector.java

示例6: _visit

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected void _visit(final JvmDeclaredType jvmType, final INode originNode, final ImportsAcceptor acceptor) {
  JvmDeclaredType _declaringType = jvmType.getDeclaringType();
  boolean _tripleEquals = (_declaringType == null);
  if (_tripleEquals) {
    this.collectTypeImportFrom(jvmType, acceptor);
  }
  final String text = NodeModelUtils.getTokenText(originNode);
  final String outerSegment = this.getFirstNameSegment(text);
  final JvmDeclaredType outerType = this.findDeclaringTypeBySimpleName(jvmType, outerSegment);
  if ((outerType == null)) {
    throw new IllegalStateException();
  }
  this.collectTypeImportFrom(outerType, acceptor);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:ImportsCollector.java

示例7: validateReferencedMetamodel

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * @since 2.3
 */
protected void validateReferencedMetamodel(ReferencedMetamodel ref) {
	if (ref.getEPackage() != null && !ref.getEPackage().eIsProxy())
		return;
	EReference eref = XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE;
	List<INode> nodes = NodeModelUtils.findNodesForFeature(ref, eref);
	String refName = nodes.isEmpty() ? "(unknown)" : NodeModelUtils.getTokenText(nodes.get(0));
	String grammarName = GrammarUtil.getGrammar(ref).getName();
	String msg = "The EPackage " + refName + " in grammar " + grammarName + " could not be found. ";
	msg += "You might want to register that EPackage in your workflow file.";
	throw new IllegalStateException(msg);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:LanguageConfig.java

示例8: createSequence

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
	SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
	while (ni.hasNext()) {
		Triple<INode, AbstractElement, EObject> node = ni.next();
		if (node.getSecond() instanceof RuleCall) {
			RuleCall rc = (RuleCall) node.getSecond();
			TypeRef ruleType = rc.getRule().getType();
			if (ruleType == null || ruleType.getClassifier() instanceof EClass)
				acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
			else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
				EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(),
						semanticObject.eClass());
				acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
			} else {
				String strVal = NodeModelUtils.getTokenText(node.getFirst());
				Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()),
						node.getFirst());
				acceptSemantic(semanticObject, rc, val, node.getFirst());
			}
		} else if (node.getSecond() instanceof Keyword)
			acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
		else if (node.getSecond() instanceof Action) {
			acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:28,代码来源:NodeModelSemanticSequencer.java

示例9: getExtendedFormatConfiguration

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Tries to find {@link FormatConfiguration} for the base formatter ({@code with} clause).
 *
 * @param resourceSet
 *          to be used for loading
 * @param node
 *          parse subtree for the reference
 * @return A singleton list containing the base format configuration, or an empty list if not found.
 */
private List<EObject> getExtendedFormatConfiguration(final ResourceSet resourceSet, final INode node) {
  String formatName = NodeModelUtils.getTokenText(node);
  if (formatName != null) {
    FormatConfiguration result = loadExtendedFormatConfiguration(formatName, resourceSet);
    if (result != null) {
      return Collections.<EObject> singletonList(result);
    }
  }
  return Collections.emptyList();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:20,代码来源:FormatLinkingService.java

示例10: createProxy

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * Creates the proxy with a custom encoded URI format (starting with "|"). The object used to produce the encoded
 * URI are collected as tuple inside {@link N4JSResource}. Then the node text is checked if it is convertible to a
 * valid value. If there is a {@link BadEscapementException} is thrown then there is either a warning or an error
 * produced via the diagnosticProducer.
 *
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param node
 *            the node representing the EObject
 * @param eRef
 *            the cross reference in the domain model
 * @param xref
 *            the cross reference in the node model
 * @param diagnosticProducer
 *            to produce errors or warnings
 * @return the created proxy
 */
private EObject createProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref,
		IDiagnosticProducer diagnosticProducer) {
	final URI uri = resource.getURI();
	/*
	 * as otherwise with 0 the EObjectDescription created for Script would be fetched
	 */
	final int fragmentNumber = resource.addLazyProxyInformation(obj, eRef, node);
	final URI encodedLink = uri.appendFragment("|" + fragmentNumber);
	EClass referenceType = findInstantiableCompatible(eRef.getEReferenceType());
	final EObject proxy = EcoreUtil.create(referenceType);
	((InternalEObject) proxy).eSetProxyURI(encodedLink);
	AbstractElement terminal = xref.getTerminal();
	if (!(terminal instanceof RuleCall)) {
		throw new IllegalArgumentException(String.valueOf(xref));
	}
	AbstractRule rule = ((RuleCall) terminal).getRule();
	try {
		String tokenText = NodeModelUtils.getTokenText(node);
		Object value = valueConverterService.toValue(tokenText, rule.getName(), node);
		if (obj instanceof IdentifierRef && value instanceof String) {
			((IdentifierRef) obj).setIdAsText((String) value);
		} else if (obj instanceof LabelRef && value instanceof String) {
			((LabelRef) obj).setLabelAsText((String) value);
		} else if (obj instanceof ParameterizedPropertyAccessExpression && value instanceof String) {
			((ParameterizedPropertyAccessExpression) obj).setPropertyAsText((String) value);
		} else if (obj instanceof NamedImportSpecifier && value instanceof String) {
			((NamedImportSpecifier) obj).setImportedElementAsText((String) value);
		} else if ((obj instanceof JSXPropertyAttribute) && (value instanceof String)) {
			((JSXPropertyAttribute) obj).setPropertyAsText((String) value);
		} else {
			setOtherElementAsText(tokenText, obj, value);
		}
	} catch (BadEscapementException e) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), e.getSeverity(), e.getIssueCode(),
				Strings.EMPTY_ARRAY));
	} catch (N4JSValueConverterException vce) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(vce.getMessage(), vce.getSeverity(),
				vce.getIssueCode(), Strings.EMPTY_ARRAY));
	} catch (N4JSValueConverterWithValueException vcwve) {
		diagnosticProducer.addDiagnostic(new DiagnosticMessage(vcwve.getMessage(), vcwve.getSeverity(),
				vcwve.getIssueCode(), Strings.EMPTY_ARRAY));
	}
	return proxy;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:66,代码来源:N4JSLinker.java

示例11: getSourceText

import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
 * <b>Attention:</b> This call is expensive due to the nested call to
 * {@link NodeModelUtils#getTokenText(org.eclipse.xtext.nodemodel.INode)}
 *
 * @return label text that is the actual text from the source code.
 */
public static String getSourceText(EObject eo) {
	ICompositeNode actualNode = NodeModelUtils.findActualNodeFor(eo);
	String text = NodeModelUtils.getTokenText(actualNode);
	return text;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:12,代码来源:FGUtils.java


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