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
Source File: FeatureParameterValueImpl.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * <!-- 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 File: OriginAwareScope.java    From n4js with 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
Source File: JvmTypeReferencesValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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
Source File: JvmTypeReferencesValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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
Source File: ScopeUtil.java    From dsl-devkit with 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 6
Source File: GModelIndex.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
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 7
Source File: GModelChangeNotifier.java    From graphical-lsp with Eclipse Public License 2.0 5 votes vote down vote up
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 8
Source File: SCTDebugElement.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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 9
Source File: AbstractTemplateVariableResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 10
Source File: DefaultBatchTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<EObject> getEntryPoints(EObject object) {
	EObject rootContainer = EcoreUtil.getRootContainer(object);
	if (rootContainer instanceof XExpression) {
		return Collections.singletonList(rootContainer);	
	}
	return Collections.emptyList();
}
 
Example 11
Source File: XImportSectionNamespaceScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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 12
Source File: DefaultReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean isHandled(EObject context) {
	return EcoreUtil.getRootContainer(context) == getRoot();
}
 
Example 13
Source File: ExecutionContextVisualizer.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
private ExecutionContext getExecutionContext(final Notification notification) {
	ExecutionContext context = (ExecutionContext) EcoreUtil.getRootContainer((EObject) notification.getNotifier());
	return context;
}
 
Example 14
Source File: TypeReferenceAssignabilityTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@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 15
Source File: JvmModelReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isInferredJvmModelElement(EObject element) {
	EObject rootContainer = EcoreUtil.getRootContainer(element);
	return !isEmpty(jvmModelAssociations.getSourceElements(rootContainer));
}
 
Example 16
Source File: DefaultReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean isHandled(JvmIdentifiableElement identifiableElement) {
	return EcoreUtil.getRootContainer(identifiableElement) == getRoot();
}
 
Example 17
Source File: DefaultReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean isHandled(XExpression expression) {
	return EcoreUtil.getRootContainer(expression) == getRoot();
}
 
Example 18
Source File: GModelIndex.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
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 19
Source File: GModelChangeNotifier.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
public static GModelChangeNotifier create(GModelElement element) {
	return new GModelChangeNotifierImpl(EcoreUtil.getRootContainer(element));
}
 
Example 20
Source File: GModelIndex.java    From graphical-lsp with Eclipse Public License 2.0 4 votes vote down vote up
public static GModelIndex create(GModelElement element) {
	return new GModelIndexImpl(EcoreUtil.getRootContainer(element));
}