org.eclipse.xtext.TypeRef Java Examples

The following examples show how to use org.eclipse.xtext.TypeRef. 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: XtextLinkingService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
	final ICompositeNode parentNode = text.getParent();
	BidiIterator<INode> iterator = parentNode.getChildren().iterator();
	while(iterator.hasPrevious()) {
		INode child = iterator.previous();
		if (child instanceof ILeafNode) {
			ILeafNode leaf = (ILeafNode) child;
			if (text == leaf)
				return super.getLinkedObjects(context, ref, text);
			if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
				IScope scope = getScope(context, ref);
				return XtextMetamodelReferenceHelper.findBestMetamodelForType(
						context, text.getText(), leaf.getText(), scope);
			}
		}
	}
	return Collections.emptyList();
}
 
Example #2
Source File: ActionImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case XtextPackage.ACTION__TYPE:
			setType((TypeRef)null);
			return;
		case XtextPackage.ACTION__FEATURE:
			setFeature(FEATURE_EDEFAULT);
			return;
		case XtextPackage.ACTION__OPERATOR:
			setOperator(OPERATOR_EDEFAULT);
			return;
	}
	super.eUnset(featureID);
}
 
Example #3
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private EClassifierInfo findOrCreateEClassifierInfo(TypeRef typeRef, String name, boolean createIfMissing) throws TransformationException {
	if (typeRef.getClassifier() != null && typeRef.getMetamodel() == null)
		throw new TransformationException(TransformationErrorCode.UnknownMetaModelAlias,
				"Cannot find EPackage for type '" + typeRef.getClassifier().getName() + "'", typeRef);
	EClassifierInfo info = eClassifierInfos.getInfo(typeRef);
	if (info == null) {
		// we assumend EString for terminal rules and datatype rules, so
		// we have to do a look up in super grammar
		EDataType dataType = GrammarUtil.findEString(GrammarUtil.getGrammar(typeRef));
		if (dataType != null && typeRef.getClassifier() == dataType) {
			info = eClassifierInfos.getInfoOrNull(typeRef);
			if (info != null)
				return info;
		}
		if (createIfMissing)
			info = createEClassifierInfo(typeRef, name);
	}
	return info;
}
 
Example #4
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the invocation of an element or rule accessor, including the .getType() call.
 * Example1: getFooRule().getType()
 * Example2: getBarRule().getFooAction().getType()
 */
public String gaTypeAccessor(final TypeRef ele) {
  String _switchResult = null;
  EObject _eContainer = ele.eContainer();
  final EObject cnt = _eContainer;
  boolean _matched = false;
  if (cnt instanceof AbstractElement) {
    _matched=true;
    String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement)cnt));
    _switchResult = (_gaRuleElementAccessor + ".getType()");
  }
  if (!_matched) {
    if (cnt instanceof AbstractRule) {
      _matched=true;
      String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule)cnt));
      _switchResult = (_gaRuleAccessor + ".getType()");
    }
  }
  if (!_matched) {
    String _name = ele.eContainer().eClass().getName();
    String _plus = ("<error: unknown type " + _name);
    _switchResult = (_plus + ">");
  }
  return _switchResult;
}
 
