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

The following examples show how to use org.eclipse.emf.ecore.EStructuralFeature#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: ReferenceCCDAValidator.java    From reference-ccda-validator with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String getPath(EObject eObject) {
	String path = "";
	while (eObject != null && !(eObject instanceof DocumentRoot)) {
		EStructuralFeature feature = eObject.eContainingFeature();
		EObject container = eObject.eContainer();
		Object value = container.eGet(feature);
		if (feature.isMany()) {
			List<?> list = (List<?>) value;
			int index = list.indexOf(eObject) + 1;
			path = "/" + feature.getName() + "[" + index + "]" + path;
		} else {
			path = "/" + feature.getName() + "[1]" + path;
		}
		eObject = eObject.eContainer();
	}
	return path;
}
 
Example 2
Source File: TypesUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private static void prependContainingFeatureName(StringBuilder id, EObject container) {
	EStructuralFeature feature = container.eContainingFeature();
	if (feature != null) {
		String name;
		if (feature.isMany()) {
			Object elements = container.eContainer().eGet(feature);
			int index = 0;
			if (elements instanceof BasicEList) {
				BasicEList<?> elementList = (BasicEList<?>) elements;
				index = elementList.indexOf(container);
			}
			name = feature.getName() + index;
		} else {
			name = feature.getName();
		}
		id.insert(0, ID_SEPARATOR);
		id.insert(0, name);
	}
}
 
Example 3
Source File: FeatureBasedDiagnostic.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param issueData optional user data. May not contain <code>null</code> entries.
 */
public FeatureBasedDiagnostic(int severity, String message, EObject source, EStructuralFeature feature, int index, CheckType checkType, String issueCode, String... issueData) {
	super(severity, message, source, checkType, issueCode, issueData);
	if (feature != null && source != null) {
		if (source.eClass().getEStructuralFeature(feature.getName()) != feature) {
			throw new IllegalArgumentException("The sources EClass '" + source.eClass().getName() + "' does not expose the feature '" + feature.getEContainingClass().getName() + "." + feature.getName() + "'");
		}
	}
	this.feature = feature;
	this.index = index;
}
 
Example 4
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<Boolean> applyRuleForEachWithBooleanExpressionInside(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass) throws RuleFailedException {
  final Consumer<EStructuralFeature> _function = new Consumer<EStructuralFeature>() {
    public void accept(final EStructuralFeature it) {
      String _name = it.getName();
      /* (!Objects.equal(_name, "foo")); */
    }
  };
  eClass.getEStructuralFeatures().forEach(_function);
  return new Result<Boolean>(true);
}
 
Example 5
Source File: TreeConstructionReportImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getDiagnosticMessage(AssignmentToken token) {
	Assignment ass = (Assignment) token.getGrammarElement();
	Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false);
	if (value == null) {
		EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass()
				.getEStructuralFeature(ass.getFeature());
		if (f == null)
			return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName()
					+ "' does not have a feature named '" + ass.getFeature() + "'";
		String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f
				.getEContainingClass().getName() : f.getEContainingClass().getName() + "("
				+ token.getEObjectConsumer().getEObject().eClass().getName() + ")";
		String feat = cls + "." + f.getName();
		if (f.isMany()) {
			int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size();
			return "All " + size + " values of " + feat + " have been consumed. "
					+ "More are needed to continue here.";
		} else
			return feat + " is not set.";
	} else {
		ErrorAcceptor err = new ErrorAcceptor();
		for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) {
			if (ruleCall.getRule() instanceof EnumRule) {
				if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err))
					return null;
			} else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) {
				if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err))
					return null;
			}
		}
		return err.getMessage();
	}
}
 
