Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#getRootContainer()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#getRootContainer() . 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
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * 
 * @generated NOT
 */
protected ExecutionContext getExecutionContext() {
	if (!(EcoreUtil.getRootContainer(this) instanceof GeneratorModel)) {
		return new ExecutionContextImpl();
	}
	ExecutionContext context = new ExecutionContextImpl();
	GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getRootContainer(this);
	EList<Property> properties = generatorModel.getProperties();
	for (Property propertyDefinition : properties) {
		ExecutionVariable variable = SRuntimeFactory.eINSTANCE.createExecutionVariable();
		variable.setName(propertyDefinition.getName());
		variable.setFqName(propertyDefinition.getName());
		variable.setType(propertyDefinition.getType());
		variable.setValue(interpreter.evaluate(propertyDefinition.getInitialValue(), context));
		context.getSlots().add(variable);
	}
	return context;
}
 
Example 2
Source Project: n4js   File: OriginAwareScope.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Enhanced query-Method marking the originating import as used.
 *
 * @see org.eclipse.xtext.scoping.IScope#getSingleElement(org.eclipse.xtext.naming.QualifiedName)
 */
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	IEObjectDescription ret = delegatee.getSingleElement(name);
	if (ret == null)
		return null;

	ImportSpecifier origin = origins.get(ret);
	if (origin != null) {
		EObject script = EcoreUtil.getRootContainer(origin);
		if ((script instanceof Script) && ((Script) script).isFlaggedUsageMarkingFinished()) {
			// do nothing as linking phase is over
		} else {
			// return usage aware description
			return getUsageAwareDescription(ret);
		}
	}
	return ret;
}
 
Example 3
protected void warning(String message, String issueCode, JvmParameterizedTypeReference typeReference) {
	EObject rootContainer = EcoreUtil.getRootContainer(typeReference);
	Resource resource = rootContainer.eResource();
	if (resource.getContents().get(0) == rootContainer) {
		super.warning(message, typeReference, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, issueCode);
	} else {
		EObject container = typeReference;
		EObject sourceElement = jvmModelAssociations.getPrimarySourceElement(container);
		container = container.eContainer();
		while(sourceElement == null && container != null) {
			sourceElement = jvmModelAssociations.getPrimarySourceElement(container);
			container = container.eContainer();
		}
		if (sourceElement != null) {
			warning(message, sourceElement, sourceElement.eClass().getEStructuralFeature("name"), -1, issueCode);
		} else {
			super.warning(message, typeReference, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, issueCode);
		}
	}
}
 
Example 4
protected void error(String message, String issueCode, JvmParameterizedTypeReference typeReference) {
	EObject rootContainer = EcoreUtil.getRootContainer(typeReference);
	Resource resource = rootContainer.eResource();
	if (resource.getContents().get(0) == rootContainer) {
		super.error(message, typeReference, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, issueCode);
	} else {
		EObject container = typeReference;
		EObject sourceElement = jvmModelAssociations.getPrimarySourceElement(container);
		container = container.eContainer();
		while(sourceElement == null && container != null) {
			sourceElement = jvmModelAssociations.getPrimarySourceElement(container);
			container = container.eContainer();
		}
		if (sourceElement != null) {
			error(message, sourceElement, sourceElement.eClass().getEStructuralFeature("name"), -1, issueCode);
		} else {
			super.error(message, typeReference, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, -1, issueCode);
		}
	}
}
 
Example 5
public static void remove(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelIndexImpl existingIndex = (GModelIndexImpl) EcoreUtil.getExistingAdapter(root, GModelIndexImpl.class);
	if (existingIndex == null) {
		return;
	}
	existingIndex.unsetTarget(root);
}
 
Example 6
public static void remove(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelChangeNotifierImpl existingNotifier = (GModelChangeNotifierImpl) EcoreUtil.getExistingAdapter(root,
			GModelChangeNotifierImpl.class);
	if (existingNotifier == null) {
		return;
	}
	existingNotifier.unsetTarget(root);
}
 
Example 7
public String fullQfn(NamedElement element) {
	List<String> qfnFragments = new ArrayList<String>();
	qfnFragments.add(element.getName());
	EObject current = element;
	while (current.eContainer() != EcoreUtil.getRootContainer(current)) {
		current = current.eContainer();
		if (current instanceof NamedElement) {
			String name = ((NamedElement) current).getName();
			if (name != null) {
				qfnFragments.add(name.replaceAll(" ", ""));
			} else {
				qfnFragments.add("<name>");
			}
		}
	}
	Collections.reverse(qfnFragments);
	StringBuilder sb = new StringBuilder();

	sb.append(element.getName() != null ? element.getName() : element.eClass().getName());
	sb.append("  (");
	String sep = "";
	for (String s : qfnFragments) {
		sb.append(sep).append(s);
		sep = ".";
	}
	sb.append(")");

	sb.append(" resource: ");
	sb.append(element.eResource().getURI().lastSegment());
	return sb.toString();
}
 