Example #5
Source File: ActionImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case XtextPackage.ACTION__TYPE:
			setType((TypeRef)newValue);
			return;
		case XtextPackage.ACTION__FEATURE:
			setFeature((String)newValue);
			return;
		case XtextPackage.ACTION__OPERATOR:
			setOperator((String)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #6
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void addSuperType(ParserRule rule, TypeRef subTypeRef, EClassifierInfo superTypeInfo) throws TransformationException {
	final EClassifier subType = subTypeRef.getClassifier();
	final EClassifierInfo subTypeInfo = subType == null
	        ? findOrCreateEClassifierInfo(subTypeRef, null, true)
			: eClassifierInfos.getInfoOrNull(subType);
	if (subTypeInfo == null)
		throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Type '"
				+ superTypeInfo.getEClassifier().getName() + "' is not available.", rule.getType());
	if (superTypeInfo.isAssignableFrom(subTypeInfo))
		return;
	if (subTypeInfo.getEClassifier() instanceof EDataType)
		throw new TransformationException(TransformationErrorCode.InvalidSupertype, "Cannot add supertype '"
				+ superTypeInfo.getEClassifier().getName() + "' to simple datatype '"
				+ subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
	if (!subTypeInfo.isGenerated())
		throw new TransformationException(TransformationErrorCode.CannotCreateTypeInSealedMetamodel,
				"Cannot add supertype '" + superTypeInfo.getEClassifier().getName() + "' to sealed type '"
						+ subTypeInfo.getEClassifier().getName() + "'.", rule.getType());
	subTypeInfo.addSupertype(superTypeInfo);
}
 
Example #7
Source File: XtextMetamodelReferenceHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
static List<EObject> findBestMetamodelForType(TypeRef context, final String alias, String typeName, IScope scope) {
	final List<AbstractMetamodelDeclaration> generatedMetamodels = new ArrayList<AbstractMetamodelDeclaration>();
	final List<AbstractMetamodelDeclaration> importedMetamodels = new ArrayList<AbstractMetamodelDeclaration>();
	filterMetamodelsInScope(alias, scope, generatedMetamodels, importedMetamodels);
	final List<AbstractMetamodelDeclaration> exactMatches = new ArrayList<AbstractMetamodelDeclaration>();
	filterExactMatches(alias, importedMetamodels, exactMatches);
	List<EObject> result = findReferencedMetamodelWithType(typeName, exactMatches);
	if (result != null)
		return result;
	result = findReferencedMetamodelWithType(typeName, importedMetamodels);
	if (result != null)
		return result;
	result = findSingleElementInCollections(alias, generatedMetamodels);
	if (result != null)
		return result;
	result = findSingleElementInCollections(alias, importedMetamodels);
	if (result != null)
		return result;
	return Collections.emptyList();
}
 
Example #8
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private TypeRef getOrComputeReturnType(AbstractRule rule) {
	TypeRef result = rule.getType();
	if (result == null) {
		EClassifier classifier = getClassifierFor(rule);
		if (classifier == null) {
			if (rule.getName() == null)
				return null;
			result = getTypeRef(rule.getName());
		} else
			result = getTypeRef(classifier);
		if (result.getMetamodel() == null) {
			AbstractMetamodelDeclaration bestMatch = null;
			for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
				if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
					bestMatch = decl;
					break;
				}
			}
			if (result.getMetamodel() == null)
				result.setMetamodel(bestMatch);
		}
		rule.setType(result);
	}
	return result;
}
 
Example #9
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_05() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	typeRef.setClassifier(EcorePackage.Literals.EOBJECT);
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setType(typeRef);
	ruleCall.setRule(parserRule);
	Assignment assignment = XtextFactory.eINSTANCE.createAssignment();
	assignment.setTerminal(ruleCall);
	unorderedGroup.getElements().add(assignment);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #10
Source File: EClassifierInfos.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public EClassifierInfo getInfo(TypeRef typeRef) {
	if (typeRef.getClassifier() == null)
		return null;
	EClassifierInfo result = getInfo(typeRef.getMetamodel(), typeRef.getClassifier().getName());
	if (result == null) {
		Grammar declaringGrammar = GrammarUtil.getGrammar(typeRef);
		if (grammar.equals(declaringGrammar))
			return result;
		for(EClassifierInfos parent: parents) {
			result = parent.getInfo(typeRef);
			if (result != null)
				return result;
		}
	}
	return result;
}
 
