Java Code Examples for org.eclipse.emf.ecore.EObject#eClass()

The following examples show how to use org.eclipse.emf.ecore.EObject#eClass() . 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: AllContentsPerformanceTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void doTestUoWImpl(EObject object, IUnitOfWork<Boolean, EObject> uow) throws Exception {
	if (object == null)
		return;
	if (!uow.exec(object).booleanValue()) {
		EClass clazz = object.eClass();
		for(EReference reference: clazz.getEAllContainments()) {
			// object.eIsSet(..) decreased performance - TODO: investigate the reason
			// TODO: handle feature maps 
			// TODO: What's FeatureListIterator#useIsSet about?
			if (reference.isMany()) {
				@SuppressWarnings("unchecked")
				List<EObject> values = (List<EObject>) object.eGet(reference);
				for(int i = 0; i<values.size(); i++) {
					doTestUoWImpl(values.get(i), uow);
				}
			} else {
				doTestUoWImpl((EObject) object.eGet(reference), uow);
			}
		}
	}
}
 
Example 2
Source File: ClosureWithExpectationHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isImplicitReturn(ITypeComputationResult expressionResult) {
	int flags = expressionResult.getConformanceFlags();
	if ((ConformanceFlags.NO_IMPLICIT_RETURN & flags) != 0) {
		return false;
	}
	XExpression expression = expressionResult.getExpression();
	if (expression == null) {
		return true;
	}
	if (expression.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) {
		return false;
	}
	TreeIterator<EObject> contents = expression.eAllContents();
	while (contents.hasNext()) {
		EObject next = contents.next();
		if (next.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) {
			return false;
		}
		if (next.eClass() == XbasePackage.Literals.XCLOSURE) {
			contents.prune();
		}
	}
	return true;
}
 
Example 3
Source File: BatchLinkableResource.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError {
	if (!isValidationDisabled()) {
		EObject context = triple.getFirst();
		if (context.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
			// here we may end up with cyclic resolution requests in rare situations, e.g. for input types
			// like :
			/*
			 * package p;
			 * class C extends p.C.Bogus {}
			 */
			return null;
		}
		DiagnosticMessage message = new DiagnosticMessage("Cyclic linking detected : " + getReferences(triple, resolving), Severity.ERROR, "cyclic-resolution");
		List<Diagnostic> list = getDiagnosticList(message);
		Diagnostic diagnostic = createDiagnostic(triple, message);
		if (!list.contains(diagnostic))
			list.add(diagnostic);
	}
	return null;
}
 
Example 4
Source File: AbstractSelectorFragmentProviderTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean appendFragmentSegment(final EObject object, final StringBuilder builder) {
  EClass eClass = object.eClass();
  EPackage ePackage = eClass.getEPackage();
  if (ePackage == XtextPackage.eINSTANCE) {
    int classifierID = eClass.getClassifierID();
    switch (classifierID) {
    case XtextPackage.GRAMMAR:
      return appendFragmentSegment((Grammar) object, builder);
    case XtextPackage.ENUM_RULE:
    case XtextPackage.PARSER_RULE:
    case XtextPackage.TERMINAL_RULE:
      return appendFragmentSegment((AbstractRule) object, builder);
    case XtextPackage.KEYWORD:
      if (((Keyword) object).getValue().equals("selectCardinality")) {
        return appendFragmentSegment((AbstractElement) object, builder);
      } else {
        return appendFragmentSegment((Keyword) object, builder);
      }
    default:
      return super.appendFragmentSegment(object, builder);
    }
  }
  return super.appendFragmentSegment(object, builder);
}
 
