Java Code Examples for org.eclipse.xtext.EcoreUtil2#typeSelect()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#typeSelect() . 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: FjTypeSystem.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
protected List<Field> applyAuxFunFields(final RuleApplicationTrace _trace_, final org.eclipse.xsemantics.example.fj.fj.Class clazz) throws RuleFailedException {
  ArrayList<Field> _xblockexpression = null;
  {
    Iterable<Field> fields = new ArrayList<Field>();
    List<org.eclipse.xsemantics.example.fj.fj.Class> _superclasses = this.superclassesInternal(_trace_, clazz);
    for (final org.eclipse.xsemantics.example.fj.fj.Class superclass : _superclasses) {
      List<Field> _typeSelect = EcoreUtil2.<Field>typeSelect(superclass.getMembers(), Field.class);
      Iterable<Field> _plus = Iterables.<Field>concat(_typeSelect, fields);
      fields = _plus;
    }
    List<Field> _typeSelect_1 = EcoreUtil2.<Field>typeSelect(clazz.getMembers(), Field.class);
    Iterable<Field> _plus_1 = Iterables.<Field>concat(fields, _typeSelect_1);
    fields = _plus_1;
    _xblockexpression = (Lists.<Field>newArrayList(fields));
  }
  return _xblockexpression;
}
 
Example 2
Source File: ImportManager.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void registerSimpleNamesOfInnerClasses(JvmDeclaredType thisType, LinkedHashSet<JvmType> handled) {
	if (!handled.add(thisType))
		return;
	List<JvmDeclaredType> nested = EcoreUtil2.typeSelect(thisType.getMembers(), JvmDeclaredType.class);
	for (JvmDeclaredType jvmDeclaredType : nested) {
		getThisTypeSimpleNames().add(jvmDeclaredType.getSimpleName());
		getThisTypeQualifiedNames().add(jvmDeclaredType.getQualifiedName(getInnerTypeSeparator()));
		thisCollidesWithJavaLang |= CodeGenUtil2.isJavaLangType(jvmDeclaredType.getSimpleName());
	}
	for (JvmTypeReference superType: thisType.getSuperTypes()) {
		if (superType.getType() instanceof JvmDeclaredType) {
			registerSimpleNamesOfInnerClasses((JvmDeclaredType) superType.getType(), handled);
		}
	}
}
 
Example 3
Source File: JavaValidatorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<Object> getParameters(Grammar grammar) {
	List<String> packageQNames = new ArrayList<String>();
	List<GeneratedMetamodel> list = EcoreUtil2.typeSelect(grammar.getMetamodelDeclarations(),
			GeneratedMetamodel.class);
	for (GeneratedMetamodel generatedMetamodel : list) {
		packageQNames.add(getGeneratedEPackageName(grammar, getNaming(), generatedMetamodel.getEPackage()));
	}
	List<Object> parameters = Lists.newArrayList((Object) packageQNames);
	parameters.add(this.composedChecks);
	parameters.add(getValidatorSuperClassName(grammar));
	return parameters;
}
 
Example 4
Source File: Generator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void checkConfigurationInternal(Issues issues) {
	naming.setProjectNameRt(getProjectNameRt());
	naming.setProjectNameIde(getProjectNameIde());
	naming.setIdeBasePackage(!isIde() && isUi() ? getProjectNameUi() : getProjectNameIde());
	naming.setProjectNameUi(getProjectNameUi());
	naming.setUiBasePackage(getProjectNameUi());
	naming.setActivatorName(getActivator());
	naming.setPathTestProject(getPathTestProject());
	naming.setFileHeader(getFileHeader());
	naming.setClassAnnotations(getClassAnnotationsAsString());
	naming.setAnnotationImports(getAnnotationImportsAsString());
	naming.setHasUI(isUi());
	naming.setHasIde(isIde());
	Map<String, Grammar> uris = new HashMap<String, Grammar>();
	for (LanguageConfig config : languageConfigs) {
		config.registerNaming(naming);
		config.checkConfiguration(issues);
		Grammar grammar = config.getGrammar();
		List<GeneratedMetamodel> select = EcoreUtil2.typeSelect(grammar.getMetamodelDeclarations(),
				GeneratedMetamodel.class);
		for (GeneratedMetamodel generatedMetamodel : select) {
			String nsURI = generatedMetamodel.getEPackage().getNsURI();
			if (uris.containsKey(nsURI)) {
				issues.addError("Duplicate generated grammar with nsURI '" + nsURI + "' in "
						+ uris.get(nsURI).getName() + " and " + grammar.getName());
			} else {
				uris.put(nsURI, grammar);
			}
		}
	}
	if (getProjectNameRt() == null)
		issues.addError("The property 'projectNameRt' is mandatory");
	if (isUiMergedIntoRt() && getPathIdeProject() != null && ! isIdeMergedIntoRt()) {
		issues.addError("Cannot have a dedicated ide project when ui project is merged into runtime project");
	}
}
 
