Java Code Examples for org.eclipse.emf.ecore.EClassifier#getName()

The following examples show how to use org.eclipse.emf.ecore.EClassifier#getName() . 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: IfcXmlDeserializer.java    From IfcPlugins with GNU Affero General Public License v3.0 6 votes vote down vote up
private Object parsePrimitive(EClassifier eType, String text) throws DeserializeException {
	if (eType == EcorePackage.eINSTANCE.getEString()) {
		return text;
	} else if (eType == EcorePackage.eINSTANCE.getEInt()) {
		return Integer.parseInt(text);
	} else if (eType == EcorePackage.eINSTANCE.getELong()) {
		return Long.parseLong(text);
	} else if (eType == EcorePackage.eINSTANCE.getEDouble()) {
		return Double.parseDouble(text);
	} else if (eType == EcorePackage.eINSTANCE.getEBoolean()) {
		return Boolean.parseBoolean(text);
	} else if (eType instanceof EEnum) {
		EEnumLiteral eEnumLiteral = ((EEnum) eType).getEEnumLiteral(text.toUpperCase());
		if (eEnumLiteral == null) {
			if (text.equals("unknown")) {
				return null;
			} else {
				throw new DeserializeException(DeserializerErrorCode.UNSPECIFIED_IFCXML_ERROR, "Unknown enum literal " + text + " in enum " + ((EEnum) eType).getName());
			}
		}
		return eEnumLiteral.getInstance();
	} else {
		throw new DeserializeException(DeserializerErrorCode.UNSPECIFIED_IFCXML_ERROR, "Unimplemented primitive type: " + eType.getName());
	}
}
 
Example 2
Source File: EMFGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void putMappingData(Map<EObject, EObject> result, EPackage usedEPackage, EPackage loadedEPackage) {
	if (loadedEPackage != null && usedEPackage != loadedEPackage) {
		result.put(usedEPackage, loadedEPackage);
		for(EClassifier usedClassifier: usedEPackage.getEClassifiers()) {
			EClassifier loadedClassifier = loadedEPackage.getEClassifier(usedClassifier.getName());
			if (loadedClassifier == null)
				throw new RuntimeException(
						"Cannot find classifier '" + usedClassifier.getName() + "' in loaded EPackage from " + loadedEPackage.eResource().getURI());
			result.put(usedClassifier, loadedClassifier);
		}
		for(EPackage usedNestedPackage: usedEPackage.getESubpackages()) {
			for(EPackage loadedNestedPackage: loadedEPackage.getESubpackages()) {
				if (usedNestedPackage.getName().equals(loadedNestedPackage.getName())) {
					putMappingData(result, usedNestedPackage, loadedNestedPackage);
					break;
				}
			}
		}
	}
}
 
Example 3
Source File: GenModelUtil2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static GenClassifier getGenClassifier(final EClassifier cls, final ResourceSet resourceSet) {
  final GenPackage genPackage = GenModelUtil2.getGenPackage(cls.getEPackage(), resourceSet);
  EList<GenClassifier> _genClassifiers = genPackage.getGenClassifiers();
  for (final GenClassifier genCls : _genClassifiers) {
    String _name = cls.getName();
    String _name_1 = genCls.getEcoreClassifier().getName();
    boolean _equals = Objects.equal(_name, _name_1);
    if (_equals) {
      return genCls;
    }
  }
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("No GenClassifier named \'");
  String _name_2 = cls.getName();
  _builder.append(_name_2);
  _builder.append("\' found in GenModel ");
  URI _uRI = genPackage.eResource().getURI();
  _builder.append(_uRI);
  throw new RuntimeException(_builder.toString());
}
 
Example 4
Source File: IfcSchemaToJson.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private String convertType(EClassifier type) {
	if (type == EcorePackage.eINSTANCE.getEDouble() || type == EcorePackage.eINSTANCE.getEDoubleObject()) {
		return "double";
	} else if (type == EcorePackage.eINSTANCE.getEInt() || type == EcorePackage.eINSTANCE.getEIntegerObject()) {
		return "int";
	} else if (type == EcorePackage.eINSTANCE.getEShort() || type == EcorePackage.eINSTANCE.getEShortObject()) {
		return "short";
	} else if (type == EcorePackage.eINSTANCE.getEBoolean() || type == EcorePackage.eINSTANCE.getEBooleanObject()) {
		return "boolean";
	} else if (type == EcorePackage.eINSTANCE.getEByteArray()) {
		return "bytearray";
	} else if (type == EcorePackage.eINSTANCE.getELong() || type == EcorePackage.eINSTANCE.getELongObject()) {
		return "long";
	} else if (type == EcorePackage.eINSTANCE.getEString()) {
		return "string";
	} else if (type instanceof EEnum) {
		return "enum";
	}
	return type.getName();
}
 
