/** * only clones the element if it is contained in another {@link EObject} or another {@link Resource} */ public static <T extends EObject> T cloneIfContained(T eObject) { if (eObject != null && (eObject.eContainer()!=null || eObject.eResource()!=null)) return clone(eObject); return eObject; }
static StyleSpecification cloneAndFilterPropagatedStyles(StyleSpecification style, EObject obj) { StyleSpecification clonedStyle = (StyleSpecification)EcoreUtil2.clone(style); if (clonedStyle instanceof StyleSpecification) { if (clonedStyle.getSuperStyles() != null) { EList<StyleSpecification> superStyles = clonedStyle.getSuperStyles(); List<StyleSpecification> filteredSuperStyles = new ArrayList<StyleSpecification>(); for (int i=0;i<superStyles.size();i++) { if (isPropagated(superStyles.get(i),obj)) { StyleSpecification clonedSuperStyle = cloneAndFilterPropagatedStyles(superStyles.get(i),obj); filteredSuperStyles.add(clonedSuperStyle); } } ((StyleSpecification) clonedStyle).getSuperStyles().clear(); ((StyleSpecification) clonedStyle).getSuperStyles().addAll(filteredSuperStyles); } } return clonedStyle; }
existingStyleSpec = (StyleSpecificationProperty)EcoreUtil2.clone(existingStyleSpec); propertyMap.put(classifierId,existingStyleSpec);
public JvmTypeReference getCommonParameterSuperType(final List<JvmTypeReference> types, List<JvmTypeReference> initiallyRequested) { Function<JvmTypeReference, String> getCanonicalName = new Function<JvmTypeReference, String>() { public String apply(JvmTypeReference from) { return from.getIdentifier(); } }; Set<String> allNames = Sets.newHashSet(Iterables.transform(types, getCanonicalName)); if (allNames.size() == 1) return types.get(0); if (types.size() == initiallyRequested.size()) { Set<String> initiallyRequestedNames = Sets.newHashSet(Iterables.transform(initiallyRequested, getCanonicalName)); if (initiallyRequestedNames.equals(allNames)) { // recursion - return object wildcard JvmTypeReference objectTypeReference = typeReferences.getTypeForName(Object.class, types.get(0).getType()); return typeReferences.wildCardExtends(objectTypeReference); } } JvmTypeReference superType = getCommonSuperType(types); if (superType instanceof JvmWildcardTypeReference) return superType; JvmWildcardTypeReference wildcardTypeReference = factory.createJvmWildcardTypeReference(); if (superType != null) { JvmUpperBound upperBound = factory.createJvmUpperBound(); upperBound.setTypeReference(EcoreUtil2.clone(superType)); wildcardTypeReference.getConstraints().add(upperBound); } return wildcardTypeReference; }
StylePropertyOther spec = (StylePropertyOther)specProperty; if (spec.getDynamicTabPage() != null) { existing.setDynamicTabPage((BoolLiteral)EcoreUtil2.clone(spec.getDynamicTabPage())); existing.setMargin((PaddingWidth)EcoreUtil2.clone(spec.getMargin())); existing.setSpacing((PaddingWidth)EcoreUtil2.clone(spec.getSpacing())); existing.setThousandSeperator((BoolLiteral)EcoreUtil2.clone(spec.getThousandSeperator())); StylePropertyFlag spec = (StylePropertyFlag)specProperty; if (spec.getEnabledExpression() != null) { existing.setEnabledExpression((EqualityExpr)EcoreUtil2.clone(spec.getEnabledExpression())); existing.setMandatoryExpression((EqualityExpr)EcoreUtil2.clone(spec.getMandatoryExpression())); existing.setVisibleExpression((EqualityExpr)EcoreUtil2.clone(spec.getVisibleExpression())); existing.setCollapsedExpression((EqualityExpr)EcoreUtil2.clone(spec.getCollapsedExpression())); existing.setAvailableExpression((EqualityExpr)EcoreUtil2.clone(spec.getAvailableExpression())); existing.setEditableExpression((EqualityExpr)EcoreUtil2.clone(spec.getEditableExpression())); existing.setTabableExpression((EqualityExpr)EcoreUtil2.clone(spec.getTabableExpression())); StylePropertyTable spec = (StylePropertyTable)specProperty; if (spec.getGridVisible() != null) { existing.setGridVisible((BoolLiteral)EcoreUtil2.clone(spec.getGridVisible()));
result.setType(rawType); for(JvmTypeReference parameterSuperType: parameterSuperTypes) { result.getArguments().add(EcoreUtil2.clone(parameterSuperType));
/** * Create a clone of the original grammar. The clone will not refer to a node model. */ private Grammar cloneGrammarIntoNewResourceSet(final Grammar original) { final Resource originalResource = original.eResource(); XtextResourceSet _xtextResourceSet = new XtextResourceSet(); final XtextResourceSet clonedResourceSet = EcoreUtil2.<XtextResourceSet>clone(_xtextResourceSet, originalResource.getResourceSet()); final Resource clonedResource = clonedResourceSet.getResource(originalResource.getURI(), false); EObject _head = IterableExtensions.<EObject>head(clonedResource.getContents()); return ((Grammar) _head); }
_extensionToFactoryMap.put( FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl); final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet()); EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents()); final Grammar copy = ((Grammar) _head);