Java Code Examples for org.eclipse.emf.ecore.EClassifier

The following examples show how to use org.eclipse.emf.ecore.EClassifier. These examples are extracted from open source projects. 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 Project: n4js   Source File: TokenTypeRewriter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier instanceof EClass
							&& TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
						builder.put(assignment, TYPE_REF_TOKEN);
					}
				}
			}
		}
	}
}
 
Example 2
Source Project: n4js   Source File: TokenTypeRewriter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
						builder.put(assignment, NUMBER_LITERAL_TOKEN);
					}
				}
			}
		}
	}
}
 
Example 3
Source Project: neoscada   Source File: ProtocolModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the types that can be created as the root object.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EClassifier eClassifier : protocolPackage.getEClassifiers () )
        {
            if ( eClassifier instanceof EClass )
            {
                EClass eClass = (EClass)eClassifier;
                if ( !eClass.isAbstract () )
                {
                    initialObjectNames.add ( eClass.getName () );
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 4
Source Project: neoscada   Source File: DetailViewModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the types that can be created as the root object.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EClassifier eClassifier : detailViewPackage.getEClassifiers () )
        {
            if ( eClassifier instanceof EClass )
            {
                EClass eClass = (EClass)eClassifier;
                if ( !eClass.isAbstract () )
                {
                    initialObjectNames.add ( eClass.getName () );
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 5
Source Project: neoscada   Source File: ProfileModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the types that can be created as the root object.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EClassifier eClassifier : profilePackage.getEClassifiers () )
        {
            if ( eClassifier instanceof EClass )
            {
                EClass eClass = (EClass)eClassifier;
                if ( !eClass.isAbstract () )
                {
                    initialObjectNames.add ( eClass.getName () );
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 6
@Test
public void testBug_266440() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate bugreport \'http://bugreport/266440\'");
  _builder.newLine();
  _builder.append("CompositeModel: (type+=EClassifier)+;");
  _builder.newLine();
  _builder.append("EClassifier: EDataType | EClass;");
  _builder.newLine();
  _builder.append("EClass: \'class\' name=ID;");
  _builder.newLine();
  _builder.append("EDataType: \'dt\' name=ID;");
  String grammar = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammar);
  Assert.assertTrue(resource.getErrors().isEmpty());
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar parsedGrammar = ((Grammar) _head);
  EList<AbstractRule> _rules = parsedGrammar.getRules();
  for (final AbstractRule rule : _rules) {
    {
      final EClassifier classifier = rule.getType().getClassifier();
      EPackage pack = classifier.getEPackage();
      Assert.assertEquals("bugreport", pack.getName());
    }
  }
}
 
Example 7
@Test
public void testAddingDifferentFeaturesWithSameName01() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append(" ");
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\'");
  _builder.append(" RuleA returns TypeA: featureA=ID; RuleB returns TypeA: featureA=INT;");
  final String grammar = _builder.toString();
  this.errorAcceptorMock.acceptError(TransformationErrorCode.NoCompatibleFeatureTypeAvailable, 
    TestErrorAcceptor.ANY_STRING, TestErrorAcceptor.ANY_EOBJECT);
  EPackage ePackage = this.getEPackageFromGrammar(grammar, 1);
  Assert.assertEquals(1, ePackage.getEClassifiers().size());
  EClassifier _type = this.<EClassifier>type(ePackage, "TypeA");
  EClass typeA = ((EClass) _type);
  Assert.assertNotNull(typeA);
  Assert.assertEquals(1, typeA.getEAttributes().size());
  this.assertAttributeConfiguration(typeA, 0, "featureA", 
    "EString");
}
 
Example 8
Source Project: neoscada   Source File: ItemModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the types that can be created as the root object.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EClassifier eClassifier : itemPackage.getEClassifiers () )
        {
            if ( eClassifier instanceof EClass )
            {
                EClass eClass = (EClass)eClassifier;
                if ( !eClass.isAbstract () )
                {
                    initialObjectNames.add ( eClass.getName () );
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 9
Source Project: neoscada   Source File: ConfigurationModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the features representing global elements.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EStructuralFeature eStructuralFeature : ExtendedMetaData.INSTANCE.getAllElements ( ExtendedMetaData.INSTANCE.getDocumentRoot ( configurationPackage ) ) )
        {
            if ( eStructuralFeature.isChangeable () )
            {
                EClassifier eClassifier = eStructuralFeature.getEType ();
                if ( eClassifier instanceof EClass )
                {
                    EClass eClass = (EClass)eClassifier;
                    if ( !eClass.isAbstract () )
                    {
                        initialObjectNames.add ( eStructuralFeature.getName () );
                    }
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 10
Source Project: bonita-studio   Source File: MetamodelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public EModelElement getElement(String name) {
	final EPackage p = getEPackage(name);
	if (p != null) {
		return p;
	}
	final EClassifier c = getEClassifier(name);
	if (c != null) {
		return c;
	}
	final EStructuralFeature f = getEFeature(name);
	if (f != null) {
		return f;
	}
	return null;
}
 
Example 11
private <T> T visitTypeReferencingMembers(EObject grammarContainer, EObject container,
		Function4<? super CodeElementExtractor, ? super EObject, ? super EObject, ? super EClassifier, ? extends T> memberCallback) {
	final Set<String> treatedMembers = new HashSet<>();
	for (final Assignment nameAssignment : IterableExtensions.filter(
			GrammarUtil.containedAssignments(container), passignment -> getCodeBuilderConfig()
			.getUnnamedMemberExtensionGrammarNames().contains(passignment.getFeature()))) {
		// Get the container of the name assignment
		final EObject assignmentContainer = getContainerInRule(grammarContainer, nameAssignment);
		if (assignmentContainer != null) {
			final EClassifier classifier = getGeneratedTypeFor(assignmentContainer);
			if (!treatedMembers.contains(classifier.getName())) {
				treatedMembers.add(classifier.getName());
				final T retVal = memberCallback.apply(this, grammarContainer, assignmentContainer, classifier);
				if (retVal != null) {
					return retVal;
				}
			}
		}
	}
	return null;
}
 
Example 12
Source Project: xtext-core   Source File: EcoreUtil2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.1
 */
public static EClassifier getCompatibleType(EClassifier typeA, EClassifier typeB, EObject grammarContext) {
	if (typeA.equals(typeB))
		return typeA;
	if (typeA instanceof EDataType && typeB instanceof EDataType) {
		Class<?> instanceClassA = typeA.getInstanceClass();
		Class<?> instanceClassB = typeB.getInstanceClass();
		if (instanceClassA != null && instanceClassB != null) {
			if (instanceClassA.isAssignableFrom(instanceClassB))
				return typeA;
			if (instanceClassB.isAssignableFrom(instanceClassA))
				return typeB;
		}
	}
	
	// no common type for simple datatypes available
	if (!(typeA instanceof EClass && typeB instanceof EClass))
		return null;

	List<EClass> sortedCandidates = getSortedCommonCompatibleTypeCandidates((EClass) typeA, (EClass) typeB);
	for (EClass candidate : sortedCandidates)
		if (isCommonCompatibleType(candidate, sortedCandidates))
			return candidate;
	EClass result = GrammarUtil.findEObject(GrammarUtil.getGrammar(grammarContext));
	return result;
}
 
Example 13
public EEnumLiteral getEEnumLiteral(String enumName, String literalName) {
	EClassifier eClassifier = ePackage.getEClassifier(enumName);
	if (eClassifier == null) {
		throw new RuntimeException("Classifier " + enumName + " not found in package " + ePackage.getName());
	}
	if (eClassifier instanceof EEnum) {
		EEnum eEnum = (EEnum)eClassifier;
		EEnumLiteral literal = eEnum.getEEnumLiteral(literalName);
		if (literal == null) {
			throw new RuntimeException("No enum literal " + literalName + " found on " + ePackage.getName() + "." + enumName);
		}
		return literal;
	} else {
		throw new RuntimeException("Classifier " + enumName + " is not of type enum");
	}
}
 
Example 14
Source Project: xtext-core   Source File: Ecore2XtextExtensions.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static boolean needsDispatcherRule(final EClassifier eClassifier) {
  boolean _switchResult = false;
  boolean _matched = false;
  if (eClassifier instanceof EClass) {
    _matched=true;
    final Function1<EClass, Boolean> _function = (EClass c) -> {
      return Boolean.valueOf(Ecore2XtextExtensions.needsConcreteRule(c));
    };
    boolean _isEmpty = IterableExtensions.isEmpty(IterableExtensions.<EClass>filter(Ecore2XtextExtensions.subClasses(((EClass)eClassifier)), _function));
    _switchResult = (!_isEmpty);
  }
  if (!_matched) {
    _switchResult = false;
  }
  return _switchResult;
}
 
Example 15
@Test
public void testGenerateTwoModels() throws Exception {
  String grammar = "";
  String _grammar = grammar;
  grammar = (_grammar + " grammar test with org.eclipse.xtext.common.Terminals");
  String _grammar_1 = grammar;
  grammar = (_grammar_1 + " generate t1 \'http://t1\'");
  String _grammar_2 = grammar;
  grammar = (_grammar_2 + " generate t2 \'http://t2\' as t2");
  String _grammar_3 = grammar;
  grammar = (_grammar_3 + " RuleA: featureA=ID;");
  String _grammar_4 = grammar;
  grammar = (_grammar_4 + " RuleB returns t2::TypeB: featureB=ID;");
  List<EPackage> ePackages = this.getEPackagesFromGrammar(grammar, 0);
  Assert.assertEquals(2, ePackages.size());
  EPackage t1 = IterableExtensions.<EPackage>head(ePackages);
  Assert.assertEquals("t1", t1.getName());
  Assert.assertEquals(1, t1.getEClassifiers().size());
  final EClassifier ruleA = this.<EClassifier>type(t1, "RuleA");
  Assert.assertNotNull(ruleA);
  EPackage t2 = ePackages.get(1);
  Assert.assertEquals(1, t2.getEClassifiers().size());
  Assert.assertEquals("t2", t2.getName());
  final EClassifier typeB = this.<EClassifier>type(t2, "TypeB");
  Assert.assertNotNull(typeB);
}
 
Example 16
Source Project: BIMserver   Source File: Step0001.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
	public void migrate(Schema schema, DatabaseSession databaseSession) {
		schema.loadEcore("ifc2x3_tc1.ecore", getClass().getResourceAsStream("IFC2X3_TC1.ecore"));
		for (EClassifier eClassifier : schema.getEPackage("ifc2x3tc1").getEClassifiers()) {
			if (eClassifier instanceof EClass) {
				EClass eClass = (EClass)eClassifier;
				for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
					if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
						// A hack because unfortunately not every "Name" field inherits from IfcRoot.Name, same could be true for GlobalId
						if (eStructuralFeature.getName().equals("Name") || eStructuralFeature.getName().equals("GlobalId")) {
//							System.out.println(eClass.getName() + "." + eStructuralFeature.getName());
							schema.addIndex(eStructuralFeature);
						}
					}
				}
			}
		}
	}
 
Example 17
Source Project: xtext-core   Source File: Ecore2XtextExtensions.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static void allAssignedClassifiers(final EClass eClazz, final Collection<EClassifier> acceptor) {
  final Function1<EStructuralFeature, Boolean> _function = (EStructuralFeature f) -> {
    return Boolean.valueOf(Ecore2XtextExtensions.needsAssignment(f));
  };
  final Function1<EStructuralFeature, EClassifier> _function_1 = (EStructuralFeature it) -> {
    return it.getEType();
  };
  final List<EClassifier> classifiers = IterableExtensions.<EClassifier>toList(IterableExtensions.<EStructuralFeature, EClassifier>map(IterableExtensions.<EStructuralFeature>filter(eClazz.getEAllStructuralFeatures(), _function), _function_1));
  Iterable<EClass> _subClasses = Ecore2XtextExtensions.subClasses(eClazz);
  Iterables.<EClassifier>addAll(classifiers, _subClasses);
  classifiers.removeAll(acceptor);
  boolean _isEmpty = classifiers.isEmpty();
  if (_isEmpty) {
    return;
  } else {
    Iterables.<EClassifier>addAll(acceptor, classifiers);
    final Consumer<EClass> _function_2 = (EClass c) -> {
      Ecore2XtextExtensions.allAssignedClassifiers(c, acceptor);
    };
    Iterables.<EClass>filter(classifiers, EClass.class).forEach(_function_2);
  }
}
 
Example 18
Source Project: xtext-eclipse   Source File: GrammarTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private AbstractRule checkConcreteImplRule(Grammar grammar, String ruleName) {
	AbstractRule concreteRule = GrammarUtil.findRuleForName(grammar, ruleName);
	assertNotNull(concreteRule);
	EClassifier returnType = ((ParserRule)concreteRule).getType().getClassifier();
	String returnTypeName = getClassifierName(returnType);
	assertEquals(ruleName, returnTypeName + "_Impl");
	List<Assignment> assignments = GrammarUtil.containedAssignments(concreteRule);
	assertEquals(1, assignments.size());
	assertEquals("name", assignments.get(0).getFeature());
	assertEquals("=", assignments.get(0).getOperator());
	List<Action> containedActions = GrammarUtil.containedActions(concreteRule);
	assertEquals(1, containedActions.size());
	assertEquals(returnTypeName, getClassifierName(containedActions.get(0).getType().getClassifier()));
	List<Keyword> containedKeywords = GrammarUtil.containedKeywords(concreteRule);
	assertEquals(1, containedKeywords.size());
	assertEquals(returnTypeName, containedKeywords.get(0).getValue());
	return concreteRule;
}
 
Example 19
@Test
public void testRefactorXtextGrammarWithGeneratedClassifier() throws Exception {
	ResourceSet rs = resourceSetProvider.get();
	Resource ecoreResource = createEcoreModel(rs, ecoreURI, initialModelRoot);
	final EClass greetingClass = getGreetingClass(ecoreResource);
	final EReference greetingRef = getReferenceoGreeting(ecoreResource, greetingClass);
	String greetingClassFragment = EcoreUtil.getURI(greetingClass).fragment();
	String greetingRefFragment = EcoreUtil.getURI(greetingRef).fragment();
	ecoreResource.unload();
	waitForBuild();
	final XtextEditor editor = openEditor(grammarFile);
	doRefactoring(editor);
	waitForBuild();
	checkConsistenceOfGrammar(editor);
	ecoreResource.load(null);
	assertEquals(REFACTOREDCLASSIFIERNAME, SimpleAttributeResolver.NAME_RESOLVER.apply(ecoreResource
			.getEObject(greetingClassFragment.replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME))));
	EReference greetingReference = (EReference) ecoreResource.getEObject(greetingRefFragment);
	EClassifier eType = greetingReference.getEType();
	assertFalse(eType.eIsProxy());
	assertEquals(REFACTOREDCLASSIFIERNAME, eType.getName());
}
 
Example 20
protected EClassifier getEClassifierForGrammar(String fqnClassName,
		Grammar grammar) {
	int dotIndex = fqnClassName.indexOf('.');
	String packageName = null;
	String className = fqnClassName;
	if (dotIndex > 0) {
		packageName = fqnClassName.substring(0, dotIndex);
		className = fqnClassName.substring(dotIndex + 1);
	}
	List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil
			.allMetamodelDeclarations(grammar);
	for (AbstractMetamodelDeclaration decl : allMetamodelDeclarations) {
		EPackage pack = decl.getEPackage();
		if (packageName == null || pack.getName().equals(packageName)) {
			EClassifier eClassifier = pack.getEClassifier(className);
			if (eClassifier != null) {
				return eClassifier;
			}
		}
	}
	return null;
}
 
Example 21
/**
 * Returns the names of the features representing global elements.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames() {
	if (initialObjectNames == null) {
		initialObjectNames = new ArrayList<String>();
		for (EStructuralFeature eStructuralFeature : ExtendedMetaData.INSTANCE.getAllElements(ExtendedMetaData.INSTANCE.getDocumentRoot(beansPackage))) {
			if (eStructuralFeature.isChangeable()) {
				EClassifier eClassifier = eStructuralFeature.getEType();
				if (eClassifier instanceof EClass) {
					EClass eClass = (EClass)eClassifier;
					if (!eClass.isAbstract()) {
						initialObjectNames.add(eStructuralFeature.getName());
					}
				}
			}
		}
		Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator());
	}
	return initialObjectNames;
}
 
Example 22
Source Project: xtext-core   Source File: GrammarUtilTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFindCurrentType_04() throws Exception {
  this.with(XtextStandaloneSetup.class);
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate g \'http://1\'");
  _builder.newLine();
  _builder.append("Rule:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment: name=ID SecondFragment?;");
  _builder.newLine();
  _builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
 
Example 23
@Test
public void testFeaturesAndInheritanceMandatoryRuleCall() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\' RuleA: RuleB featureA=INT; RuleB: featureB=STRING;");
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  Assert.assertEquals(2, ePackage.getEClassifiers().size());
  EClassifier _type = this.<EClassifier>type(ePackage, "RuleA");
  EClass ruleA = ((EClass) _type);
  Assert.assertNotNull(ruleA);
  EClassifier _type_1 = this.<EClassifier>type(ePackage, "RuleB");
  EClass ruleB = ((EClass) _type_1);
  Assert.assertNotNull(ruleB);
  Assert.assertEquals(0, ruleA.getEAttributes().size());
  Assert.assertEquals(2, ruleB.getEAttributes().size());
  this.assertAttributeConfiguration(ruleB, 0, "featureA", "EInt");
  this.assertAttributeConfiguration(ruleB, 1, "featureB", 
    "EString");
}
 
Example 24
Source Project: xtext-core   Source File: EClassifierInfo.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private EStructuralFeature createFeatureWith(String featureName, EClassifier featureClassifier,
		boolean isMultivalue, boolean isContainment) {
	EStructuralFeature newFeature;

	if (featureClassifier instanceof EClass) {
		EReference reference = EcoreFactory.eINSTANCE.createEReference();
		reference.setContainment(isContainment);
		newFeature = reference;
	} else {
		newFeature = EcoreFactory.eINSTANCE.createEAttribute();
	}
	newFeature.setName(featureName);
	newFeature.setEType(featureClassifier);
	newFeature.setLowerBound(0);
	newFeature.setUpperBound(isMultivalue ? -1 : 1);
	newFeature.setUnique(!isMultivalue || (isContainment && featureClassifier instanceof EClass));
	if (newFeature.getEType() instanceof EEnum) {
		newFeature.setDefaultValue(null);
	}
	return newFeature;
}
 
Example 25
@Override
public void getEClassRequirements(Set<EClass> classRequirements) {
	for (EClassifier eClassifier : eClass.getEPackage().getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			EClass foundEClass = (EClass)eClassifier;
			if (eClass.isSuperTypeOf(foundEClass)) {
				classRequirements.add(foundEClass);
			}
		}
	}
}
 
Example 26
Source Project: n4js   Source File: EcoreUtilN4Test.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private EPackage epack(String n, EObject... contents) {
	EPackage p = EcoreFactory.eINSTANCE.createEPackage();
	p.setName(n);

	for (EObject eobj : contents) {
		if (eobj instanceof EPackage) {
			p.getESubpackages().add((EPackage) eobj);
		} else {
			p.getEClassifiers().add((EClassifier) eobj);
		}
	}

	return p;
}
 
Example 27
Source Project: xtext-core   Source File: TypeRefImpl.java    License: 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 XtextTestPackage.TYPE_REF__METAMODEL:
      setMetamodel((AbstractMetamodelDeclaration)null);
      return;
    case XtextTestPackage.TYPE_REF__CLASSIFIER:
      setClassifier((EClassifier)null);
      return;
  }
  super.eUnset(featureID);
}
 
Example 28
Source Project: xtext-core   Source File: GenModelUtil2.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static String getJavaTypeName(final EClassifier classifier, final ResourceSet resourceSet) {
  final GenClassifier genClassifier = GenModelUtil2.getGenClassifier(classifier, resourceSet);
  if ((genClassifier instanceof GenClass)) {
    return ((GenClass)genClassifier).getQualifiedInterfaceName();
  } else {
    return ((GenDataType) genClassifier).getQualifiedInstanceClassName();
  }
}
 
Example 29
@Test
public void testOptionalAssignmentsInGroup() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\' RuleA: (featureA?=\'abstract\' featureB+=INT)?;");
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  Assert.assertEquals(1, ePackage.getEClassifiers().size());
  EClassifier _type = this.<EClassifier>type(ePackage, "RuleA");
  EClass ruleA = ((EClass) _type);
  Assert.assertNotNull(ruleA);
  Assert.assertEquals(2, ruleA.getEAttributes().size());
  this.assertAttributeConfiguration(ruleA, 0, "featureA", "EBoolean", 0, 1);
  this.assertAttributeConfiguration(ruleA, 1, "featureB", "EInt", 0, 
    (-1));
}
 
Example 30
Source Project: xtext-core   Source File: Inheritance2Test.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testReturnTypes_01() {
	ParserRule rule = grammarAccess.getModelRule();
	EClassifier classifier = rule.getType().getClassifier();
	assertEquals("Model", classifier.getName());
	EPackage pack = classifier.getEPackage();
	assertNotNull(pack);
	assertEquals(grammarAccess.getGrammar().getMetamodelDeclarations().get(0).getEPackage(), pack);
	EClassifier superClassifier = ((EClass)classifier).getESuperTypes().get(0);
	assertEquals("Model", superClassifier.getName());
	EPackage superPack = superClassifier.getEPackage();
	assertNotNull(superPack);
	assertEquals(grammarAccess.getGrammar().getUsedGrammars().get(0).getMetamodelDeclarations().get(0).getEPackage(), superPack);
}