Java Code Examples for org.eclipse.emf.ecore.EClass#getEPackage()

The following examples show how to use org.eclipse.emf.ecore.EClass#getEPackage() . 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: 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 2
Source File: TypeCompareLogic.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private static int compareEClasses(EClass ec1, EClass ec2) {
	if (ec1 == ec2) {
		return 0;
	}
	if (ec1 == null) {
		return -1;
	}
	if (ec2 == null) {
		return 1;
	}
	if (ec1.getEPackage() == ec2.getEPackage()) {
		return ec1.getClassifierID() - ec2.getClassifierID();
	} else {
		// NsURIs are to be different!
		return ec1.getEPackage().getNsURI().compareTo(ec2.getEPackage().getNsURI());
	}
}
 
Example 3
Source File: EClassifierInfo.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
    * Determine whether the class represented by {@code left} is either the same as
    * or is a superclass of the class represented by {@code right} comparing the classifier ID
    * and namespace URI.
 */
private boolean isAssignableByID(EClass left, EClass right) {
	if (left.getEPackage() != null) {
		// Compare namespace URI and classifier Id
		if (left.getClassifierID() == right.getClassifierID()
				&& right.getEPackage() != null
				&& left.getEPackage().getNsURI().equals(right.getEPackage().getNsURI())) {
			return true;
		}
		// Check all supertypes of the right class
		for (EClass superClass : right.getEAllSuperTypes()) {
			if (left.getClassifierID() == superClass.getClassifierID()
					&& superClass.getEPackage() != null
					&& left.getEPackage().getNsURI().equals(superClass.getEPackage().getNsURI())) {
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static Iterable<EClass> subClasses(final EClass it) {
  Iterable<EClass> _xifexpression = null;
  EPackage _ePackage = it.getEPackage();
  boolean _tripleEquals = (_ePackage == null);
  if (_tripleEquals) {
    _xifexpression = CollectionLiterals.<EClass>emptyList();
  } else {
    final Function1<EClass, Boolean> _function = (EClass c) -> {
      return Boolean.valueOf(c.getEAllSuperTypes().contains(it));
    };
    _xifexpression = IterableExtensions.<EClass>filter(Iterables.<EClass>filter(it.getEPackage().getEClassifiers(), EClass.class), _function);
  }
  return _xifexpression;
}
 
Example 5
Source File: MigrationValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine whether an instance is of a valid type
 *
 * @param instance
 * @return true if constraint holds, false otherwise
 */
private boolean validate_validType(Instance instance) {
	final EClass eClass = instance.getEClass();
	final boolean result = eClass != null && eClass.getEPackage() != null
		&& !eClass.isAbstract();
	return result;
}
 
Example 6
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends IdEObject> T create(EClass eClass) {
	if (eClass.getEPackage() == ePackage) {
		return (T) ePackage.getEFactoryInstance().create(eClass);
	} else {
		for (PackageMetaData dep : dependencies) {
			if (dep.has(eClass)) {
				return dep.create(eClass);
			}
		}
	}
	throw new RuntimeException("Mismatch");
}
 
Example 7
Source File: GenerateGeometryLibrary.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void process(EClass eClass, EReference eReferencedFrom) {
		if (definesNode.has(eClass.getName())) {
			return;
		}
//		if (eReferencedFrom != null) {
//			System.out.println(eReferencedFrom.getEContainingClass().getName() + "." + eReferencedFrom.getName() + " -> " + eClass.getName());
//		}
		ObjectNode defineNode = OBJECT_MAPPER.createObjectNode();
		definesNode.set(eClass.getName(), defineNode);
		
		// TODO no type node required, subclasses always used
		ObjectNode typeNode = OBJECT_MAPPER.createObjectNode();
		typeNode.put("name", eClass.getName());
		typeNode.put("includeAllSubTypes", true);
		defineNode.set("type", typeNode);
		
		ArrayNode fieldsNode = OBJECT_MAPPER.createArrayNode();
		defineNode.set("fields", fieldsNode);
		
		ArrayNode includesNode = OBJECT_MAPPER.createArrayNode();
		defineNode.set("includes", includesNode);
		for (EReference eReference : eClass.getEAllReferences()) {
			if (!packageMetaData.isInverse(eReference) || isException(eReference)) {
				EClass eType = (EClass) eReference.getEType();
				if (eType.getEPackage() == ePackage) {
					for (EClass eClass2 : packageMetaData.getAllSubClassesIncludingSelf(eType)) {
						if (eClass2.getEAnnotation("wrapped") == null) {
							process(eClass2);
							includesNode.add(eClass2.getName());
						}
					}
					fieldsNode.add(eReference.getName());
				}
			}
		}
	}
 
Example 8
Source File: Database.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public void initInternalStructure(DatabaseSession databaseSession) throws BimserverLockConflictException, BimserverDatabaseException {
	RecordIterator recordIterator = keyValueStore.getRecordIterator(CLASS_LOOKUP_TABLE, databaseSession);
	try {
		Record record = recordIterator.next();
		while (record != null) {
			String packageAndClassName = BinUtils.byteArrayToString(record.getValue());
			String packageName = packageAndClassName.substring(0, packageAndClassName.indexOf("_"));
			String className = packageAndClassName.substring(packageAndClassName.indexOf("_") + 1);
			EClass eClass = (EClass) getEClassifier(packageName, className);
			
			// TODO geometry?
			boolean transactional = !(eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE);

			keyValueStore.openTable(databaseSession, packageAndClassName, transactional);
			
			for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
				if (eStructuralFeature.getEAnnotation("singleindex") != null) {
					String indexTableName = eClass.getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
					try {
						keyValueStore.openIndexTable(databaseSession, indexTableName, transactional);
					} catch (DatabaseNotFoundException e) {
					}
				}
			}
			
			Short cid = BinUtils.byteArrayToShort(record.getKey());
			cidToEclass[cid] = eClass;
			eClassToCid.put(eClass, cid);
			record = recordIterator.next();
		}
	} finally {
		recordIterator.close();
	}
}
 
Example 9
Source File: XtendJdtRenameParticipantProcessor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return true, if the triggering refactoring targets an Xtend element. 
 */
protected boolean isXtendRename() {
	JdtRenameParticipant jdtRenameParticipant = ((JvmModelJdtRenameParticipantContext) getRenameElementContext())
			.getJdtRenameParticipant();
	RefactoringProcessor triggeringProcessor = jdtRenameParticipant.getProcessor().getRefactoring().getProcessor();
	if(triggeringProcessor instanceof RenameElementProcessor) {
		EClass targetElementEClass = ((RenameElementProcessor) triggeringProcessor).getRenameElementContext().getTargetElementEClass();
		return targetElementEClass.getEPackage() == XtendPackage.eINSTANCE;
	}
	return false;
}
 
Example 10
Source File: EObjectDescriptionImpl.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public EObject getEObjectOrProxy() {
	EClass clazz = getEClass();
	if (clazz != null && !clazz.eIsProxy()) {
		EPackage ePackage = clazz.getEPackage();
		if (ePackage != null && ePackage.getEFactoryInstance() != null) {
			org.eclipse.emf.ecore.InternalEObject proxy = (org.eclipse.emf.ecore.InternalEObject) ePackage.getEFactoryInstance().create(clazz);
			proxy.eSetProxyURI(getEObjectURI());
			return proxy;
		}
	}
	return null;
}
 
Example 11
Source File: JSONDocumentSymbolKindProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected SymbolKind getSymbolKind(EClass clazz) {
	if (clazz.getEPackage() == JSONPackage.eINSTANCE) {
		switch (clazz.getClassifierID()) {
		case JSONPackage.JSON_DOCUMENT: {
			return SymbolKind.File;
		}
		case JSONPackage.JSON_OBJECT: {
			return SymbolKind.Object;
		}
		case JSONPackage.JSON_ARRAY: {
			return SymbolKind.Array;
		}
		case JSONPackage.NAME_VALUE_PAIR: {
			return SymbolKind.Field;
		}
		case JSONPackage.JSON_STRING_LITERAL: {
			// The outline does not look like something super exciting with this symbol
			// kind, but its likely the best choice here
			return SymbolKind.String;
		}
		case JSONPackage.JSON_NUMERIC_LITERAL: {
			return SymbolKind.Number;
		}
		case JSONPackage.JSON_BOOLEAN_LITERAL: {
			return SymbolKind.Boolean;
		}
		case JSONPackage.JSON_NULL_LITERAL: {
			return SymbolKind.Null;
		}
		}
	}
	throw new UnsupportedOperationException("Not supported for " + clazz.getName());
}
 
Example 12
Source File: IfcStepStreamingSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(HashMapVirtualObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();

	if (eClass.getEPackage() == GeometryPackage.eINSTANCE) {
		return;
	}
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = packageMetaData.getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	
	EntityDefinition entityBN = getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {

		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!packageMetaData.isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 13
Source File: IfcStepSerializer.java    From IfcPlugins with GNU Affero General Public License v3.0 4 votes vote down vote up
private void write(IdEObject object) throws SerializerException, IOException {
	EClass eClass = object.eClass();
	if (eClass.getEAnnotation("hidden") != null) {
		return;
	}
	if (eClass.getEPackage() != getPackageMetaData().getEPackage()) {
		return;
	}
	print(DASH);
	long convertedKey = getExpressId(object);
	if (convertedKey == -1) {
		throw new SerializerException("Going to serialize an object with id -1 (" + object.eClass().getName() + ")");
	}
	print(String.valueOf(convertedKey));
	print("= ");
	String upperCase = getPackageMetaData().getUpperCase(eClass);
	if (upperCase == null) {
		throw new SerializerException("Type not found: " + eClass.getName());
	}
	print(upperCase);
	print(OPEN_PAREN);
	boolean isFirst = true;
	EntityDefinition entityBN = getPackageMetaData().getSchemaDefinition().getEntityBN(object.eClass().getName());
	for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
		if (feature.getEAnnotation("hidden") == null && (entityBN != null && (!entityBN.isDerived(feature.getName()) || entityBN.isDerivedOverride(feature.getName())))) {
			EClassifier type = feature.getEType();
			if (type instanceof EEnum) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEnum(object, feature);
				isFirst = false;
			} else if (type instanceof EClass) {
				EReference eReference = (EReference)feature;
				if (!getPackageMetaData().isInverse(eReference)) {
					if (!isFirst) {
						print(COMMA);
					}
					writeEClass(object, feature);
					isFirst = false;
				}
			} else if (type instanceof EDataType) {
				if (!isFirst) {
					print(COMMA);
				}
				writeEDataType(object, entityBN, feature);
				isFirst = false;
			}
		}
	}
	println(PAREN_CLOSE_SEMICOLON);
}
 
Example 14
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean perRecordVersioning(EClass eClass) {
	return eClass.getEPackage() != Ifc2x3tc1Package.eINSTANCE && eClass.getEPackage() != Ifc4Package.eINSTANCE && eClass.getEPackage() != GeometryPackage.eINSTANCE;
}
 
Example 15
Source File: N4JSGlobalScopeProvider.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns <code>true</code> if the given {@code type} is a subtype of {@link IdentifiableElement}.
 */
protected boolean isSubtypeOfIdentifiable(EClass type) {
	return type == TypesPackage.Literals.IDENTIFIABLE_ELEMENT || type.getEPackage() == TypesPackage.eINSTANCE
			&& TypesPackage.Literals.IDENTIFIABLE_ELEMENT.isSuperTypeOf(type);
}
 
Example 16
Source File: ChangeHelper.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean canBeChanged(EClass eClass) {
	return eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE;
}
 
Example 17
Source File: PackageMetaData.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private boolean has(EClass eClass) {
	return eClass.getEPackage() == ePackage;
}
 
Example 18
Source File: DefaultN4GlobalScopeProvider.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns <code>true</code> if the given {@code type} is a subtype of {@link Type}.
 */
protected boolean isSubtypeOfType(EClass type) {
	return type == TypesPackage.Literals.TYPE || type.getEPackage() == TypesPackage.eINSTANCE
			&& TypesPackage.Literals.TYPE.isSuperTypeOf(type);
}