Example #11
Source File: AbstractRuleImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case XtextPackage.ABSTRACT_RULE__NAME:
			setName((String)newValue);
			return;
		case XtextPackage.ABSTRACT_RULE__TYPE:
			setType((TypeRef)newValue);
			return;
		case XtextPackage.ABSTRACT_RULE__ALTERNATIVES:
			setAlternatives((AbstractElement)newValue);
			return;
		case XtextPackage.ABSTRACT_RULE__ANNOTATIONS:
			getAnnotations().clear();
			getAnnotations().addAll((Collection<? extends Annotation>)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #12
Source File: TreeConstState.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void populateTypes(Map<TreeConstState, List<TreeConstState>> map) {
	typesDirty = false;
	List<TreeConstState> origins = map.get(this);
	if (origins != null)
		for (TreeConstState origin : origins) {
			Set<TypeRef> t = types;
			if (origin.getGrammarElement() instanceof Action
					&& ((Action) origin.getGrammarElement()).getFeature() != null)
				t = Collections.emptySet();
			else if (t.contains(null) && origin.isConsumingElement()) {
				t = Sets.newLinkedHashSet(t);
				t.remove(null);
				if (origin.getGrammarElement() instanceof Assignment)
					t.add(GrammarUtil.containingRule(origin.getGrammarElement()).getType());
			}
			if (origin.getTypes().addAll(t) || origin.typesDirty)
				origin.populateTypes(map);
		}
}
 
Example #13
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Not a full featured solution for the computation of available structural features, but it is sufficient for some
 * interesting 85%.
 */
@Override
public void completeAssignment_Feature(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	AbstractRule rule = EcoreUtil2.getContainerOfType(model, AbstractRule.class);
	TypeRef typeRef = rule.getType();
	if (typeRef != null && typeRef.getClassifier() instanceof EClass) {
		Iterable<EStructuralFeature> features = ((EClass) typeRef.getClassifier()).getEAllStructuralFeatures();
		Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
		Iterable<String> processedFeatures = completeStructuralFeatures(context, factory, acceptor, features);
		if(rule.getType().getMetamodel() instanceof GeneratedMetamodel) {
			if(notNull(rule.getName()).toLowerCase().startsWith("import")) {
				completeSpecialAttributeAssignment("importedNamespace", 2, processedFeatures, factory, context, acceptor); 
				completeSpecialAttributeAssignment("importURI", 1, processedFeatures, factory, context, acceptor); 
			} else {
				completeSpecialAttributeAssignment("name", 3, processedFeatures, factory, context, acceptor); 
			}
		}
	}
	super.completeAssignment_Feature(model, assignment, context, acceptor);
}
 
Example #14
Source File: XtextLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private String getClassifierName(TypeRef ref) {
	String classifierName = UNKNOWN;
	if (ref != null) {
		if (ref.getClassifier() != null)
			classifierName = ref.getClassifier().getName();
		else {
			ICompositeNode node = NodeModelUtils.getNode(ref);
			if (node != null) {
				List<ILeafNode> leafs = Lists.newArrayList(node.getLeafNodes());
				for (int i = leafs.size() - 1; i >= 0; i--) {
					if (!leafs.get(i).isHidden()) {
						classifierName = leafs.get(i).getText();
						break;
					}
				}
			}
		}
	}
	return classifierName;
}
 
Example #15
Source File: InheritanceTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testMetamodel() throws Exception {
	AbstractRule rule = GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "OverridableParserRule2");
	assertNotNull("rule", rule);
	TypeRef ref = rule.getType();
	assertNotNull("ref", ref);
	final EClass clazz = (EClass) ref.getClassifier();
	assertNotNull("class", clazz);
	assertEquals("AType2", clazz.getName());
	assertEquals(2, clazz.getESuperTypes().size());
	Set<String> expectedNames = new HashSet<String>(Arrays.asList(new String[]{"AType", "RootRule"}));
	Iterator<String> iter = Iterables.transform(clazz.getESuperTypes(), new Function<EClass, String>(){
		@Override
		public String apply(EClass param) {
			return param.getName();
		}
	}).iterator();
	while(iter.hasNext()) {
		String name = iter.next();
		assertTrue("name = '" + name + "'", expectedNames.remove(name));
	}
	assertTrue(expectedNames.toString(), expectedNames.isEmpty());
}
 
Example #16
Source File: AbstractRuleImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case XtextPackage.ABSTRACT_RULE__NAME:
			setName(NAME_EDEFAULT);
			return;
		case XtextPackage.ABSTRACT_RULE__TYPE:
			setType((TypeRef)null);
			return;
		case XtextPackage.ABSTRACT_RULE__ALTERNATIVES:
			setAlternatives((AbstractElement)null);
			return;
		case XtextPackage.ABSTRACT_RULE__ANNOTATIONS:
			getAnnotations().clear();
			return;
	}
	super.eUnset(featureID);
}
 
Example #17
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug318424_01() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	reference.setType(typeRef);
	typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkCrossReferenceType(reference);
	messageAcceptor.validate();
}
 
Example #18
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug318424_02() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	Action action = XtextFactory.eINSTANCE.createAction();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	action.setType(typeRef);
	typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkInstantiatedType(action);
	messageAcceptor.validate();
}
 