Example 5
Source File: Tracer.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Same as {@link #getSingleIntermediateModelElement(EObject, boolean)}, but makes sure that the element is of the
 * same type as the given original AST node. Returns <code>null</code> if no element in intermediate model defined
 * or if it is of wrong type. If second argument is <code>true</code>, then throws an exception instead of returning
 * <code>null</code>.
 * <p>
 * This method is particularly useful in the {@link Transformation#analyze() analyze()} method of an AST
 * transformation, because there the intermediate model is guaranteed to be in its initial state and this method
 * should always return a non-null value.
 */
public <T extends EObject> T getSingleIntermediateModelElementOfSameType(T originalASTNode, boolean failFast) {
	final EObject elemInIM = getSingleIntermediateModelElement(originalASTNode, failFast);
	if (elemInIM != null && elemInIM.eClass() == originalASTNode.eClass()) {
		@SuppressWarnings("unchecked")
		final T elemCasted = (T) elemInIM;
		return elemCasted;
	}
	if (failFast) {
		if (elemInIM != null)
			throw new IllegalStateException("there was an element in the intermediate model, but of wrong type");
		throw new IllegalStateException("no element in intermediate model found");
	}
	return null;
}
 
Example 6
Source File: XtendReentrantTypeResolver.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean doIsHandled(EObject root, EObject instance) {
	if (root.eClass() == XtendPackage.Literals.ANONYMOUS_CLASS) {
		// the immediate constructor call is not processed by the anonymous class itself
		AnonymousClass casted = (AnonymousClass) root;
		if (casted == instance || EcoreUtil.isAncestor(casted.getConstructorCall(), instance)) {
			return false;
		}
	}
	boolean result = EcoreUtil.isAncestor(root, instance);
	return result;
}
 
Example 7
Source File: JdtRefactoringContext.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public JdtRefactoringContext(EObject targetJvmElement, IJavaElement javaElement, IEditorPart editor,
		ISelection selection, XtextResource contextResource, boolean isRealJvmMember) {
	super(getPlatformResourceOrNormalizedURI(targetJvmElement), targetJvmElement.eClass(), editor, selection,
			getPlatformResourceOrNormalizedURI(contextResource));
	this.javaElement = javaElement;
	this.isRealJvmElement = isRealJvmMember;
}
 
Example 8
Source File: TokenDiagnosticProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getFullReferenceName(EObject semanticObject, CrossReference reference) {
	EReference ref = GrammarUtil.getReference(reference);
	String clazz = semanticObject.eClass().getName();
	if (ref.getEContainingClass() != semanticObject.eClass())
		clazz = ref.getEContainingClass().getName() + "(" + clazz + ")";
	return clazz + "." + ref.getName();
}
 
Example 9
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected EObject getContainingAnnotationTarget(XAnnotation annotation) {
	final EObject eContainer = annotation.eContainer();
	// skip synthetic container
	if (eContainer.eClass() == XtendPackage.Literals.XTEND_MEMBER || eContainer.eClass() == XtendPackage.Literals.XTEND_TYPE_DECLARATION) {
		return eContainer.eContainer();
	}
	return eContainer;
}
 
Example 10
Source File: ForwardConverter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/** Create a new node for an EMF model element. */
protected Instance newInstance(EObject eObject, boolean proxy) {
	final EClass eClass = eObject.eClass();
	final Instance element = model.newInstance(eClass);
	mapping.put(eObject, element);
	if (proxy) {
		element.setUri(EcoreUtil.getURI(eObject));
	}
	return element;
}
 
Example 11
Source File: LinkedModelCalculatorIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCorrectTextEditsDeclarationNotInFile() throws Exception {
	String initialModel1 = "A { B ref A } C { D ref A }";
	createFile(pathToFile1, initialModel1);
	String initialModel2 = "E { ref A } F { ref E ref A}";
	IFile file2 = createFile(pathToFile2, initialModel2);
	waitForBuild();
	XtextEditor editor = openEditor(file2);
	EObject a = editor.getDocument().readOnly(new IUnitOfWork<EObject, XtextResource>() {

		@Override
		public EObject exec(XtextResource state) throws Exception {
			return ((Element) state.getContents().get(0).eContents().get(0)).getReferenced().get(0);
		}

	});

	URI uri = EcoreUtil.getURI(a);
	selectElementInEditor(a, uri, editor, (XtextResource) a.eResource());
	IRenameElementContext renameElementContext = new IRenameElementContext.Impl(uri, a.eClass(), editor, editor
			.getSelectionProvider().getSelection(), uriToFile2);
	LinkedPositionGroup linkedPositionGroup = linkedModelCalculator.getLinkedPositionGroup(renameElementContext,
			new NullProgressMonitor()).get();
	LinkedPosition[] positions = linkedPositionGroup.getPositions();
	assertEquals(2, positions.length);

	int[] offsets = { 8, 26 };
	for (int i = 0; i < positions.length; i++) {
		assertEquals(offsets[i], positions[i].getOffset());
	}
}
 
Example 12
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
protected Result<EClass> applyRuleEObjectEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EObject obj) throws RuleFailedException {
  EClass eClass = null; // output parameter
  eClass = obj.eClass();
  return new Result<EClass>(eClass);
}
 
Example 13
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
private EClass _applyRuleEObjectEClass_1(final RuleEnvironment G, final EObject eObject) throws RuleFailedException {
  EClass _eClass = eObject.eClass();
  return _eClass;
}
 
Example 14
Source File: EObjectNode.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.4
 */
public EObjectNode(EObject eObject, IOutlineNode parent, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) {
	super(parent, imageDescriptor, text, isLeaf);
	this.eObjectURI = EcoreUtil.getURI(eObject);
	this.eClass = eObject.eClass();
}
 
Example 15
Source File: RoutePropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.ROUTE == eObj.eClass();
}
 
Example 16
Source File: EnricherPropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.ENRICHER == eObj.eClass();
}
 
Example 17
Source File: GatewayPropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.GATEWAY == eObj.eClass();
}
 
Example 18
Source File: ContentFilterPropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.CONTENT_FILTER == eObj.eClass();
}
 
Example 19
Source File: CompositeProcessorPropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.COMPOSITE_PROCESSOR == eObj.eClass();
}
 
Example 20
Source File: AggregatorPropertiesEditionProvider.java    From eip-designer with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object)
 */
public boolean select(Object toTest) {
	EObject eObj = EEFUtils.resolveSemanticObject(toTest);
	return eObj != null && EipPackage.Literals.AGGREGATOR == eObj.eClass();
}