Example 8
protected List<EObject> getEntryPoints(EObject object) {
	EObject rootContainer = EcoreUtil.getRootContainer(object);
	if (rootContainer instanceof XExpression) {
		return Collections.singletonList(rootContainer);	
	}
	return Collections.emptyList();
}
 
Example 9
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
	if(EcoreUtil.getRootContainer(context) != context) 
		return Collections.emptyList();
	XImportSection importSection = importsConfiguration.getImportSection((XtextResource) context.eResource());
	if(importSection != null) {
		return getImportedNamespaceResolvers(importSection, ignoreCase);
	}
	return Collections.emptyList();
}
 
Example 10
protected Grammar getGrammar(XtextTemplateContext xtextTemplateContext) {
	EObject grammarElement = xtextTemplateContext.getContentAssistContext()
			.getRootNode().getGrammarElement();
	if (grammarElement == null && grammarAccess != null)
		return grammarAccess.getGrammar();
	return (Grammar) EcoreUtil.getRootContainer(grammarElement);
}
 
Example 11
Source Project: dsl-devkit   File: ScopeUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the root object of a scope language resource.
 *
 * @param obj
 *          Some object in the resource
 * @return The containing root object, which is a BuildDescription.
 */
public static ScopeModel getRoot(final EObject obj) {
  final EObject root = EcoreUtil.getRootContainer(obj);
  if (root instanceof ScopeModel) {
    return (ScopeModel) root;
  }
  return null;
}
 
Example 12
public static GModelIndex get(GModelElement element) {
	EObject root = EcoreUtil.getRootContainer(element);
	GModelIndex existingIndex = (GModelIndexImpl) EcoreUtil.getExistingAdapter(root, GModelIndexImpl.class);
	return Optional.ofNullable(existingIndex).orElseGet(() -> (create(element)));
}
 
Example 13
public static GModelIndex create(GModelElement element) {
	return new GModelIndexImpl(EcoreUtil.getRootContainer(element));
}
 
Example 14
public static GModelChangeNotifier create(GModelElement element) {
	return new GModelChangeNotifierImpl(EcoreUtil.getRootContainer(element));
}
 
Example 15
@Override
protected boolean isHandled(EObject context) {
	return EcoreUtil.getRootContainer(context) == getRoot();
}
 
Example 16
@Override
protected boolean isHandled(XExpression expression) {
	return EcoreUtil.getRootContainer(expression) == getRoot();
}
 
Example 17
@Override
protected boolean isHandled(JvmIdentifiableElement identifiableElement) {
	return EcoreUtil.getRootContainer(identifiableElement) == getRoot();
}
 
Example 18
protected boolean isInferredJvmModelElement(EObject element) {
	EObject rootContainer = EcoreUtil.getRootContainer(element);
	return !isEmpty(jvmModelAssociations.getSourceElements(rootContainer));
}
 
Example 19
@Override
public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def ");
    {
      boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder.append("<");
        String _value = lhsAndParams.getValue();
        _builder.append(_value);
        _builder.append("> ");
      }
    }
    _builder.append("void method(");
    String _fixup = this.fixup(lhsAndParams.getKey());
    _builder.append(_fixup);
    _builder.append(" lhs, ");
    String _fixup_1 = this.fixup(rhs);
    _builder.append(_fixup_1);
    _builder.append(" rhs) {}");
    final String signature = _builder.toString();
    final XtendFunction function = this.function(signature.toString());
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    EObject _rootContainer = EcoreUtil.getRootContainer(function);
    final XtendFile xtendFile = ((XtendFile) _rootContainer);
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
      TypeReference _xifexpression = null;
      String _key = lhsAndParams.getKey();
      boolean _tripleNotEquals = (_key != null);
      if (_tripleNotEquals) {
        _xifexpression = it.toTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
      } else {
        _xifexpression = it.toTypeReference(this.getOwner().newAnyTypeReference());
      }
      final TypeReference lhsType = _xifexpression;
      TypeReference _xifexpression_1 = null;
      if ((rhs != null)) {
        _xifexpression_1 = it.toTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
      } else {
        _xifexpression_1 = it.toTypeReference(this.getOwner().newAnyTypeReference());
      }
      final TypeReference rhsType = _xifexpression_1;
      String _simpleName = lhsType.getSimpleName();
      String _plus = (_simpleName + " := ");
      String _simpleName_1 = rhsType.getSimpleName();
      String _plus_1 = (_plus + _simpleName_1);
      Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), 
        Boolean.valueOf(this.testIsAssignable(it, lhsType, rhsType)));
      if (expectation) {
        Iterable<? extends TypeReference> _declaredSuperTypes = lhsType.getDeclaredSuperTypes();
        for (final TypeReference superType : _declaredSuperTypes) {
          if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
            Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(it, superType, rhsType)));
          }
        }
      }
    };
    this.asCompilationUnit(xtendFile, _function);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 20
private ExecutionContext getExecutionContext(final Notification notification) {
	ExecutionContext context = (ExecutionContext) EcoreUtil.getRootContainer((EObject) notification.getNotifier());
	return context;
}