Example 5
Source File: DefaultOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _createChildren(EStructuralFeatureNode parentNode, EObject modelElement) {
	Object values = modelElement.eGet(parentNode.getEStructuralFeature());
	if (values != null) {
		if (parentNode.getEStructuralFeature().isMany()) {
			for (EObject value : EcoreUtil2.typeSelect((List<?>) values, EObject.class)) {
				createNode(parentNode, value);
			}
		} else {
			if (values instanceof EObject)
				createNode(parentNode, (EObject) values);
		}
	}
}
 
Example 6
Source File: BackgroundOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void internalCreateChildren(EStructuralFeatureNode parentNode, EObject modelElement) {
	Object values = modelElement.eGet(parentNode.getEStructuralFeature());
	if (values != null) {
		if (parentNode.getEStructuralFeature().isMany()) {
			for (EObject value : EcoreUtil2.typeSelect((List<?>) values, EObject.class)) {
				createNode(parentNode, value);
			}
		} else {
			if (values instanceof EObject)
				createNode(parentNode, (EObject) values);
		}
	}
}
 
Example 7
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private Set<String> getGeneratedEPackageURIs() {
	List<GeneratedMetamodel> list = EcoreUtil2.typeSelect(grammar.getMetamodelDeclarations(), GeneratedMetamodel.class);
	return Sets.newLinkedHashSet(Iterables.transform(list, new Function<GeneratedMetamodel, String>() {
		@Override
		public String apply(GeneratedMetamodel from) {
			return from.getEPackage()!=null?from.getEPackage().getNsURI() : null;
		}
	}));
}
 
Example 8
Source File: FjTypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected List<Method> applyAuxFunMethods(final RuleApplicationTrace _trace_, final org.eclipse.xsemantics.example.fj.fj.Class clazz) throws RuleFailedException {
  List<Method> _xblockexpression = null;
  {
    final List<Method> methods = EcoreUtil2.<Method>typeSelect(clazz.getMembers(), Method.class);
    final Consumer<org.eclipse.xsemantics.example.fj.fj.Class> _function = new Consumer<org.eclipse.xsemantics.example.fj.fj.Class>() {
      public void accept(final org.eclipse.xsemantics.example.fj.fj.Class c) {
        methods.addAll(EcoreUtil2.<Method>typeSelect(c.getMembers(), Method.class));
      }
    };
    this.superclassesInternal(_trace_, clazz).forEach(_function);
    _xblockexpression = (methods);
  }
  return _xblockexpression;
}
 
