Java Code Examples for org.eclipse.xtext.AbstractElement#eContainer()

The following examples show how to use org.eclipse.xtext.AbstractElement#eContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private List<String> getElementDescription(final AbstractElement element) {
  final ArrayList<String> result = new ArrayList<String>();
  AbstractElement container = element;
  while ((container != null)) {
    {
      result.addAll(0, this.getSingleElementDescription(container));
      final EObject eContainer = container.eContainer();
      AbstractElement _xifexpression = null;
      if ((eContainer instanceof AbstractElement)) {
        _xifexpression = ((AbstractElement)eContainer);
      } else {
        _xifexpression = null;
      }
      container = _xifexpression;
    }
  }
  return result;
}
 
Example 2
Source File: RequiredRuleNameComputer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.14
 */
protected String[][] getAdjustedRequiredRuleNames(Param param, AbstractElement elementToParse,
		String originalRuleName) {
	String adjustedRuleName = adjustRuleName(originalRuleName, param);
	if (!(GrammarUtil.isOptionalCardinality(elementToParse)
			|| GrammarUtil.isOneOrMoreCardinality(elementToParse))) {
		return new String[][] { { adjustedRuleName } };
	}
	EObject container = elementToParse.eContainer();
	if (container instanceof Group) {
		Group group = (Group) container;
		List<AbstractElement> filteredElements = getFilteredElements(group.getElements(), param);
		int idx = filteredElements.indexOf(elementToParse) + 1;
		if (idx != filteredElements.size()) {
			String adjustedSecondRule = getAdjustedSecondRule(param, group, idx);
			return getRuleNamesInGroup(param, elementToParse, adjustedRuleName, adjustedSecondRule);
		}
	}
	return new String[][] { { adjustedRuleName } };
}
 
Example 3
Source File: FixedPartialParsingHelper.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
private boolean hasMandatoryFollowElements(final AbstractElement lastParsedElement) {
  if (lastParsedElement.eContainer() instanceof AbstractElement) {
    AbstractElement directParent = (AbstractElement) lastParsedElement.eContainer();
    if (directParent instanceof Group) {
      Group group = (Group) directParent;
      int idx = group.getElements().indexOf(lastParsedElement) + 1;
      for (int i = idx; i < group.getElements().size(); i++) {
        if (isMandatory(group.getElements().get(i))) {
          return true;
        }
      }
    }
    return hasMandatoryFollowElements(directParent);
  }
  return false;
}
 
Example 4
Source File: ParamAwareEntryPointFinder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isMultipleCardinality(AbstractElement e) {
	if (GrammarUtil.isMultipleCardinality(e)) {
		return true;
	}
	if (e.eContainer() instanceof AbstractElement) {
		return isMultipleCardinality((AbstractElement) e.eContainer());
	}
	return false;
}
 
Example 5
Source File: GrammarAccessUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private static List<String> getElementDescription(AbstractElement element) {
	final ArrayList<String> result = new ArrayList<String>();
	AbstractElement container = element;
	while (container != null) {
		result.addAll(0, getSingleElementDescription(container));
		container = container.eContainer() instanceof AbstractElement ? (AbstractElement) container
				.eContainer()
				: null;
	}
	return result;
}
 
Example 6
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean hasMandatoryFollowElements(AbstractElement lastParsedElement) {
	if (lastParsedElement.eContainer() instanceof AbstractElement) {
		AbstractElement directParent = (AbstractElement) lastParsedElement.eContainer();
		if (directParent instanceof Group) {
			Group group = (Group) directParent;
			int idx = group.getElements().indexOf(lastParsedElement) + 1;
			for (int i = idx; i < group.getElements().size(); i++) {
				if (isMandatory(group.getElements().get(i)))
					return true;
			}
		}
		return hasMandatoryFollowElements(directParent);
	}
	return false;
}
 
Example 7
Source File: TreeConstructionNFAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean filter(AbstractElement grammarElement) {
	if (grammarElement.eContainer() instanceof AbstractRule)
		return false;
	if (EcoreUtil2.getContainerOfType(grammarElement.eContainer(), Assignment.class) != null)
		return true;

	return false;
}
 
Example 8
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String loadElementParentStatement(final AbstractElement ele) {
  String _xifexpression = null;
  EObject _eContainer = ele.eContainer();
  if ((_eContainer instanceof AbstractElement)) {
    EObject _eContainer_1 = ele.eContainer();
    _xifexpression = this.gaElementAccessorLocalVarName(((AbstractElement) _eContainer_1));
  } else {
    _xifexpression = "rule";
  }
  return _xifexpression;
}
 
Example 9
Source File: RequiredRuleNameComputer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Return the containing group if it contains exactly one element.
 * 
 * @since 2.14
 */
protected AbstractElement getEnclosingSingleElementGroup(AbstractElement elementToParse) {
	EObject container = elementToParse.eContainer();
	if (container instanceof Group) {
		if (((Group) container).getElements().size() == 1) {
			return (AbstractElement) container;
		}
	}
	return null;
}
 
Example 10
Source File: CfgAdapter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AbstractElement getParent(AbstractElement ele) {
	EObject cnt = ele.eContainer();
	return cnt instanceof AbstractElement ? (AbstractElement) cnt : null;
}