Example 5
Source File: GenModelAccess.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static GenClassifier getGenClassifier(EClassifier cls, ResourceSet resourceSet) {
	GenPackage genPackage = getGenPackage(cls.getEPackage(), resourceSet);
	for (GenClassifier genCls : genPackage.getGenClassifiers())
		if (cls.getName().equals(genCls.getEcoreClassifier().getName())) {
			return genCls;
		}
	throw new RuntimeException("No GenClassifier named '" + cls.getName() + "' found in GenModel "
			+ genPackage.eResource().getURI());
}
 
Example 6
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void completeParserRule(EObject model, final ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	final Grammar grammar = GrammarUtil.getGrammar(model);
	for (AbstractMetamodelDeclaration metamodelDeclaration : grammar.getMetamodelDeclarations()) {
		if (metamodelDeclaration instanceof ReferencedMetamodel) {
			ReferencedMetamodel referencedMetamodel = (ReferencedMetamodel) metamodelDeclaration;
			EPackage ePackage = referencedMetamodel.getEPackage();
			if (ePackage != null) {
				for (EClassifier eClassifier : ePackage.getEClassifiers()) {
					if (isProposeParserRule(eClassifier, grammar)) {
						String proposal = eClassifier.getName();
						String metamodelAlias = referencedMetamodel.getAlias();
						if (metamodelAlias != null) {
							proposal = proposal + " returns " + metamodelAlias + "::" + eClassifier.getName();
						}
						proposal = proposal + ": \n;\n";
						ConfigurableCompletionProposal completionProposal = (ConfigurableCompletionProposal) createCompletionProposal(
								proposal, eClassifier.getName() + " - parser rule",
								getImage(XtextFactory.eINSTANCE.createParserRule()), context);
						if (completionProposal != null) {
							completionProposal.setCursorPosition(proposal.length() - 3);
							acceptor.accept(completionProposal);
						}
					}
				}
			}
		}
	}
}
 
Example 7
Source File: Xtext2EcoreInterpretationContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private EClassifierInfo getEClassifierInfoOrThrowException(EClassifier type, AbstractElement parserElement)
		throws TransformationException {
	final EClassifierInfo featureTypeInfo = eClassifierInfos.getInfoOrNull(type);
	if (featureTypeInfo == null) {
		String typeName = "null";
		if (type != null)
			typeName = type.getName();
		throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, 
				"Cannot resolve type " + typeName, parserElement);
	}
	return featureTypeInfo;
}
 
Example 8
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkGeneratedPackageForNameClashes(GeneratedMetamodel metamodel) {
	EPackage pack = metamodel.getEPackage();
	Multimap<String, ENamedElement> constantNameToElement = HashMultimap.create();
	Multimap<String, ENamedElement> accessorNameToElement = HashMultimap.create();
	if (pack != null) {
		for(EClassifier classifier: pack.getEClassifiers()) {
			String accessorName = classifier.getName();
			if ("Class".equals(accessorName) || "Name".equals(accessorName))
				accessorName += "_";
			accessorNameToElement.put("get" + accessorName, classifier);
			String classifierConstantName = CodeGenUtil2.format(classifier.getName(), '_', null, true, true).toUpperCase();
			constantNameToElement.put(classifierConstantName, classifier);
			if (classifier instanceof EClass) {
				for(EStructuralFeature feature: ((EClass) classifier).getEAllStructuralFeatures()) {
					String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, false, false).toUpperCase();
					String featureConstantName = classifierConstantName + "__" + featureConstantPart;
					constantNameToElement.put(featureConstantName, feature);
					String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName());
					accessorNameToElement.put(featureAccessorName, feature);
				}
			}
		}
	}
	createMessageForNameClashes(constantNameToElement);
	createMessageForNameClashes(accessorNameToElement);
}
 
