Java Code Examples for org.eclipse.emf.ecore.EObject#eIsSet()
The following examples show how to use
org.eclipse.emf.ecore.EObject#eIsSet() .
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: GenerateImplementations.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * Find any scripting languages used and add them to the languages information. * * @param model the crossflow model * @param languages the languages information */ private static Map<String, String[]> findScriptingLanguages(EmfModel model) { final Map<String, String[]> languages = new HashMap<>(); Resource r = model.getResource(); EClass scriptingTask = (EClass) r.getContents().get(0).eClass().getEPackage().getEClassifier("ScriptedTask"); EAttribute scriptingLanguage = scriptingTask.getEAllAttributes().stream() .filter(a -> a.getName().equals("scriptingLanguage")).findFirst().get(); for (Iterator<EObject> it = r.getAllContents(); it.hasNext();) { EObject o; String language; if ((o = it.next()).eClass().equals(scriptingTask)) if (o.eIsSet(scriptingLanguage) && (language = (String) o.eGet(scriptingLanguage)).trim().length() > 0) languages.put(language, new String[] { "src", "src-gen" }); } return languages; }
Example 2
Source File: OutlineNodeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public EStructuralFeatureNode createEStructuralFeatureNode(IOutlineNode parentNode, EObject owner, EStructuralFeature feature, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, imageDescriptor, text, isLeaf || !isFeatureSet); if (isFeatureSet) { ITextRegion region = locationInFileProvider.getFullTextRegion(owner, feature, 0); if (feature.isMany()) { int numValues = ((Collection<?>) owner.eGet(feature)).size(); ITextRegion fullTextRegion = locationInFileProvider.getFullTextRegion(owner, feature, numValues - 1); if(fullTextRegion != null) region = region.merge(fullTextRegion); } eStructuralFeatureNode.setTextRegion(region); } return eStructuralFeatureNode; }
Example 3
Source File: DefaultOutlineTreeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected EStructuralFeatureNode createEStructuralFeatureNode(IOutlineNode parentNode, EObject owner, EStructuralFeature feature, Image image, Object text, boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, image, text, isLeaf || !isFeatureSet); setTextRegion(eStructuralFeatureNode, isFeatureSet, owner, feature); return eStructuralFeatureNode; }
Example 4
Source File: DefaultOutlineTreeProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.12 */ protected EStructuralFeatureNode createEStructuralFeatureNode(IOutlineNode parentNode, EObject owner, EStructuralFeature feature, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, imageDescriptor, text, isLeaf || !isFeatureSet); setTextRegion(eStructuralFeatureNode, isFeatureSet, owner, feature); return eStructuralFeatureNode; }
Example 5
Source File: LegacyTransientValueService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) { if (feature.isTransient()) return ValueTransient.YES; boolean isSet = semanticObject.eIsSet(feature); if (defaultValueIsSerializeable(feature) && !isSet) return ValueTransient.PREFERABLY; if (legacy.isTransient(semanticObject, feature, 0)) return ValueTransient.YES; return isSet ? ValueTransient.NO : ValueTransient.YES; }
Example 6
Source File: TransientValueService.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) { if (feature.isTransient() || !semanticObject.eIsSet(feature) || isContainerReferenceInSameResource(semanticObject, feature)) { if (defaultValueIsSerializeable(feature)) return ValueTransient.PREFERABLY; else return ValueTransient.YES; } else return ValueTransient.NO; }
Example 7
Source File: Linker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void setDefaultValues(EObject obj, Set<EReference> references, IDiagnosticProducer producer) { for (EReference ref : obj.eClass().getEAllReferences()) { if (canSetDefaultValues(ref) && !references.contains(ref) && !obj.eIsSet(ref) && !ref.isDerived()) { setDefaultValue(obj, ref, producer); } } }
Example 8
Source File: AbstractHoverTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Build a directory of node hovers indexed by the {@link EObject}. * * @param model * the model for which to build the hover map, must not be {@code null} */ private void buildHoverMap(final EObject model) { // All contained features List<EStructuralFeature> features = model.eClass().getEAllStructuralFeatures(); for (EStructuralFeature feature : features) { if (feature instanceof EReference && model.eIsSet(feature)) { EList<EObject> children = getFeatureValues(model, feature); boolean referenceAdded = false; IEObjectHoverProvider hoverProvider = getHoverProvider(); for (EObject childModelElement : children) { if (!childModelElement.eIsProxy()) { buildHoverMap(childModelElement); Object element = childModelElement.eClass(); Object hover = hoverProvider.getHoverInfo(childModelElement, null, null).getInfo(); if (element != null && hover != null) { addToHoverMap(element, hover.toString()); // also add the hover using the reference feature as key if (!referenceAdded) { addToHoverMap(feature, hover.toString()); referenceAdded = true; } } } } } } }
Example 9
Source File: ChartElementUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Checks if a attribute is set value. * * @param eContainer * @param attribute * @return true if attribute is set value. */ public static boolean isSetEObjectAttribute( EObject eContainer, String attribute ) { EStructuralFeature esf = eContainer.eClass( ) .getEStructuralFeature( attribute ); if ( esf == null ) { return false; } return eContainer.eIsSet( esf ); }
Example 10
Source File: Bpmn2ResourceImpl.java From fixflow with Apache License 2.0 | 5 votes |
/** * Set the ID attribute of cur to a generated ID, if it is not already set. * @param obj The object whose ID should be set. */ protected static void setIdIfNotSet(EObject obj) { if (obj.eClass() != null) { EStructuralFeature idAttr = obj.eClass().getEIDAttribute(); if (idAttr != null && !obj.eIsSet(idAttr)) { obj.eSet(idAttr, EcoreUtil.generateUUID()); } } }
Example 11
Source File: OrderedEmfFormatter.java From n4js with Eclipse Public License 1.0 | 4 votes |
private static void objToStrImpl(Object obj, String indent, Appendable buf) throws Exception { String innerIdent = INDENT + indent; if (obj instanceof EObject) { EObject eobj = (EObject) obj; buf.append(eobj.eClass().getName()).append(" {\n"); for (EStructuralFeature f : getAllFeatures(eobj.eClass())) { if (!eobj.eIsSet(f)) continue; buf.append(innerIdent); if (f instanceof EReference) { EReference r = (EReference) f; if (r.isContainment()) { buf.append("cref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); objToStrImpl(eobj.eGet(f), innerIdent, buf); } else { buf.append("ref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); refToStr(eobj, r, innerIdent, buf); } } else if (f instanceof EAttribute) { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); // logger.debug(Msg.create("Path:").path(eobj)); Object at = eobj.eGet(f); if (eobj != at) objToStrImpl(at, innerIdent, buf); else buf.append("<same as container object>"); } else { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(" ??????"); } buf.append('\n'); } buf.append(indent).append("}"); return; } if (obj instanceof FeatureMap.Entry) { FeatureMap.Entry e = (FeatureMap.Entry) obj; buf.append(e.getEStructuralFeature().getEContainingClass().getName()); buf.append("."); buf.append(e.getEStructuralFeature().getName()); buf.append("->"); objToStrImpl(e.getValue(), innerIdent, buf); return; } if (obj instanceof Collection<?>) { int counter = 0; Collection<?> coll = (Collection<?>) obj; buf.append("[\n"); for (Object o : coll) { buf.append(innerIdent); printInt(counter++, coll.size(), buf); buf.append(": "); objToStrImpl(o, innerIdent, buf); buf.append("\n"); } buf.append(indent + "]"); return; } if (obj != null) { buf.append("'").append(Strings.notNull(obj)).append("'"); return; } buf.append("null"); }
Example 12
Source File: EObjectFeatureMerger.java From n4js with Eclipse Public License 1.0 | 4 votes |
private EObject merge(final EObject from, final EObject to, final Collection<Object> visitedObjects) { if (null == from || null == to) { return null; } // This is against cycles through EReferences. if (visitedObjects.contains(from) || visitedObjects.contains(to)) { return to; } visitedObjects.add(to); visitedObjects.add(from); final Collection<EStructuralFeature> fromFeatures = from.eClass().getEAllStructuralFeatures(); for (final EStructuralFeature feature : fromFeatures) { if (-1 != to.eClass().getFeatureID(feature) && feature.isChangeable()) { if (from.eIsSet(feature)) { final Object fromValue = from.eGet(feature, true); final Object toValue = to.eGet(feature, true); if (null == toValue) { to.eSet(feature, fromValue); } else { if (feature.isMany()) { @SuppressWarnings("unchecked") final Collection<Object> toManyValue = (Collection<Object>) toValue; @SuppressWarnings("unchecked") final Collection<Object> fromManyValue = (Collection<Object>) fromValue; for (final Iterator<Object> itr = fromManyValue.iterator(); itr.hasNext(); /**/) { final Object fromElement = itr.next(); if (!contains(toManyValue, fromElement)) { itr.remove(); toManyValue.add(fromElement); } } } else { if (feature instanceof EAttribute) { to.eSet(feature, fromValue); } else if (feature instanceof EReference) { to.eSet(feature, merge((EObject) fromValue, (EObject) toValue, visitedObjects)); } } } } } } return to; }
Example 13
Source File: DefaultTransientValueService.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public boolean isTransient(EObject owner, EStructuralFeature feature, int index) { return feature.isTransient() || !owner.eIsSet(feature) || isContainerReferenceInSameResource(owner, feature); }
Example 14
Source File: EmfFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private static void objToStrImpl(Object obj, String indent, Appendable buf, Predicate<EStructuralFeature> ignoredFeatures) throws Exception { String innerIdent = INDENT + indent; if (obj instanceof EObject) { EObject eobj = (EObject) obj; buf.append(eobj.eClass().getName()).append(" {\n"); for (EStructuralFeature f : eobj.eClass().getEAllStructuralFeatures()) { if (!eobj.eIsSet(f) || ignoredFeatures.apply(f)) continue; buf.append(innerIdent); if (f instanceof EReference) { EReference r = (EReference) f; if (r.isContainment()) { buf.append("cref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); objToStrImpl(eobj.eGet(f), innerIdent, buf, ignoredFeatures); } else { buf.append("ref "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); refToStr(eobj, r, innerIdent, buf); } } else if (f instanceof EAttribute) { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(SPACE); // logger.debug(Msg.create("Path:").path(eobj)); Object at = eobj.eGet(f); if (eobj != at) objToStrImpl(at, innerIdent, buf, ignoredFeatures); else buf.append("<same as container object>"); } else { buf.append("attr "); buf.append(f.getEType().getName()).append(SPACE); buf.append(f.getName()).append(" ??????"); } buf.append('\n'); } buf.append(indent).append("}"); return; } if(obj instanceof FeatureMap.Entry) { FeatureMap.Entry e = (FeatureMap.Entry)obj; buf.append(e.getEStructuralFeature().getEContainingClass().getName()); buf.append("."); buf.append(e.getEStructuralFeature().getName()); buf.append("->"); objToStrImpl(e.getValue(), innerIdent, buf, ignoredFeatures); return ; } if (obj instanceof Collection<?>) { int counter = 0; Collection<?> coll = (Collection<?>) obj; buf.append("[\n"); for (Object o : coll) { buf.append(innerIdent); printInt(counter++, coll.size(), buf); buf.append(": "); objToStrImpl(o, innerIdent, buf, ignoredFeatures); buf.append("\n"); } buf.append(indent + "]"); return; } if (obj != null) { buf.append("'").append(Strings.notNull(obj)).append("'"); return; } buf.append("null"); }
Example 15
Source File: AbstractOutlineTreeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** * Creates children for all {@link EStructuralFeatures} (that are set) of the given {@link EObject} model element. {@inheritDoc} * * @param parentNode * the parent {@link IOutlineNode} * @param modelElement * a valid {@link EObject} */ @SuppressWarnings({"unchecked", "PMD.NPathComplexity"}) @Override protected void internalCreateChildren(final IOutlineNode parentNode, final EObject modelElement) { // from all structural features, select only those which are set and retrieve the text location // TODO : sorting for feature lists needs to be based on the objects in the list, not the feature. List<Pair<Integer, EStructuralFeature>> pairsLocationFeature = Lists.newArrayList(); for (EStructuralFeature structuralFeature : modelElement.eClass().getEAllStructuralFeatures()) { if (modelElement.eIsSet(structuralFeature)) { int offset = 0; List<INode> nodes = NodeModelUtils.findNodesForFeature(modelElement, structuralFeature); if (!nodes.isEmpty()) { offset = nodes.get(0).getTotalOffset(); } pairsLocationFeature.add(Tuples.create(offset, structuralFeature)); } } // sort the features according to their appearance in the source text Collections.sort(pairsLocationFeature, new Comparator<Pair<Integer, EStructuralFeature>>() { @Override public int compare(final Pair<Integer, EStructuralFeature> o1, final Pair<Integer, EStructuralFeature> o2) { return o1.getFirst() - o2.getFirst(); } }); // go through the sorted list of children and create nodes for (Pair<Integer, EStructuralFeature> pairLocationFeature : pairsLocationFeature) { EStructuralFeature feature = pairLocationFeature.getSecond(); if (feature instanceof EAttribute) { if (getRelevantElements().contains(feature)) { createNodeDispatcher.invoke(parentNode, modelElement, feature); } } else if (feature instanceof EReference && ((EReference) feature).isContainment()) { // only consider containment references IOutlineNode listNode = null; EList<EObject> featureElements; Object value = modelElement.eGet(feature); if (feature.isMany()) { featureElements = (EList<EObject>) value; if (getRelevantElements().contains(feature)) { listNode = createEStructuralFeatureNode(parentNode, modelElement, feature, getImageDescriptor(feature), feature.getName(), false); } } else { featureElements = new BasicEList<EObject>(); featureElements.add((EObject) value); } for (EObject childElement : featureElements) { if (childElement == null) { continue; } if (isRelevantElement(childElement)) { createNodeDispatcher.invoke(listNode != null ? listNode : parentNode, childElement); } else { createChildrenDispatcher.invoke(listNode != null ? listNode : parentNode, childElement); } } } } }
Example 16
Source File: AbstractOutlineTreeProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** * Creates a new structural feature node with a given image description and label. * * @param parentNode * the parent {@link IOutlineNode} * @param owner * a valid model element as {@link EObject} * @param feature * a structural feature {@link EStructuralFeature} * @param image * an image descriptor {@link ImageDescriptor} * @param text * the label text * @param isLeaf * true if feature is a leaf * @return newly created structural feature node */ protected EStructuralFeatureNode createEStructuralFeatureNode(final IOutlineNode parentNode, final EObject owner, final EStructuralFeature feature, final ImageDescriptor image, final Object text, final boolean isLeaf) { boolean isFeatureSet = owner.eIsSet(feature); EStructuralFeatureNode eStructuralFeatureNode = new EStructuralFeatureNode(owner, feature, parentNode, image, text, isLeaf || !isFeatureSet); if (isFeatureSet) { ITextRegion region = getLocationInFileProvider().getFullTextRegion(owner, feature, 0); if (feature.isMany()) { int numValues = ((Collection<?>) owner.eGet(feature)).size(); ITextRegion fullTextRegion = getLocationInFileProvider().getFullTextRegion(owner, feature, numValues - 1); if (fullTextRegion != null) { region = region.merge(fullTextRegion); } } eStructuralFeatureNode.setTextRegion(region); } return eStructuralFeatureNode; }