org.eclipse.emf.ecore.EClassifier Java Examples

The following examples show how to use org.eclipse.emf.ecore.EClassifier. 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: Ecore2XtextExtensions.java    From xtext-core with 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 #2
Source File: DetailViewModelWizard.java    From neoscada with 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 #3
Source File: ProtocolModelWizard.java    From neoscada with 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 File: TokenTypeRewriter.java    From n4js with 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 #5
Source File: Ecore2XtextExtensions.java    From xtext-core with 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 #6
Source File: ProfileModelWizard.java    From neoscada with 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 #7
Source File: GrammarTest.java    From xtext-eclipse with 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 #8
Source File: EClassifierInfo.java    From xtext-core with 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 #9
Source File: TokenTypeRewriter.java    From n4js with 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 #10
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #11
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #12
Source File: ItemModelWizard.java    From neoscada with 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 #13
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #14
Source File: XtextGrammarRefactoringIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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 #15
Source File: AbstractTemplateVariableResolver.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 #16
Source File: BeansModelWizard.java    From hybris-commerce-eclipse-plugin with Apache License 2.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(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 #17
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #18
Source File: GrammarUtilTest.java    From xtext-core with 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 #19
Source File: EcoreUtil2.java    From xtext-core with 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 #20
Source File: NoBacktrackGrammarCodeElementExtractor.java    From sarl with Apache License 2.0 6 votes vote down vote up
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 #21
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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 #22
Source File: Step0001.java    From BIMserver with 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 #23
Source File: MetamodelImpl.java    From bonita-studio with 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 #24
Source File: ConfigurationModelWizard.java    From neoscada with 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 #25
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSingleFeatures() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals generate test \'http://test\' RuleA: featureA=INT;");
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  EClassifier _type = this.<EClassifier>type(ePackage, "RuleA");
  EClass ruleA = ((EClass) _type);
  Assert.assertNotNull(ruleA);
  Assert.assertEquals(1, ruleA.getEAttributes().size());
  this.assertAttributeConfiguration(ruleA, 0, "featureA", 
    "EInt");
}
 
Example #26
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isProposeParserRule(EClassifier eClassifier, Grammar grammar) {
	if (eClassifier instanceof EDataType && !((EDataType) eClassifier).isSerializable()) {
		return false;
	}
	return GrammarUtil.allParserRules(grammar)
			.stream()
			.filter(r -> r.getType() != null)
			.map(r -> r.getType().getClassifier())
			.allMatch(c -> !Objects.equals(c, eClassifier));
}
 
Example #27
Source File: TypeRefImpl.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 setClassifier(EClassifier newClassifier)
{
  EClassifier oldClassifier = classifier;
  classifier = newClassifier;
  if (eNotificationRequired())
    eNotify(new ENotificationImpl(this, Notification.SET, XtextTerminalsTestLanguagePackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
 
Example #28
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testParserRuleFragment_03() 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: IntFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment IntFeatureHolder: myFeature=INT NameFeatureHolder;");
  _builder.newLine();
  _builder.append("fragment NameFeatureHolder: name=STRING;");
  _builder.newLine();
  final String grammar = _builder.toString();
  EPackage ePackage = this.getEPackageFromGrammar(grammar);
  final EList<EClassifier> classifiers = ePackage.getEClassifiers();
  Assert.assertEquals(3, classifiers.size());
  final EClassifier myRuleType = IterableExtensions.<EClassifier>head(classifiers);
  Assert.assertEquals("MyRule", myRuleType.getName());
  Assert.assertTrue(this.features(myRuleType).isEmpty());
  final EClassifier intFeatureHolder = classifiers.get(1);
  Assert.assertEquals("EInt", this.<EStructuralFeature>feature(intFeatureHolder, "myFeature").getEType().getName());
  Assert.assertTrue(this.superTypes(myRuleType).contains(intFeatureHolder));
  final EClassifier nameFeatureHolder = IterableExtensions.<EClassifier>last(classifiers);
  Assert.assertEquals("EString", this.<EStructuralFeature>feature(nameFeatureHolder, "name").getEType().getName());
  Assert.assertTrue(this.superTypes(intFeatureHolder).contains(nameFeatureHolder));
}
 
Example #29
Source File: XSDSchemaReader.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void createGroup(XSModelGroupDecl modelGroupDecl) {
	EClass eClass = ecoreFactory.createEClass();
	eClass.setName(modelGroupDecl.getName());
	ePackage.getEClassifiers().add(eClass);
	for (XSParticle particle : modelGroupDecl.getModelGroup().getChildren()) {
		XSTerm term = particle.getTerm();
		if (term.isElementDecl()) {
			String name = term.asElementDecl().getName();
			EClassifier subClass = ePackage.getEClassifier(name);
			if (subClass != null && subClass instanceof EClass) {
				((EClass) subClass).getESuperTypes().add(eClass);
			}
		}
	}
}
 
Example #30
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<EClass> getAllClasses() {
	List<EClass> result = new ArrayList<>();
	for (EClassifier eClassifier : ePackage.getEClassifiers()) {
		if (eClassifier instanceof EClass) {
			result.add((EClass)eClassifier);
		}
	}
	return result;
}