本文整理汇总了Java中org.eclipse.xtext.nodemodel.util.NodeModelUtils.findNodesForFeature方法的典型用法代码示例。如果您正苦于以下问题:Java NodeModelUtils.findNodesForFeature方法的具体用法?Java NodeModelUtils.findNodesForFeature怎么用?Java NodeModelUtils.findNodesForFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.nodemodel.util.NodeModelUtils
的用法示例。
在下文中一共展示了NodeModelUtils.findNodesForFeature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGetNode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected INode doGetNode(EObject object, EStructuralFeature feature, int idx) {
if (object == null)
return null;
if (feature == null) {
INode result = NodeModelUtils.findActualNodeFor(object);
if (result != null) {
return result;
}
return doGetNode(object.eContainer(), object.eContainmentFeature(), -1);
}
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(object, feature);
if (nodesForFeature.isEmpty()) {
return doGetNode(object, null, -1);
}
if (idx == -1 /* INSIGNIFICANT_INDEX */) {
idx = 0;
}
if (nodesForFeature.size() > idx ) {
return nodesForFeature.get(idx);
}
return doGetNode(object, null, -1);
}
示例2: getLegacyImportSyntax
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public String getLegacyImportSyntax(XImportDeclaration importDeclaration) {
List<INode> list = NodeModelUtils.findNodesForFeature(importDeclaration, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE);
if (list.isEmpty()) {
return null;
}
INode singleNode = list.get(0);
if (singleNode.getText().indexOf('$') < 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for(ILeafNode node: singleNode.getLeafNodes()) {
if (!node.isHidden()) {
sb.append(node.getText().replace("^", ""));
}
}
return sb.toString();
}
示例3: getNodeForModifier
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Returns the INode for a given modifier. This is intended for computing error message regions, quick fixes, etc.
*/
public static final ILeafNode getNodeForModifier(ModifiableElement elem, int index) {
final List<INode> nodes = NodeModelUtils.findNodesForFeature(elem,
N4JSPackage.eINSTANCE.getModifiableElement_DeclaredModifiers());
if (index >= 0 && index < nodes.size()) {
final Iterable<ILeafNode> leafNodes = nodes.get(index).getLeafNodes();
for (ILeafNode currLeaf : leafNodes) {
if (!currLeaf.isHidden())
return currLeaf;
}
}
return null;
}
示例4: getPropertyAsString
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
private String getPropertyAsString(ParameterizedPropertyAccessExpression propAccessExpr) {
final StringBuilder sb = new StringBuilder();
for (INode node : NodeModelUtils.findNodesForFeature(propAccessExpr,
N4JSPackage.eINSTANCE.getParameterizedPropertyAccessExpression_Property())) {
sb.append(NodeModelUtils.getTokenText(node));
}
return sb.toString();
}
示例5: test_05
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void test_05() throws Exception {
Model model = (Model) getModel("model id { element withNumbers01 }");
assertEquals("id", model.getName());
Element element = model.getElements().get(0);
assertEquals("withNumbers01", element.getName());
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(element, InheritanceTestPackage.Literals.ELEMENT__NAME);
assertTrue(nodesForFeature.size() == 1);
assertEquals("withNumbers01", nodesForFeature.get(0).getText());
}
示例6: getFirstParseTreeNode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Gets the first node from the parse tree for given semantic object and structural feature.
*
* @param semanticElement
* the semantic element
* @param feature
* the structural feature
* @return the first parse tree node or {@code null} if none found
*/
private INode getFirstParseTreeNode(final EObject semanticElement, final EStructuralFeature feature) {
if (feature == null) {
return NodeModelUtils.findActualNodeFor(semanticElement);
}
List<INode> nodes = NodeModelUtils.findNodesForFeature(semanticElement, feature);
if (!nodes.isEmpty()) {
return nodes.get(0);
}
return null;
}
示例7: test_02
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void test_02() throws Exception {
Model model = (Model) getModel("model id { element inheritedIdSyntax }");
assertEquals("id", model.getName());
Element element = model.getElements().get(0);
assertEquals("inheritedIdSyntax", element.getName());
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(element, InheritanceTestPackage.Literals.ELEMENT__NAME);
assertTrue(nodesForFeature.size() == 1);
assertEquals("inheritedIdSyntax", nodesForFeature.get(0).getText());
}
示例8: test_03
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void test_03() throws Exception {
Model model = (Model) getModel("model id { element 'string' }");
assertEquals("id", model.getName());
Element element = model.getElements().get(0);
assertEquals("string", element.getName());
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(element, InheritanceTestPackage.Literals.ELEMENT__NAME);
assertTrue(nodesForFeature.size() == 1);
assertEquals("'string'", nodesForFeature.get(0).getText());
}
示例9: getImportedTypeName
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public String getImportedTypeName() {
String result = getImportedNamespace();
if (result == null) {
if (this.eIsSet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE)) {
JvmType unresolvedType = (JvmType) this.eGet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, false);
if(!unresolvedType.eIsProxy())
return unresolvedType.getIdentifier();
List<INode> list = NodeModelUtils.findNodesForFeature(this,
XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE);
StringBuilder sb = new StringBuilder();
for (INode iNode : list) {
sb.append(NodeModelUtils.getTokenText(iNode).replace("^", ""));
}
result = sb.toString().replace(" ", "");
if (isStatic()) {
return trim(result, 1);
}
return result;
}
return null;
}
if (isWildcard()) {
return trim(result, 2);
}
return result;
}
示例10: getCrossReferenceNode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected INode getCrossReferenceNode(EObject context, EReference reference, EObject target) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(context, reference);
if (!nodes.isEmpty()) {
if (reference.isMany()) {
int index = ((List<?>) context.eGet(reference, false)).indexOf(target);
if (index >= 0 && index < nodes.size())
return nodes.get(index);
} else {
return nodes.get(0);
}
}
return null;
}
示例11: test_01
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void test_01() throws Exception {
Model model = (Model) getModel("model id { element id }");
assertEquals("id", model.getName());
Element element = model.getElements().get(0);
assertEquals("id", element.getName());
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(element, InheritanceTestPackage.Literals.ELEMENT__NAME);
assertTrue(nodesForFeature.size() == 1);
assertEquals("id", nodesForFeature.get(0).getText());
}
示例12: highlightFeature
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Highlights an object at the position of the given {@link EStructuralFeature}
*/
protected void highlightFeature(IHighlightedPositionAcceptor acceptor, EObject object, EStructuralFeature feature,
String... styleIds) {
List<INode> children = NodeModelUtils.findNodesForFeature(object, feature);
if (children.size() > 0)
highlightNode(acceptor, children.get(0), styleIds);
}
示例13: testAssignment_rhs_01
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testAssignment_rhs_01() throws Exception {
String text = "a=b";
XAssignment assignment = (XAssignment) expression(text);
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(assignment, XbasePackage.Literals.XASSIGNMENT__VALUE);
assertEquals(1, nodesForFeature.size());
String nodeText = nodesForFeature.get(0).getText();
assertEquals("b", nodeText);
}
示例14: testAssignment_rhs_02
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testAssignment_rhs_02() throws Exception {
String text = "a=b+=c";
XAssignment assignment = (XAssignment) expression(text);
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(assignment, XbasePackage.Literals.XASSIGNMENT__VALUE);
assertEquals(1, nodesForFeature.size());
String nodeText = nodesForFeature.get(0).getText();
assertEquals("b+=c", nodeText);
}
示例15: testAssignment_rhs_03
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testAssignment_rhs_03() throws Exception {
String text = "a=b+=c";
XBinaryOperation assignment = (XBinaryOperation) ((XAssignment) expression(text)).getValue();
List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(assignment, XbasePackage.Literals.XBINARY_OPERATION__RIGHT_OPERAND);
assertEquals(1, nodesForFeature.size());
String nodeText = nodesForFeature.get(0).getText();
assertEquals("c", nodeText);
}