Example 9
Source File: DefaultEcoreElementFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EObject create(EClassifier classifier) {
	if (classifier == null)
		throw new NullPointerException("Classifier may not be null.");
	if (!(classifier instanceof EClass))
		throw new IllegalArgumentException("Cannot create instance of datatype '" + classifier.getName() + "'");
	EClass clazz = (EClass) classifier;
	if (clazz.isAbstract() || clazz.isInterface())
		throw new IllegalArgumentException("Cannot create instance of abstract class '" + clazz.getName() + "'");
	if (classifier.eIsProxy())
		throw new IllegalStateException("Unresolved proxy "+((InternalEObject)classifier).eProxyURI()+". Make sure the EPackage has been registered.");
	return clazz.getEPackage().getEFactoryInstance().create(clazz);
}
 
Example 10
Source File: EcoreQualifiedNameProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected String name(EClassifier eClassifier) {
	return eClassifier.getName();
}
 
Example 11
Source File: GrammarTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected String getClassifierName(EClassifier returnType) {
	return (returnType.eIsProxy()) ? ((InternalEObject)returnType).eProxyURI().fragment().replaceAll("/", "") : returnType.getName();
}
 
Example 12
Source File: EClassifierInfos.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public EClassifierInfo getInfo(EClassifier eClassifier) {
	for (EClassifierInfo info : infoMap.values())
		if (info.getEClassifier().equals(eClassifier))
			return info;
	throw new NullPointerException("cannot find type info for classifier '" + eClassifier.getName() + "'");
}
 
Example 13
Source File: EClassifierInfo.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private String classifierToString(EClassifier classifier) {
	String result = "'" + classifier.getName() + "'";
	if (classifier.getInstanceTypeName() != null)
		result += " [" + classifier.getInstanceTypeName() + "]";
	return result;
}
 
Example 14
Source File: EcoreQualifiedNameProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String name(EClassifier eClassifier) {
	return eClassifier.getName();
}
 
Example 15
Source File: GenerateUtils.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getType(EStructuralFeature eStructuralFeature) {
	boolean embedsReference = eStructuralFeature.getEAnnotation("embedsreference") != null;
	EClassifier eType = eStructuralFeature.getEType();
	if (eStructuralFeature.isMany()) {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "List<String>";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "List<Integer>";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "List<Long>";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "List<Double>";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "List<Boolean>";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "List<Float>";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "List<Date>";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "List<S" + eType.getName() + ">";
			} else {
				return "List<Long>";
			}
		}
	} else {
		if (eType instanceof EDataType) {
			if (eType == EcorePackage.eINSTANCE.getEString()) {
				return "String";
			} else if (eType == EcorePackage.eINSTANCE.getEInt() || eType == EcorePackage.eINSTANCE.getEIntegerObject()) {
				return "Integer";
			} else if (eType == EcorePackage.eINSTANCE.getELong() || eType == EcorePackage.eINSTANCE.getELongObject()) {
				return "Long";
			} else if (eType == EcorePackage.eINSTANCE.getEShort() || eType == EcorePackage.eINSTANCE.getEShortObject()) {
				return "Short";
			} else if (eType == EcorePackage.eINSTANCE.getEDouble() || eType == EcorePackage.eINSTANCE.getEDoubleObject()) {
				return "Double";
			} else if (eType == EcorePackage.eINSTANCE.getEBoolean() || eType == EcorePackage.eINSTANCE.getEBooleanObject()) {
				return "Boolean";
			} else if (eType == EcorePackage.eINSTANCE.getEFloat() || eType == EcorePackage.eINSTANCE.getEFloatObject()) {
				return "Float";
			} else if (eType == EcorePackage.eINSTANCE.getEDate()) {
				return "Date";
			} else if (eType == EcorePackage.eINSTANCE.getEByteArray()) {
				return "byte[]";
			} else if (eType.getInstanceClass() == DataHandler.class) {
				return "DataHandler";
			}
		} else if (eType instanceof EClass) {
			if (embedsReference) {
				return "S" + eType.getName();
			} else {
				return "Long";
			}
		}
	}
	return "S" + eType.getName();
}
 
Example 16
Source File: StringRepresentation.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
protected String stringRep(EClassifier eClassifier) {
	return eClassifier.getName();
}