Example #19
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_02() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	typeRef.setClassifier(EcorePackage.Literals.EBIG_DECIMAL);
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setType(typeRef);
	ruleCall.setRule(parserRule);
	unorderedGroup.getElements().add(ruleCall);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #20
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTypesOfImplicitSuperGrammar() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate test \'http://test\'");
  _builder.newLine();
  _builder.append("MyRule: myFeature=INT;");
  _builder.newLine();
  final String xtextGrammar = _builder.toString();
  EObject _model = this.getModel(xtextGrammar);
  final Grammar grammar = ((Grammar) _model);
  final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
  transformer.removeGeneratedPackages();
  transformer.transform();
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  TypeRef type = rule.getType();
  Assert.assertNotNull(type);
  Assert.assertNotNull(transformer.getEClassifierInfos().getInfo(type));
  AbstractMetamodelDeclaration _get = GrammarUtil.allMetamodelDeclarations(grammar).get(1);
  final ReferencedMetamodel referenced = ((ReferencedMetamodel) _get);
  Assert.assertNotNull(referenced);
  Assert.assertEquals("ecore", referenced.getAlias());
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EString"));
  Assert.assertNull(transformer.getEClassifierInfos().getInfo(referenced, "EInt"));
  EClassifierInfos parentInfos = IterableExtensions.<EClassifierInfos>head(transformer.getEClassifierInfos().getParents());
  Assert.assertNotNull(parentInfos.getInfo(referenced, "EString"));
  Assert.assertNotNull(parentInfos.getInfo(referenced, "EInt"));
}
 
Example #21
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_01() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
	typeRef.setClassifier(EcorePackage.Literals.EOBJECT);
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setType(typeRef);
	ruleCall.setRule(parserRule);
	unorderedGroup.getElements().add(ruleCall);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(ruleCall, true, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #22
Source File: TreeConstTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void assertTypes(Collection<TypeRef> actual, String... expected) {
	Set<String> refs = Sets.newHashSet();
	for (TypeRef t : actual)
		refs.add(t == null ? "null" : t.getClassifier().getName());
	Set<String> actual2 = Sets.newHashSet(refs);
	for (String e : expected) {
		if (refs.contains(e))
			refs.remove(e);
		else
			fail("Type '" + e + "' not found. Actual:" + actual2 + " Expected: " + Joiner.on(", ").join(expected));
	}
	if (!refs.isEmpty())
		fail("Types '" + refs + "' are not expected. Actual:" + actual2 + " Expected: " + Joiner.on(", ").join(expected));
}
 
Example #23
Source File: NodeModelSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
		}
	}
}
 
Example #24
Source File: AbstractRuleImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetType(TypeRef newType, NotificationChain msgs) {
	TypeRef oldType = type;
	type = newType;
	if (eNotificationRequired()) {
		ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ABSTRACT_RULE__TYPE, oldType, newType);
		if (msgs == null) msgs = notification; else msgs.add(notification);
	}
	return msgs;
}
 
Example #25
Source File: CrossReferenceImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case XtextPackage.CROSS_REFERENCE__TYPE:
			setType((TypeRef)null);
			return;
		case XtextPackage.CROSS_REFERENCE__TERMINAL:
			setTerminal((AbstractElement)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #26
Source File: CrossReferenceImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case XtextPackage.CROSS_REFERENCE__TYPE:
			setType((TypeRef)newValue);
			return;
		case XtextPackage.CROSS_REFERENCE__TERMINAL:
			setTerminal((AbstractElement)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #27
Source File: CrossReferenceImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setType(TypeRef newType) {
	if (newType != type) {
		NotificationChain msgs = null;
		if (type != null)
			msgs = ((InternalEObject)type).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XtextPackage.CROSS_REFERENCE__TYPE, null, msgs);
		if (newType != null)
			msgs = ((InternalEObject)newType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XtextPackage.CROSS_REFERENCE__TYPE, null, msgs);
		msgs = basicSetType(newType, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.CROSS_REFERENCE__TYPE, newType, newType));
}
 
Example #28
Source File: CrossReferenceImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetType(TypeRef newType, NotificationChain msgs) {
	TypeRef oldType = type;
	type = newType;
	if (eNotificationRequired()) {
		ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.CROSS_REFERENCE__TYPE, oldType, newType);
		if (msgs == null) msgs = notification; else msgs.add(notification);
	}
	return msgs;
}
 
Example #29
Source File: ContextTypePDAProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EClass getInstantiatedType(AbstractElement element) {
	TypeRef type = null;
	if (GrammarUtil.isAssigned(element) || GrammarUtil.isEObjectFragmentRuleCall(element)) {
		type = GrammarUtil.containingRule(element).getType();
	} else if (element instanceof Action) {
		type = ((Action) element).getType();
	}
	if (type != null) {
		EClassifier classifier = type.getClassifier();
		if (classifier instanceof EClass && !classifier.eIsProxy()) {
			return (EClass) classifier;
		}
	}
	return null;
}
 
Example #30
Source File: FlattenedGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private TypeRef copyTypeRef(TypeRef ref) {
	if (ref == null)
		return null;
	TypeRef copy = copy(ref);
	copy.setClassifier(ref.getClassifier());
	return copy;
}