Example 6
Source File: QueryClassificationsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<ObjectIdentifier> getOids(EClass eClass, EStructuralFeature eStructuralFeature, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
	if (eStructuralFeature.getEAnnotation("singleindex") != null) {
		List<ObjectIdentifier> result = new ArrayList<>();
		String indexTableName = eStructuralFeature.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else if (value instanceof Long) {
			queryBytes = BinUtils.longToByteArray((Long)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
		valueBuffer.putInt(pid);
		valueBuffer.putInt(-rid);
		valueBuffer.put(queryBytes);
		List<byte[]> duplicates = databaseInterface.getDuplicates(indexTableName, valueBuffer.array());
		for (byte[] duplicate : duplicates) {
			ByteBuffer buffer = ByteBuffer.wrap(duplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			
			result.add(new ObjectIdentifier(oid, (short)oid));
		}
		return result;
	} else {
		throw new UnsupportedOperationException();
	}
}
 
Example 7
Source File: SharedJsonDeserializer.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addToList(EStructuralFeature eStructuralFeature, int index, AbstractEList list, EObject referencedObject) throws DeserializeException {
	EClass referenceEClass = referencedObject.eClass();
	if (((EClass) eStructuralFeature.getEType()).isSuperTypeOf(referenceEClass)) {
		while (list.size() <= index) {
			list.addUnique(referencedObject);
		}
	} else {
		throw new DeserializeException(DeserializerErrorCode.REFERENCED_OBJECT_CANNOT_BE_STORED_IN_THIS_FIELD, -1, referenceEClass.getName() + " cannot be stored in " + eStructuralFeature.getName());
	}
}
 
Example 8
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertValue(EStructuralFeature feature, Object value) {
	if (value != null && !feature.getEType().isInstance(value)) {
		String valueType = value.getClass().getSimpleName();
		String featureName = feature.eClass().getName() + "." + feature.getName();
		String msg = "The value of type '" + valueType + "' can not be assigned to feature " + featureName
				+ " of type  '" + feature.getEType().getName() + "'.";
		throw new RuntimeException(msg);
	}
}
 
Example 9
Source File: TransientHandlerSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) {
	final String n = feature.getName();
	if ("required1".equals(n) || "required2".equals(n))
		return ValueTransient.PREFERABLY;
	if ("opt1".equals(n) || "opt2".equals(n))
		return ValueTransient.YES;
	return super.isValueTransient(semanticObject, feature);
}
 
Example 10
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<Boolean> applyRuleForEachWithBooleanExpressionInside(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass) throws RuleFailedException {
  final Consumer<EStructuralFeature> _function = new Consumer<EStructuralFeature>() {
    public void accept(final EStructuralFeature it) {
      String _name = it.getName();
      /* (!Objects.equal(_name, "foo")); */
    }
  };
  eClass.getEStructuralFeatures().forEach(_function);
  return new Result<Boolean>(true);
}
 
Example 11
Source File: TransientHandlerPTC.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
	// System.out.println("isTransient " + feature.getName()
	// + ((index >= 0) ? "[" + index + "]" : ""));
	final String n = feature.getName();
	if ("required1".equals(n) || "required2".equals(n))
		return true;
	if ("opt1".equals(n) || "opt2".equals(n))
		return true;
	if ("item".equals(n)) {
		List<?> l = (List<?>) owner.eGet(feature);
		return ((Integer) l.get(index) % 2) == 0;
	}
	return super.isTransient(owner, feature, index);
}
 
Example 12
Source File: CustomPropertyColumnLabelProvider.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public CustomPropertyColumnLabelProvider(final IPropertySourceProvider propertySourceProvider, final EStructuralFeature feature,
        final IObservableSet knowElements) {
    super(propertySourceProvider, feature.getName());
    this.knowElements = knowElements;
    this.feature = feature;
}
 
Example 13
Source File: Visualise.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public StructuralFeatureNode(IdEObject idEObject, EStructuralFeature eStructuralFeature) {
	super(eStructuralFeature.getName());
	this.idEObject = idEObject;
	this.eStructuralFeature = eStructuralFeature;
}
 
Example 14
Source File: EcoreQualifiedNameProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String name(EStructuralFeature eStructuralFeature) {
	return eStructuralFeature.getName();
}
 
Example 15
Source File: EcoreQualifiedNameProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected String name(EStructuralFeature eStructuralFeature) {
	return eStructuralFeature.getName();
}
 
Example 16
Source File: AbstractSemanticRegionsFinder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public FeaturePredicate(EStructuralFeature feature) {
	this.name = feature.getName();
	this.type = feature.getEContainingClass();
}
 
Example 17
Source File: SequencerDiagnosticProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ISerializationDiagnostic createFeatureValueMissing(EObject semanticObject, EStructuralFeature feature) {
	String msg = "A value for feature '" + feature.getName() + "' is missing but required.";
	return new SerializationDiagnostic(FEATURE_VALUE_MISSING, semanticObject, grammarAccess.getGrammar(), msg);
}
 
Example 18
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void assertIndex(EStructuralFeature feature) {
	if (feature.isMany())
		throw new RuntimeException(feature.eClass().getName() + "." + feature.getName()
				+ " is a multi-value-feature, therefore it needs an index.");
}
 
Example 19
Source File: DefaultEcoreElementFactory.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private void checkNullForPrimitiveFeatures(EStructuralFeature structuralFeature, Object tokenValue, INode node) {
	if(tokenValue == null && structuralFeature.getEType().getInstanceClass().isPrimitive()) {
		throw new ValueConverterException("ValueConverter returned null for primitive feature " + structuralFeature.getName(), node, null);
	}
}
 
Example 20
Source File: ConfigurationHandler.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Fills in the configuration into the configuration object and adds it to the {@link OHConfig}.
 *
 * @param ohtfDevice The device specific configuration object {@link OHTFDevice}.
 * @param deviceConfig The device configuration as {@code Map} of {@code Strings}.
 * @throws ConfigurationException
 */
private void fillupConfig(OHTFDevice<?, ?> ohtfDevice, Map<String, String> deviceConfig)
        throws ConfigurationException {
    String uid = deviceConfig.get(ConfigKey.uid.name());
    if (uid == null || uid.equals("")) {
        // das kommt hier gar nie an
        logger.error("===== uid missing");
        throw new ConfigurationException(deviceConfig.toString(),
                "config is an invalid missing uid: openhab.cfg has to be fixed!");
    } else {
        logger.debug("*** uid is \"{}\"", uid);
    }
    ohtfDevice.setUid(uid);
    String subid = deviceConfig.get(ConfigKey.subid.name());
    if (subid != null) {
        if (!ohtfDevice.isValidSubId(subid)) {
            throw new ConfigurationException(subid,
                    String.format("\"%s\" is an invalid subId: openhab.cfg has to be fixed!", subid));
        }
        logger.trace("fillupConfig ohtfDevice subid {}", subid);
        ohtfDevice.setSubid(subid);
    }
    if (ohConfig.getConfigByTFId(uid, subid) != null) {
        throw new ConfigurationException(String.format("uid: %s subId: %s", uid, subid),
                String.format("%s: duplicate device config for uid \"%s\" and subId \"%s\": fix openhab.cfg",
                        LoggerConstants.CONFIG, uid, subid));
    }
    String symbolicName = deviceConfig.get(ConfigKeyAdmin.ohId.name());
    if (ohConfig.getConfigByOHId(symbolicName) != null) {
        throw new ConfigurationException(String.format("symbolic name: %s", symbolicName),
                String.format("%s: duplicate device config for symbolic name \"%s\": fix openhab.cfg",
                        LoggerConstants.CONFIG, symbolicName));
    }
    ohtfDevice.setOhid(symbolicName);

    EObject tfConfig = ohtfDevice.getTfConfig();
    EList<EStructuralFeature> features = null;
    if (tfConfig != null) {
        features = tfConfig.eClass().getEAllStructuralFeatures();
    }
    ArrayList<String> configKeyList = new ArrayList<String>();
    for (ConfigKeyAdmin configKey : ConfigKeyAdmin.values()) {
        configKeyList.add(configKey.toString());
    }
    for (String property : deviceConfig.keySet()) {
        if (configKeyList.contains(property)) {
            continue;
        } else {
            logger.trace("{} found  property {}", LoggerConstants.CONFIG, property);
        }

        if (features != null) {
            for (EStructuralFeature feature : features) {
                logger.trace("found feature: {}", feature.getName());
                if (feature.getName().equals(property)) {
                    logger.trace("{} feature type {}", LoggerConstants.CONFIG,
                            feature.getEType().getInstanceClassName());
                    logger.debug("configuring feature: {} for uid {} subid {}", feature.getName(), uid, subid);
                    String className = feature.getEType().getInstanceClassName();
                    if (className.equals("int") || className.equals("java.lang.Integer")) {
                        tfConfig.eSet(feature, Integer.parseInt(deviceConfig.get(property)));
                    } else if (className.equals("short") || className.equals("java.lang.Short")) {
                        tfConfig.eSet(feature, Short.parseShort(deviceConfig.get(property)));
                    } else if (className.equals("long") || className.equals("java.lang.Long")) {
                        tfConfig.eSet(feature, Long.parseLong(deviceConfig.get(property)));
                    } else if (className.equals("boolean") || className.equals("java.lang.Boolean")) {
                        logger.debug("{} found boolean value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, Boolean.parseBoolean(deviceConfig.get(property)));
                    } else if (className.equals("java.lang.String")) {
                        logger.debug("{} found String value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, deviceConfig.get(property));
                    } else if (className.equals("java.math.BigDecimal")) {
                        logger.debug("{} found BigDecimal value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, new BigDecimal(deviceConfig.get(property)));
                        // } else if (feature.getEType().getInstanceClassName().equals("EList")){
                        // logger.debug("{} found EList value", LoggerConstants.CONFIG);
                        // List<String> strings = new
                        // ArrayList<String>(Arrays.asList(deviceConfig.get(property).trim().split("\\s+")));
                        // tfConfig.eSet(feature, strings);
                    } else {
                        throw new ConfigurationException(feature.getName(),
                                "unsupported configuration type needed: " + className);
                    }
                    break;
                }
            }
        }
    }

    ohConfig.getOhTfDevices().add(ohtfDevice);
}