Example 9
Source File: FjFirstTypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<List<Field>> applyRuleFields(final RuleEnvironment G, final RuleApplicationTrace _trace_, final org.eclipse.xsemantics.example.fj.fj.Class cl) throws RuleFailedException {
  List<Field> fields = null; // output parameter
  final List<org.eclipse.xsemantics.example.fj.fj.Class> superclasses = this.superclassesInternal(_trace_, cl);
  Collections.reverse(superclasses);
  fields = CollectionLiterals.<Field>newArrayList();
  for (final org.eclipse.xsemantics.example.fj.fj.Class superclass : superclasses) {
    List<Field> _typeSelect = EcoreUtil2.<Field>typeSelect(
      superclass.getMembers(), 
      Field.class);
    Iterables.<Field>addAll(fields, _typeSelect);
  }
  /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) or true */
  {
    RuleFailedException previousFailure = null;
    try {
      List<Field> _typeSelect_1 = EcoreUtil2.<Field>typeSelect(
        cl.getMembers(), 
        Field.class);
      boolean _add = Iterables.<Field>addAll(fields, _typeSelect_1);
      /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) */
      if (!_add) {
        sneakyThrowRuleFailedException("fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) )");
      }
    } catch (Exception e) {
      previousFailure = extractRuleFailedException(e);
      /* true */
    }
  }
  return new Result<List<Field>>(fields);
}
 
Example 10
Source File: FjFirstTypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<List<Field>> applyRuleFields(final RuleEnvironment G, final RuleApplicationTrace _trace_, final org.eclipse.xsemantics.example.fj.fj.Class cl) throws RuleFailedException {
  List<Field> fields = null; // output parameter
  final List<org.eclipse.xsemantics.example.fj.fj.Class> superclasses = this.superclassesInternal(_trace_, cl);
  Collections.reverse(superclasses);
  fields = CollectionLiterals.<Field>newArrayList();
  for (final org.eclipse.xsemantics.example.fj.fj.Class superclass : superclasses) {
    List<Field> _typeSelect = EcoreUtil2.<Field>typeSelect(
      superclass.getMembers(), 
      Field.class);
    Iterables.<Field>addAll(fields, _typeSelect);
  }
  /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) or true */
  {
    RuleFailedException previousFailure = null;
    try {
      List<Field> _typeSelect_1 = EcoreUtil2.<Field>typeSelect(
        cl.getMembers(), 
        Field.class);
      boolean _add = Iterables.<Field>addAll(fields, _typeSelect_1);
      /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) */
      if (!_add) {
        sneakyThrowRuleFailedException("fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) )");
      }
    } catch (Exception e) {
      previousFailure = extractRuleFailedException(e);
      /* true */
    }
  }
  return new Result<List<Field>>(fields);
}
 
Example 11
Source File: FjFirstTypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<List<Field>> applyRuleFields(final RuleEnvironment G, final RuleApplicationTrace _trace_, final org.eclipse.xsemantics.example.fj.fj.Class cl) throws RuleFailedException {
  List<Field> fields = null; // output parameter
  final List<org.eclipse.xsemantics.example.fj.fj.Class> superclasses = this.superclassesInternal(_trace_, cl);
  Collections.reverse(superclasses);
  fields = CollectionLiterals.<Field>newArrayList();
  for (final org.eclipse.xsemantics.example.fj.fj.Class superclass : superclasses) {
    List<Field> _typeSelect = EcoreUtil2.<Field>typeSelect(
      superclass.getMembers(), 
      Field.class);
    Iterables.<Field>addAll(fields, _typeSelect);
  }
  /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) or true */
  {
    RuleFailedException previousFailure = null;
    try {
      List<Field> _typeSelect_1 = EcoreUtil2.<Field>typeSelect(
        cl.getMembers(), 
        Field.class);
      boolean _add = Iterables.<Field>addAll(fields, _typeSelect_1);
      /* fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) ) */
      if (!_add) {
        sneakyThrowRuleFailedException("fields += EcoreUtil2::typeSelect( cl.members, typeof(Field) )");
      }
    } catch (Exception e) {
      previousFailure = extractRuleFailedException(e);
      /* true */
    }
  }
  return new Result<List<Field>>(fields);
}
 
Example 12
Source File: FjAuxiliaryFunctions.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
public List<Field> selectFields(Class cl) {
	return EcoreUtil2.typeSelect(
			cl.getMembers(), Field.class);
}
 
Example 13
Source File: FjAuxiliaryFunctions.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
public List<Method> selectMethods(Class cl) {
	return EcoreUtil2.typeSelect(
			cl.getMembers(), Method.class);
}