Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 354245 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/codegen/ecore/genmodel/GenClass.java (+7 lines)
Lines 624-627 Link Here
624
   * @since 2.4
624
   * @since 2.4
625
   */
625
   */
626
  boolean hasCollidingUnsetAccessorOperation(GenFeature genFeature);
626
  boolean hasCollidingUnsetAccessorOperation(GenFeature genFeature);
627
628
  /**
629
   * Returns as list that corresponds to {@link #getInterfaceExtends()}.
630
   * @since 2.8
631
   */
632
  List<String >getQualifiedInterfaceExtendsList();
633
  
627
}
634
}
(-)src/org/eclipse/emf/codegen/ecore/genmodel/GenModel.java (+24 lines)
Lines 32-38 Link Here
32
import org.eclipse.emf.common.util.EList;
32
import org.eclipse.emf.common.util.EList;
33
import org.eclipse.emf.ecore.EClass;
33
import org.eclipse.emf.ecore.EClass;
34
import org.eclipse.emf.ecore.EClassifier;
34
import org.eclipse.emf.ecore.EClassifier;
35
import org.eclipse.emf.ecore.EOperation;
35
import org.eclipse.emf.ecore.EPackage;
36
import org.eclipse.emf.ecore.EPackage;
37
import org.eclipse.emf.ecore.EStructuralFeature;
38
import org.eclipse.emf.ecore.ETypeParameter;
36
import org.eclipse.emf.ecore.util.ExtendedMetaData;
39
import org.eclipse.emf.ecore.util.ExtendedMetaData;
37
import org.eclipse.jdt.core.formatter.CodeFormatter;
40
import org.eclipse.jdt.core.formatter.CodeFormatter;
38
41
Lines 2794-2797 Link Here
2794
   * @since 2.7
2797
   * @since 2.7
2795
   */
2798
   */
2796
  String getQualifiedEditorEntryPointClassName();
2799
  String getQualifiedEditorEntryPointClassName();
2800
 
2801
  /**
2802
   * Set up reasonable initial defaults.
2803
   * @since 2.8
2804
   */
2805
  void initialize();
2806
 
2807
  /**
2808
   * @since 2.8
2809
   */
2810
  GenTypeParameter findGenTypeParameter(ETypeParameter eTypeParameter);
2811
 
2812
  /**
2813
   * @since 2.8
2814
   */
2815
  GenFeature findGenFeature(EStructuralFeature eStructuralFeature);
2816
 
2817
  /**
2818
   * @since 2.8
2819
   */
2820
  GenOperation findGenOperation(EOperation eOperation);
2797
}
2821
}
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelImpl.java (+174 lines)
Lines 30-36 Link Here
30
import java.util.Map;
30
import java.util.Map;
31
import java.util.Set;
31
import java.util.Set;
32
32
33
import org.eclipse.core.resources.IProject;
34
import org.eclipse.core.resources.IWorkspace;
35
import org.eclipse.core.resources.ResourcesPlugin;
33
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.IStatus;
37
import org.eclipse.jdt.core.IClasspathEntry;
38
import org.eclipse.jdt.core.IJavaProject;
39
import org.eclipse.jdt.core.JavaCore;
34
import org.eclipse.jdt.core.ToolFactory;
40
import org.eclipse.jdt.core.ToolFactory;
35
import org.eclipse.jdt.core.formatter.CodeFormatter;
41
import org.eclipse.jdt.core.formatter.CodeFormatter;
36
42
Lines 75-87 Link Here
75
import org.eclipse.emf.common.util.TreeIterator;
81
import org.eclipse.emf.common.util.TreeIterator;
76
import org.eclipse.emf.common.util.URI;
82
import org.eclipse.emf.common.util.URI;
77
import org.eclipse.emf.common.util.UniqueEList;
83
import org.eclipse.emf.common.util.UniqueEList;
84
import org.eclipse.emf.ecore.EAnnotation;
85
import org.eclipse.emf.ecore.EAttribute;
78
import org.eclipse.emf.ecore.EClass;
86
import org.eclipse.emf.ecore.EClass;
79
import org.eclipse.emf.ecore.EClassifier;
87
import org.eclipse.emf.ecore.EClassifier;
80
import org.eclipse.emf.ecore.EDataType;
88
import org.eclipse.emf.ecore.EDataType;
81
import org.eclipse.emf.ecore.EEnum;
89
import org.eclipse.emf.ecore.EEnum;
90
import org.eclipse.emf.ecore.EModelElement;
82
import org.eclipse.emf.ecore.EObject;
91
import org.eclipse.emf.ecore.EObject;
92
import org.eclipse.emf.ecore.EOperation;
83
import org.eclipse.emf.ecore.EPackage;
93
import org.eclipse.emf.ecore.EPackage;
84
import org.eclipse.emf.ecore.EStructuralFeature;
94
import org.eclipse.emf.ecore.EStructuralFeature;
95
import org.eclipse.emf.ecore.ETypeParameter;
85
import org.eclipse.emf.ecore.EValidator;
96
import org.eclipse.emf.ecore.EValidator;
86
import org.eclipse.emf.ecore.EcorePackage;
97
import org.eclipse.emf.ecore.EcorePackage;
87
import org.eclipse.emf.ecore.InternalEObject;
98
import org.eclipse.emf.ecore.InternalEObject;
Lines 8995-9000 Link Here
8995
  {
9006
  {
8996
    return super.findGenClassifier(classifier);
9007
    return super.findGenClassifier(classifier);
8997
  }
9008
  }
9009
9010
  @Override
9011
  public GenFeature findGenFeature(EStructuralFeature feature)
9012
  {
9013
    return super.findGenFeature(feature);
9014
  }
9015
9016
  @Override
9017
  public GenOperation findGenOperation(EOperation operation)
9018
  {
9019
    return super.findGenOperation(operation);
9020
  }
9021
  
9022
  public GenTypeParameter findGenTypeParameter(ETypeParameter eTypeParameter)
9023
  {
9024
    for (EObject eObject = eTypeParameter.eContainer(); eObject != null; eObject = eObject.eContainer())
9025
    {
9026
      if (eObject instanceof EOperation)
9027
      {
9028
        EOperation eOperation = (EOperation)eObject;
9029
        int index = eOperation.getETypeParameters().indexOf(eTypeParameter);
9030
        if (index != -1)
9031
        {
9032
          GenOperation genOperation = findGenOperation(eOperation);
9033
          return genOperation.getGenTypeParameters().get(index);
9034
        }
9035
      }
9036
      else if (eObject instanceof EClassifier)
9037
      {
9038
        EClassifier eClassifier = (EClassifier)eObject;
9039
        int index = eClassifier.getETypeParameters().indexOf(eTypeParameter);
9040
        if (index != -1)
9041
        {
9042
          GenClassifier genClassifier = findGenClassifier(eClassifier);
9043
          return genClassifier.getGenTypeParameters().get(index);
9044
        }
9045
      }
9046
    }
9047
    return null;
9048
  }
8998
  
9049
  
8999
  public boolean isSuppressedAnnotation(String source)
9050
  public boolean isSuppressedAnnotation(String source)
9000
  {
9051
  {
Lines 9378-9381 Link Here
9378
    return getEditorModuleName();
9429
    return getEditorModuleName();
9379
  }
9430
  }
9380
9431
9432
  public void initialize()
9433
  {
9434
    Resource resource = eResource();
9435
    if (resource != null)
9436
    {
9437
      URI uri = resource.getURI();
9438
      setModelDirectory(EclipseHelper.getModelDirectory(uri));
9439
      setComplianceLevel(EclipseHelper.getComplianceLevel(uri));
9440
    }
9441
    setUpdateClasspath(false);
9442
    setOperationReflection(true);
9443
    setMinimalReflectiveMethods(true);
9444
    setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container");
9445
    GenPackage mainGenPackage = getMainGenPackage();
9446
    setModelName(mainGenPackage.getPrefix());
9447
    GenRuntimeVersion[] values = GenRuntimeVersion.values();
9448
    setRuntimeVersion(values[values.length - 1]);
9449
    
9450
    handleAnnotations(this, mainGenPackage.getEcorePackage());
9451
    for (TreeIterator<EObject> i = eAllContents(); i.hasNext();)
9452
    {
9453
      EObject content = i.next();
9454
      if (content instanceof GenBase)
9455
      {
9456
        GenBase genBase = (GenBase)content;
9457
        EModelElement eModelElement = genBase.getEcoreModelElement();
9458
        if (eModelElement != null)
9459
        {
9460
          handleAnnotations(genBase, eModelElement);
9461
        }
9462
      }
9463
    }
9464
  }
9465
  
9466
  protected void handleAnnotations(GenBase genBase, EModelElement eModelElement)
9467
  {
9468
    EAnnotation eAnnotation = eModelElement.getEAnnotation(GenModelPackage.eNS_URI);
9469
    if (eAnnotation != null)
9470
    {
9471
      EClass eClass = genBase.eClass();
9472
      for (Map.Entry<String, String> entry : eAnnotation.getDetails())
9473
      {
9474
        EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(entry.getKey());
9475
        if (eStructuralFeature instanceof EAttribute)
9476
        {
9477
          EAttribute eAttribute = (EAttribute)eStructuralFeature;
9478
          genBase.eSet(eStructuralFeature, EcoreUtil.createFromString(eAttribute.getEAttributeType(), entry.getValue()));
9479
        }
9480
      }
9481
    }
9482
  }
9483
9484
  private static class EclipseHelper
9485
  {
9486
    static String getModelDirectory(URI uri)
9487
    {
9488
      if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE)
9489
      {
9490
        try
9491
        {
9492
          IWorkspace workspace = ResourcesPlugin.getWorkspace();
9493
          IProject project = workspace.getRoot().getProject(uri.segment(1));
9494
          IJavaProject javaProject = JavaCore.create(project);
9495
          IClasspathEntry[] classpath = javaProject.getRawClasspath();
9496
          IClasspathEntry bestEntry = null;
9497
          for (IClasspathEntry classpathEntry : classpath)
9498
          {
9499
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
9500
            {
9501
              // Look for the first entry that's Java source.
9502
              if (bestEntry == null)
9503
              {
9504
                bestEntry = classpathEntry;
9505
              }
9506
              // If there's a src-gen entry, prefer that over all others.
9507
              //
9508
              else if (classpathEntry.getPath().toString().endsWith("src-gen"))
9509
              {
9510
                bestEntry = classpathEntry;
9511
              }
9512
            }
9513
          }
9514
          return bestEntry == null ? project.getFullPath() + "/src" : bestEntry.getPath().toString();
9515
        }
9516
        catch (Exception exception)
9517
        {
9518
          CodeGenEcorePlugin.INSTANCE.log(exception);
9519
        }
9520
      }
9521
      return null;
9522
    }
9523
    
9524
    static GenJDKLevel getComplianceLevel(URI uri)
9525
    {
9526
      if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE)
9527
      {
9528
        try
9529
        {
9530
          IWorkspace workspace = ResourcesPlugin.getWorkspace();
9531
          IProject project = workspace.getRoot().getProject(uri.segment(2));
9532
          String complianceLevel = CodeGenUtil.EclipseUtil.getJavaComplianceLevel(project);
9533
          if ("1.5".equals(complianceLevel))
9534
          {
9535
            return GenJDKLevel.JDK50_LITERAL;
9536
          }
9537
          else if ("1.6".equals(complianceLevel))
9538
          {
9539
            return GenJDKLevel.JDK60_LITERAL;
9540
          }
9541
          else if ("1.4".equals(complianceLevel))
9542
          {
9543
            return GenJDKLevel.JDK14_LITERAL;
9544
          }
9545
        }
9546
        catch (Exception exception)
9547
        {
9548
          CodeGenEcorePlugin.INSTANCE.log(exception);
9549
        }
9550
      }
9551
      return GenJDKLevel.JDK50_LITERAL;
9552
    }
9553
  }
9554
9381
} //GenModelImpl
9555
} //GenModelImpl
(-)src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenTypeParameterImpl.java (+7 lines)
Lines 23-28 Link Here
23
import org.eclipse.emf.common.notify.Notification;
23
import org.eclipse.emf.common.notify.Notification;
24
import org.eclipse.emf.ecore.EClass;
24
import org.eclipse.emf.ecore.EClass;
25
import org.eclipse.emf.ecore.EGenericType;
25
import org.eclipse.emf.ecore.EGenericType;
26
import org.eclipse.emf.ecore.EModelElement;
26
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.emf.ecore.ETypeParameter;
28
import org.eclipse.emf.ecore.ETypeParameter;
28
import org.eclipse.emf.ecore.InternalEObject;
29
import org.eclipse.emf.ecore.InternalEObject;
Lines 252-256 Link Here
252
    }
253
    }
253
    return result.toString().trim();
254
    return result.toString().trim();
254
  }
255
  }
256
  
257
  @Override
258
  public EModelElement getEcoreModelElement()
259
  {
260
    return getEcoreTypeParameter();
261
  }
255
262
256
} //GenTypeParameterImpl
263
} //GenTypeParameterImpl
(-)plugin.properties (+1 lines)
Lines 122-127 Link Here
122
_UI_SettingDelegateRegistry_extensionpoint = Feature Setting Delegate Factory Registry
122
_UI_SettingDelegateRegistry_extensionpoint = Feature Setting Delegate Factory Registry
123
_UI_InvocationDelegateRegistry_extensionpoint = Operation Invocation Delegate Factory Registry
123
_UI_InvocationDelegateRegistry_extensionpoint = Operation Invocation Delegate Factory Registry
124
_UI_QueryDelegateRegistry_extensionpoint = Query Delegate Factory Registry
124
_UI_QueryDelegateRegistry_extensionpoint = Query Delegate Factory Registry
125
_UI_ConversionDelegateRegistry_extensionpoint = Conversion Delegate Factory Registry
125
126
126
_UI_GenericInvariant_diagnostic = The ''{0}'' invariant is violated on ''{1}''
127
_UI_GenericInvariant_diagnostic = The ''{0}'' invariant is violated on ''{1}''
127
_UI_GenericConstraint_diagnostic = The ''{0}'' constraint is violated on ''{1}''
128
_UI_GenericConstraint_diagnostic = The ''{0}'' constraint is violated on ''{1}''
(-)plugin.xml (+1 lines)
Lines 14-19 Link Here
14
   <extension-point id="setting_delegate" name="%_UI_SettingDelegateRegistry_extensionpoint" schema="schema/setting_delegate.exsd"/>
14
   <extension-point id="setting_delegate" name="%_UI_SettingDelegateRegistry_extensionpoint" schema="schema/setting_delegate.exsd"/>
15
   <extension-point id="invocation_delegate" name="%_UI_InvocationDelegateRegistry_extensionpoint" schema="schema/invocation_delegate.exsd"/>
15
   <extension-point id="invocation_delegate" name="%_UI_InvocationDelegateRegistry_extensionpoint" schema="schema/invocation_delegate.exsd"/>
16
   <extension-point id="query_delegate" name="%_UI_QueryDelegateRegistry_extensionpoint" schema="schema/query_delegate.exsd"/>
16
   <extension-point id="query_delegate" name="%_UI_QueryDelegateRegistry_extensionpoint" schema="schema/query_delegate.exsd"/>
17
   <extension-point id="conversion_delegate" name="%_UI_ConversionDelegateRegistry_extensionpoint" schema="schema/conversion_delegate.exsd"/>
17
18
18
   <extension point="org.eclipse.emf.ecore.generated_package">
19
   <extension point="org.eclipse.emf.ecore.generated_package">
19
      <package
20
      <package
(-)schema/conversion_delegate.exsd (+124 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.emf.ecore" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.emf.ecore" id="conversion_delegate" name="Conversion Delegate Factory Registry"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point is used to define a factory for conversion delegates whose type is identified by a URI. The global EMF conversion delegate factory registry, &lt;samp&gt;EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE&lt;/samp&gt;, is used to record the registration.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="factory" minOccurs="1" maxOccurs="unbounded"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  A fully qualified identifier of the target extension point.
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  An optional identifier of the extension instance.
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  An optional name of the extension instance.
41
               </documentation>
42
            </annotation>
43
         </attribute>
44
      </complexType>
45
   </element>
46
47
   <element name="factory">
48
      <annotation>
49
         <appInfo>
50
            <meta.element labelAttribute="id"/>
51
         </appInfo>
52
      </annotation>
53
      <complexType>
54
         <attribute name="uri" type="string" use="required">
55
            <annotation>
56
               <documentation>
57
                  A URI identifying the type of conversion delegates that can be created by the factory.
58
               </documentation>
59
            </annotation>
60
         </attribute>
61
         <attribute name="class" type="string" use="required">
62
            <annotation>
63
               <documentation>
64
                  The fully qualified name of a Java class implementing &lt;samp&gt;org.eclipse.emf.ecore.EDataType.Internal.Delegate.Factory&lt;/samp&gt;.
65
               </documentation>
66
               <appInfo>
67
                  <meta.attribute kind="java" basedOn="org.eclipse.emf.ecore.EDataType.Internal.ConversionDelegate.Factory"/>
68
               </appInfo>
69
            </annotation>
70
         </attribute>
71
      </complexType>
72
   </element>
73
74
   <annotation>
75
      <appInfo>
76
         <meta.section type="since"/>
77
      </appInfo>
78
      <documentation>
79
         2.8.0
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appInfo>
85
         <meta.section type="examples"/>
86
      </appInfo>
87
      <documentation>
88
         Following is an example of how an conversion delegate factory can be registered: 
89
&lt;pre&gt;
90
  &lt;extension point=&quot;org.eclipse.emf.ecore.conversion_delegate&quot; &gt;
91
    &lt;factory uri=&quot;http://www.eclipse.org/emf/2002/Ecore/Javascript&quot; class=&quot;org.eclipse.emf.js4emf.ecore.internal.delegates.JavascriptDelegateFactory&quot;/&gt; 
92
  &lt;/extension&gt;
93
&lt;/pre&gt;
94
      </documentation>
95
   </annotation>
96
97
   <annotation>
98
      <appInfo>
99
         <meta.section type="apiInfo"/>
100
      </appInfo>
101
      <documentation>
102
         The value of the class attribute must represent a class that implements &lt;samp&gt;org.eclipse.emf.ecore.EDataType.Internal.ConversionDelegate.Factory&lt;/samp&gt; and has a no argument contructor.
103
&lt;p&gt;
104
A conversion delegate factory can be also registered from the source code with the &lt;samp&gt;EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE&lt;/samp&gt; as follows:
105
&lt;/p&gt;
106
&lt;pre&gt;
107
  EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE.put(&quot;http://www.eclipse.org/emf/2002/Ecore/Javascript&quot;, new JavascriptDelegateFactory());
108
&lt;/pre&gt;
109
      </documentation>
110
   </annotation>
111
112
113
   <annotation>
114
      <appInfo>
115
         <meta.section type="copyright"/>
116
      </appInfo>
117
      <documentation>
118
         Copyright (c) 2011 Hallvard Traetteberg and others.&lt;br&gt;
119
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at &lt;a 
120
href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
121
      </documentation>
122
   </annotation>
123
124
</schema>
(-)src/org/eclipse/emf/ecore/EDataType.java (+101 lines)
Lines 16-21 Link Here
16
 */
16
 */
17
package org.eclipse.emf.ecore;
17
package org.eclipse.emf.ecore;
18
18
19
import java.util.HashMap;
20
import java.util.Map;
19
21
20
22
21
/**
23
/**
Lines 70-73 Link Here
70
   */
72
   */
71
  void setSerializable(boolean value);
73
  void setSerializable(boolean value);
72
74
75
  /**
76
   * Internal API implemented by all data types.
77
   * @since 2.8
78
   */
79
  interface Internal
80
  {
81
    /**
82
     * An API for converting values of the data type to and from a string representation.
83
     */
84
    interface ConversionDelegate
85
    {
86
      /**
87
       * A factory for creating conversion delegates.
88
       */
89
      interface Factory
90
      {
91
        /**
92
         * Creates a conversion delegate for the given EDataType.
93
         * @param eDataType the EDataType for which a conversion delegate is to be created.
94
         * @return a new conversion delegate for the given EDataType.
95
         */
96
        ConversionDelegate createConversionDelegate(EDataType eDataType);
97
98
        /**
99
         * A <code>Factory</code> wrapper that is used by the {@link Factory.Registry}.
100
         */
101
        interface Descriptor
102
        {
103
          Factory getFactory();
104
        }
105
106
        /**
107
         * A registry of factories for creating conversion delegates.
108
         */
109
        interface Registry extends Map<String, Object>
110
        {
111
          Registry INSTANCE = new Impl();
112
113
          Factory getFactory(String uri);
114
115
          class Impl extends HashMap<String, Object> implements Registry
116
          {
117
            private static final long serialVersionUID = 1L;
118
119
            @Override
120
            public Object get(Object key)
121
            {
122
              Object factory = super.get(key);
123
              if (factory instanceof Descriptor)
124
              {
125
                Descriptor factoryDescriptor = (Descriptor)factory;
126
                factory = factoryDescriptor.getFactory();
127
                put((String)key, factory);
128
                return factory;
129
              }
130
              else
131
              {
132
                return factory;
133
              }
134
            }
135
136
            public Factory getFactory(String uri)
137
            {
138
              return (Factory)get(uri);
139
            }
140
          }
141
        }
142
      }
143
144
      /**
145
       * Converts a value of the data type to a string literal.
146
       * @param value the value to be converted.
147
       * @return the literal representation of the value.
148
       */
149
      String convertToString(Object value);
150
151
      /**
152
       * Creates a value of the data type from a string literal.
153
       * @param literal the string literal to be converted.
154
       * @return the value of the literal representation.
155
       */
156
      Object createFromString(String literal);
157
    }
158
159
    /**
160
     * Returns the delegate for this data type.
161
     * A default delegate implementation need not be available,
162
     * so this might <code>null</code>.
163
     * @return the delegate for this feature.
164
     */
165
    ConversionDelegate getConversionDelegate();
166
167
    /**
168
     * Sets the specialized delegate for this data type.
169
     * @param settingDelegate the specialized delegate.
170
     */
171
    void setConversionDelegate(ConversionDelegate conversionDelegate);
172
  }
173
73
} //EDataType
174
} //EDataType
(-)src/org/eclipse/emf/ecore/impl/EDataTypeImpl.java (-1 / +33 lines)
Lines 18-23 Link Here
18
18
19
19
20
import java.util.Collection;
20
import java.util.Collection;
21
import java.util.List;
21
22
22
import org.eclipse.emf.common.notify.Notification;
23
import org.eclipse.emf.common.notify.Notification;
23
import org.eclipse.emf.ecore.EAnnotation;
24
import org.eclipse.emf.ecore.EAnnotation;
Lines 25-30 Link Here
25
import org.eclipse.emf.ecore.EDataType;
26
import org.eclipse.emf.ecore.EDataType;
26
import org.eclipse.emf.ecore.ETypeParameter;
27
import org.eclipse.emf.ecore.ETypeParameter;
27
import org.eclipse.emf.ecore.EcorePackage;
28
import org.eclipse.emf.ecore.EcorePackage;
29
import org.eclipse.emf.ecore.util.EcoreUtil;
28
30
29
31
30
/**
32
/**
Lines 40-46 Link Here
40
 *
42
 *
41
 * @generated
43
 * @generated
42
 */
44
 */
43
public class EDataTypeImpl extends EClassifierImpl implements EDataType
45
public class EDataTypeImpl extends EClassifierImpl implements EDataType, EDataType.Internal
44
{
46
{
45
  /**
47
  /**
46
   * The default value of the '{@link #isSerializable() <em>Serializable</em>}' attribute.
48
   * The default value of the '{@link #isSerializable() <em>Serializable</em>}' attribute.
Lines 326-329 Link Here
326
    return result.toString();
328
    return result.toString();
327
  }
329
  }
328
330
331
  protected ConversionDelegate conversionDelegate;
332
  protected boolean conversionDelegateIsSet;
333
334
  public ConversionDelegate getConversionDelegate()
335
  {
336
    if (conversionDelegate == null)
337
    {
338
      List<String> conversionDelegates = EcoreUtil.getConversionDelegates(getEPackage());
339
      if (!conversionDelegates.isEmpty())
340
      {
341
        for (String eDataTypeDelegateUri : conversionDelegates)
342
        {
343
          String body = EcoreUtil.getAnnotation(this, eDataTypeDelegateUri, "createFromString");
344
          if (body != null)
345
          {
346
            EDataType.Internal.ConversionDelegate.Factory eDataTypeDelegateFactory = EcoreUtil.getConversionDelegateFactory(this);
347
            conversionDelegate = eDataTypeDelegateFactory.createConversionDelegate(this);
348
            conversionDelegateIsSet = true;
349
          }
350
        }
351
      }
352
    }
353
    return conversionDelegate;
354
  }
355
356
  public void setConversionDelegate(ConversionDelegate conversionDelegate)
357
  {
358
    this.conversionDelegate = conversionDelegate;
359
  }
360
329
}
361
}
(-)src/org/eclipse/emf/ecore/impl/EFactoryImpl.java (+12 lines)
Lines 359-364 Link Here
359
      throw new IllegalArgumentException("The value '" + stringValue + "' does not match any member types of the union datatype '" + eDataType.getName() + "'");
359
      throw new IllegalArgumentException("The value '" + stringValue + "' does not match any member types of the union datatype '" + eDataType.getName() + "'");
360
    }
360
    }
361
361
362
    EDataType.Internal.ConversionDelegate conversionDelegate = ((EDataType.Internal)eDataType).getConversionDelegate();
363
    if (conversionDelegate != null)
364
    {
365
      return conversionDelegate.createFromString(stringValue);
366
    }
367
362
    Class<?> c = EcoreUtil.wrapperClassFor(eDataType.getInstanceClass());
368
    Class<?> c = EcoreUtil.wrapperClassFor(eDataType.getInstanceClass());
363
    if (c == null) return null;
369
    if (c == null) return null;
364
370
Lines 523-528 Link Here
523
      throw new IllegalArgumentException("Invalid value: '" + objectValue + "' for datatype :"+eDataType.getName());
529
      throw new IllegalArgumentException("Invalid value: '" + objectValue + "' for datatype :"+eDataType.getName());
524
    }
530
    }
525
531
532
    EDataType.Internal.ConversionDelegate conversionDelegate = ((EDataType.Internal)eDataType).getConversionDelegate();
533
    if (conversionDelegate != null)
534
    {
535
      return conversionDelegate.convertToString(objectValue);
536
    }
537
526
    if (objectValue == null)
538
    if (objectValue == null)
527
    {
539
    {
528
      return null;
540
      return null;
(-)src/org/eclipse/emf/ecore/plugin/ConversionDelegateFactoryRegistryReader.java (+92 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2011 Hallvard Traetteberg and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *   Hallvard Traetteberg - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id$
16
 */
17
package org.eclipse.emf.ecore.plugin;
18
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.emf.ecore.EDataType;
22
23
24
/**
25
 * A plugin extension reader that populates the
26
 * {@link org.eclipse.emf.ecore.util.EDataType.ConversionDelegate.Factory.Registry#INSTANCE global} EDataType delegate factory registry.
27
 * Clients are not expected to use this class directly.
28
 */
29
class ConversionDelegateFactoryRegistryReader extends RegistryReader
30
{
31
  static class ConversionDelegateFactoryDescriptor extends PluginClassDescriptor implements EDataType.Internal.ConversionDelegate.Factory.Descriptor
32
  {
33
    protected EDataType.Internal.ConversionDelegate.Factory factory;
34
35
    public ConversionDelegateFactoryDescriptor(IConfigurationElement e, String attrName)
36
    {
37
      super(e, attrName);
38
    }
39
40
    public EDataType.Internal.ConversionDelegate.Factory getFactory()
41
    {
42
      if (factory == null)
43
      {
44
        factory = (EDataType.Internal.ConversionDelegate.Factory)createInstance();
45
      }
46
      return factory;
47
    }
48
  }
49
50
  static final String TAG_FACTORY = "factory";
51
  static final String ATT_URI = "uri";
52
  static final String ATT_CLASS = "class";
53
54
  public ConversionDelegateFactoryRegistryReader()
55
  {
56
    super(Platform.getExtensionRegistry(), EcorePlugin.getPlugin().getBundle().getSymbolicName(), EcorePlugin.CONVERSION_DELEGATE_PPID);
57
  }
58
59
  @Override
60
  protected boolean readElement(IConfigurationElement element, boolean add)
61
  {
62
    if (element.getName().equals(TAG_FACTORY))
63
    {
64
      String uri = element.getAttribute(ATT_URI);
65
      if (uri == null)
66
      {
67
        logMissingAttribute(element, ATT_URI);
68
      }
69
      else if (element.getAttribute(ATT_CLASS) == null)
70
      {
71
        logMissingAttribute(element, ATT_CLASS);
72
      }
73
      else if (add)
74
      {
75
        Object previous = EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE.put(uri, new ConversionDelegateFactoryDescriptor(element, ATT_CLASS));
76
        if (previous instanceof ConversionDelegateFactoryDescriptor)
77
        {
78
          ConversionDelegateFactoryDescriptor descriptor = (ConversionDelegateFactoryDescriptor)previous;
79
          EcorePlugin.INSTANCE.log("Both '" + descriptor.element.getContributor().getName() + "' and '" + element.getContributor().getName() + "' register a conversion delegate factory for '" + uri + "'");
80
        }
81
        return true;
82
      }
83
      else
84
      {
85
        EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE.remove(uri);
86
        return true;
87
      }
88
    }
89
90
    return false;
91
  }
92
}
(-)src/org/eclipse/emf/ecore/plugin/EcorePlugin.java (+1 lines)
Lines 639-642 Link Here
639
  public static final String SETTING_DELEGATE_PPID = "setting_delegate";
639
  public static final String SETTING_DELEGATE_PPID = "setting_delegate";
640
  public static final String INVOCATION_DELEGATE_PPID = "invocation_delegate";
640
  public static final String INVOCATION_DELEGATE_PPID = "invocation_delegate";
641
  public static final String QUERY_DELEGATE_PPID = "query_delegate";
641
  public static final String QUERY_DELEGATE_PPID = "query_delegate";
642
  public static final String CONVERSION_DELEGATE_PPID = "conversion_delegate";
642
}
643
}
(-)src/org/eclipse/emf/ecore/util/EObjectValidator.java (-1 / +1 lines)
Lines 1649-1655 Link Here
1649
         {
1649
         {
1650
           getValueLabel(eDataType, value, context),
1650
           getValueLabel(eDataType, value, context),
1651
           value == null ? "<null>" : value.getClass().getName(),
1651
           value == null ? "<null>" : value.getClass().getName(),
1652
           eDataType.getInstanceClass().getName()
1652
           eDataType.getInstanceClassName()
1653
         },
1653
         },
1654
         new Object [] { value, eDataType },
1654
         new Object [] { value, eDataType },
1655
         context));
1655
         context));
(-)src/org/eclipse/emf/ecore/util/EcoreUtil.java (+69 lines)
Lines 4318-4323 Link Here
4318
    return null;
4318
    return null;
4319
  }
4319
  }
4320
4320
4321
  /**
4322
   * @since 2.8
4323
   */
4324
  public static List<String> getConversionDelegates(EPackage ePackage)
4325
  {
4326
    EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI);
4327
    if (eAnnotation != null)
4328
    {
4329
      String eDataTypeDelegates = eAnnotation.getDetails().get("conversionDelegates");
4330
      if (eDataTypeDelegates != null)
4331
      {
4332
        List<String> result = new ArrayList<String>();
4333
        for (StringTokenizer stringTokenizer = new StringTokenizer(eDataTypeDelegates); stringTokenizer.hasMoreTokens();)
4334
        {
4335
          String eDataTypeDelegate = stringTokenizer.nextToken();
4336
          result.add(eDataTypeDelegate);
4337
        }
4338
        return result;
4339
      }
4340
    }
4341
    return Collections.emptyList();
4342
  }
4343
4344
  public static void setConversionDelegates(EPackage ePackage, List<String> eDataTypeDelegates)
4345
  {
4346
    EAnnotation eAnnotation = ePackage.getEAnnotation(EcorePackage.eNS_URI);
4347
    if (eDataTypeDelegates == null || eDataTypeDelegates.isEmpty())
4348
    {
4349
      if (eAnnotation != null)
4350
      {
4351
        eAnnotation.getDetails().remove("conversionDelegates");
4352
      }
4353
    }
4354
    else
4355
    {
4356
      if (eAnnotation == null)
4357
      {
4358
        eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
4359
        eAnnotation.setSource(EcorePackage.eNS_URI);
4360
        ePackage.getEAnnotations().add(eAnnotation);
4361
      }
4362
      StringBuffer value = new StringBuffer();
4363
      for (Iterator<String> i = eDataTypeDelegates.iterator(); i.hasNext();)
4364
      {
4365
        value.append(i.next());
4366
        if (i.hasNext())
4367
        {
4368
          value.append(' ');
4369
        }
4370
      }
4371
      eAnnotation.getDetails().put("conversionDelegates", value.toString());
4372
    }
4373
  }
4374
4375
  /**
4376
   * @since 2.8
4377
   */
4378
  public static EDataType.Internal.ConversionDelegate.Factory getConversionDelegateFactory(EDataType eDataType)
4379
  {
4380
    for (String eDataTypeDelegate : getConversionDelegates(eDataType.getEPackage()))
4381
    {
4382
      if (eDataType.getEAnnotation(eDataTypeDelegate) != null)
4383
      {
4384
        return EDataType.Internal.ConversionDelegate.Factory.Registry.INSTANCE.getFactory(eDataTypeDelegate);
4385
      }
4386
    }
4387
    return null;
4388
  }
4389
4321
  /*
4390
  /*
4322
   static 
4391
   static 
4323
   {
4392
   {
(-)src/org/eclipse/emf/ecore/util/EcoreValidator.java (-1 / +1 lines)
Lines 2580-2586 Link Here
2580
        createDiagnostic
2580
        createDiagnostic
2581
         (Diagnostic.ERROR,
2581
         (Diagnostic.ERROR,
2582
          DIAGNOSTIC_SOURCE,
2582
          DIAGNOSTIC_SOURCE,
2583
          VALID_LOWER_BOUND,
2583
          VALID_DEFAULT_VALUE_LITERAL,
2584
          "_UI_EStructuralFeatureValidDefaultValueLiteral_diagnostic",
2584
          "_UI_EStructuralFeatureValidDefaultValueLiteral_diagnostic",
2585
          new Object[] { defaultValueLiteral },
2585
          new Object[] { defaultValueLiteral },
2586
          new Object[] { eStructuralFeature },
2586
          new Object[] { eStructuralFeature },
(-)src/org/eclipse/emf/ecore/change/impl/ChangeDescriptionImpl.java (-1 / +5 lines)
Lines 479-485 Link Here
479
        }
479
        }
480
      };
480
      };
481
    Collection<EObject> newObjectsToAttach = copier.copyAll(objectToDetach);
481
    Collection<EObject> newObjectsToAttach = copier.copyAll(objectToDetach);
482
    copier.copyReferences();
482
    // copier.copyReferences();
483
483
484
    // The children of the objects to attach might become orphans;
484
    // The children of the objects to attach might become orphans;
485
    // we'll need to check for that later.
485
    // we'll need to check for that later.
Lines 612-617 Link Here
612
      {
612
      {
613
        newObjectsToAttach.add(eObject);
613
        newObjectsToAttach.add(eObject);
614
      }
614
      }
615
      else
616
      {
617
        newObjectsToAttach.remove(eObject);
618
      }
615
    }
619
    }
616
620
617
    // Reverse the objects to attach and detach lists.
621
    // Reverse the objects to attach and detach lists.
(-)src/org/eclipse/emf/ecore/change/impl/FeatureChangeImpl.java (-1 / +13 lines)
Lines 718-726 Link Here
718
718
719
  protected void reverse(EList<Object> toList)
719
  protected void reverse(EList<Object> toList)
720
  {
720
  {
721
    EList<Object> copy = null;
721
    for (ListChange listChange : getListChanges())
722
    for (ListChange listChange : getListChanges())
722
    {
723
    {
723
      listChange.reverse(toList);
724
      if (listChange.getKind() == ChangeKind.REMOVE_LITERAL)
725
      {
726
        if (copy == null)
727
        {
728
          copy = new BasicEList<Object>(toList);
729
        }
730
        listChange.applyAndReverse(copy);
731
      }
732
      else
733
      {
734
        listChange.reverse(toList);
735
      } 
724
    }
736
    }
725
  }
737
  }
726
738
(-)src/org/eclipse/emf/ecore/change/util/ChangeRecorder.java (-1 / +1 lines)
Lines 252-258 Link Here
252
252
253
  protected boolean isOrphan(EObject eObject)
253
  protected boolean isOrphan(EObject eObject)
254
  {
254
  {
255
    return eObject.eContainer() == null && eObject.eResource() == null;
255
    return ((InternalEObject)eObject).eInternalContainer() == null && eObject.eResource() == null;
256
  }
256
  }
257
257
258
  public void notifyChanged(Notification notification)
258
  public void notifyChanged(Notification notification)
(-)src/org/eclipse/emf/ecore/presentation/EcoreEditor.java (-3 / +62 lines)
Lines 19-24 Link Here
19
19
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.lang.reflect.Method;
22
23
23
import java.util.ArrayList;
24
import java.util.ArrayList;
24
import java.util.Collection;
25
import java.util.Collection;
Lines 32-37 Link Here
32
33
33
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IMarker;
35
import org.eclipse.core.resources.IMarker;
36
import org.eclipse.core.resources.IProject;
35
import org.eclipse.core.resources.IResource;
37
import org.eclipse.core.resources.IResource;
36
import org.eclipse.core.resources.IResourceChangeEvent;
38
import org.eclipse.core.resources.IResourceChangeEvent;
37
import org.eclipse.core.resources.IResourceChangeListener;
39
import org.eclipse.core.resources.IResourceChangeListener;
Lines 113-118 Link Here
113
115
114
import org.eclipse.emf.common.notify.AdapterFactory;
116
import org.eclipse.emf.common.notify.AdapterFactory;
115
import org.eclipse.emf.common.notify.Notification;
117
import org.eclipse.emf.common.notify.Notification;
118
import org.eclipse.emf.common.notify.impl.AdapterImpl;
116
119
117
import org.eclipse.emf.common.ui.MarkerHelper;
120
import org.eclipse.emf.common.ui.MarkerHelper;
118
121
Lines 762-768 Link Here
762
   * This sets up the editing domain for the model editor.
765
   * This sets up the editing domain for the model editor.
763
   * <!-- begin-user-doc -->
766
   * <!-- begin-user-doc -->
764
   * <!-- end-user-doc -->
767
   * <!-- end-user-doc -->
765
   * @generated
768
   * @generated NOT
766
   */
769
   */
767
  protected void initializeEditingDomain()
770
  protected void initializeEditingDomain()
768
  {
771
  {
Lines 808-816 Link Here
808
         }
811
         }
809
       });
812
       });
810
813
814
    ResourceSet resourceSet = null;
815
    try
816
    {
817
      Class<?> xtextResourceSetClass = CommonPlugin.loadClass("org.eclipse.xtext", "org.eclipse.xtext.resource.XtextResourceSet");
818
      
819
      resourceSet = (ResourceSet)xtextResourceSetClass.newInstance();
820
      class EditingDomainProvider extends AdapterImpl implements IEditingDomainProvider
821
      {
822
        public EditingDomain getEditingDomain()
823
        {
824
          return editingDomain;
825
        }
826
        @Override
827
        public boolean isAdapterForType(Object type)
828
        {
829
          return IEditingDomainProvider.class.equals(type);
830
        }
831
      }
832
      resourceSet.eAdapters().add(new EditingDomainProvider());
833
    }
834
    catch (Exception e)
835
    {
836
      e.printStackTrace();
837
      // ignore missing Xtext
838
    }
839
    
811
    // Create the editing domain with a special command stack.
840
    // Create the editing domain with a special command stack.
812
    //
841
    //
813
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
842
    editingDomain = 
843
       new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet)
844
    {
845
      {
846
        resourceToReadOnlyMap = new HashMap<Resource, Boolean>();
847
      }
848
      @Override
849
      public boolean isReadOnly(Resource resource)
850
      {
851
        return 
852
          "java".equals(resource.getURI().scheme()) || 
853
          "xcore".equals(resource.getURI().fileExtension()) ||
854
          super.isReadOnly(resource);
855
      }
856
    };
814
  }
857
  }
815
858
816
  /**
859
  /**
Lines 1637-1643 Link Here
1637
   * This is called during startup.
1680
   * This is called during startup.
1638
   * <!-- begin-user-doc -->
1681
   * <!-- begin-user-doc -->
1639
   * <!-- end-user-doc -->
1682
   * <!-- end-user-doc -->
1640
   * @generated
1683
   * @generated NOT
1641
   */
1684
   */
1642
  @Override
1685
  @Override
1643
  public void init(IEditorSite site, IEditorInput editorInput)
1686
  public void init(IEditorSite site, IEditorInput editorInput)
Lines 1648-1653 Link Here
1648
    site.setSelectionProvider(this);
1691
    site.setSelectionProvider(this);
1649
    site.getPage().addPartListener(partListener);
1692
    site.getPage().addPartListener(partListener);
1650
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
1693
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
1694
    
1695
    try
1696
    {
1697
      ResourceSet resourceSet = editingDomain.getResourceSet();
1698
      Method setClasspathURIContextMethod = resourceSet.getClass().getMethod("setClasspathURIContext", Object.class);
1699
      Class<?> javaCoreClass = CommonPlugin.loadClass("org.eclipse.jdt.core", "org.eclipse.jdt.core.JavaCore");
1700
      IProject project = ((IFileEditorInput)editorInput).getFile().getProject();
1701
      Method createMethod = javaCoreClass.getMethod("create", IProject.class);
1702
      Object javaProject = createMethod.invoke(null, project);
1703
      setClasspathURIContextMethod.invoke(resourceSet, javaProject);
1704
    }
1705
    catch (Exception e)
1706
    {
1707
      e.printStackTrace();
1708
      // ignore missing Xtext
1709
    }
1651
  }
1710
  }
1652
1711
1653
  /**
1712
  /**
(-)src/org/eclipse/emf/test/core/change/ChangeDescriptionReverseTest.java (+72 lines)
Lines 36-41 Link Here
36
import org.eclipse.emf.ecore.EObject;
36
import org.eclipse.emf.ecore.EObject;
37
import org.eclipse.emf.ecore.EPackage;
37
import org.eclipse.emf.ecore.EPackage;
38
import org.eclipse.emf.ecore.EcoreFactory;
38
import org.eclipse.emf.ecore.EcoreFactory;
39
import org.eclipse.emf.ecore.InternalEObject;
39
import org.eclipse.emf.ecore.change.ChangeDescription;
40
import org.eclipse.emf.ecore.change.ChangeDescription;
40
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
41
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
41
import org.eclipse.emf.ecore.resource.Resource;
42
import org.eclipse.emf.ecore.resource.Resource;
Lines 54-59 Link Here
54
  public static Test suite()
55
  public static Test suite()
55
  {
56
  {
56
    TestSuite ts = new TestSuite("ChangeDescription copyAndReverse Test");
57
    TestSuite ts = new TestSuite("ChangeDescription copyAndReverse Test");
58
    /*
57
    ts.addTest(new ChangeDescriptionReverseTest("testOne"));
59
    ts.addTest(new ChangeDescriptionReverseTest("testOne"));
58
    ts.addTest(new ChangeDescriptionReverseTest("testTwo"));
60
    ts.addTest(new ChangeDescriptionReverseTest("testTwo"));
59
    ts.addTest(new ChangeDescriptionReverseTest("testThree"));
61
    ts.addTest(new ChangeDescriptionReverseTest("testThree"));
Lines 61-66 Link Here
61
    ts.addTest(new ChangeDescriptionReverseTest("testFive"));
63
    ts.addTest(new ChangeDescriptionReverseTest("testFive"));
62
    ts.addTest(new ChangeDescriptionReverseTest("testSix"));
64
    ts.addTest(new ChangeDescriptionReverseTest("testSix"));
63
    ts.addTest(new ChangeDescriptionReverseTest("testSeven"));
65
    ts.addTest(new ChangeDescriptionReverseTest("testSeven"));
66
    */
67
    ts.addTest(new ChangeDescriptionReverseTest("testEight"));
64
    return ts;
68
    return ts;
65
  }
69
  }
66
70
Lines 81-86 Link Here
81
      makeChanges();
85
      makeChanges();
82
        
86
        
83
      ChangeDescription changeDescription = changeRecorder.endRecording();
87
      ChangeDescription changeDescription = changeRecorder.endRecording();
88
      {
89
      ResourceSet finalResourceSet = new ResourceSetImpl();
90
      Resource changeDescriptionResource = finalResourceSet.createResource(URI.createURI("changes.change"));
91
      changeDescriptionResource.getContents().add(changeDescription);
92
      changeDescriptionResource.save(System.err, null);
93
        
94
      }
84
      changeDescription.copyAndReverse(eObjectToProxyURIMap);
95
      changeDescription.copyAndReverse(eObjectToProxyURIMap);
85
      
96
      
86
      ResourceSet finalResourceSet = new ResourceSetImpl();
97
      ResourceSet finalResourceSet = new ResourceSetImpl();
Lines 288-293 Link Here
288
    }.doit();
299
    }.doit();
289
  }
300
  }
290
  
301
  
302
  public void testEight() throws Exception
303
  {
304
    new TestHelper()
305
      {
306
        Resource ecoreResource;
307
        EPackage ecorePackage;
308
309
        @Override
310
        void loadResources(ResourceSet resourceSet)
311
        {
312
          ecoreResource = resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"), true);
313
          ecorePackage = (EPackage)ecoreResource.getContents().get(0);
314
315
          EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
316
          ecorePackage.getEAnnotations().add(eAnnotation);
317
318
          eAnnotation.setSource(getName());
319
320
          EList<EObject> references = eAnnotation.getReferences();
321
322
          EObject eClassProxy = EcoreFactory.eINSTANCE.createEObject();
323
          ((InternalEObject)eClassProxy).eSetProxyURI(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EClass"));
324
          references.add(eClassProxy);
325
326
          EObject ePackageProxy = EcoreFactory.eINSTANCE.createEObject();
327
          ((InternalEObject)ePackageProxy).eSetProxyURI(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EPackage"));
328
          references.add(ePackageProxy);
329
        }
330
331
        @Override
332
        void makeChanges()
333
        {
334
          EList<EObject> references = ecorePackage.getEAnnotation(getName()).getReferences();
335
          references.clear();
336
337
          references.add(ecorePackage.getEClassifier("EClass"));
338
          references.add(ecorePackage.getEClassifier("EPackage"));
339
340
          EClass eClass = EcoreFactory.eINSTANCE.createEClass();
341
          eClass.setName("NewClass");
342
343
          EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
344
          eAnnotation.getReferences().add(eClass);
345
346
          EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
347
          ePackage.setName("NewPackage");
348
349
          ePackage.getEClassifiers().add(eClass);
350
351
          ecorePackage.getESubpackages().add(ePackage);
352
          ecorePackage.getEAnnotations().add(eAnnotation);
353
354
          ResourceSet resourceSet = ecoreResource.getResourceSet();
355
          resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/EPackage/NewPackage.ecore")).getContents().add(
356
            ePackage);
357
          resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/EClass/NewClass.ecore")).getContents().add(
358
            eClass);
359
        }
360
      }.doit();
361
  }
362
  
291
  void assertEquals(ResourceSet resourceSet1, ResourceSet resourceSet2)
363
  void assertEquals(ResourceSet resourceSet1, ResourceSet resourceSet2)
292
  {
364
  {
293
    EcoreUtil.resolveAll(resourceSet1);
365
    EcoreUtil.resolveAll(resourceSet1);
(-)src/org/eclipse/emf/test/core/ecore/BadEcoreDiagnosticTest.java (-2 / +2 lines)
Lines 1192-1198 Link Here
1192
    assertEquals(Diagnostic.ERROR, diagnostic126.getSeverity());
1192
    assertEquals(Diagnostic.ERROR, diagnostic126.getSeverity());
1193
    assertEquals("org.eclipse.emf.ecore.model", diagnostic126.getSource());
1193
    assertEquals("org.eclipse.emf.ecore.model", diagnostic126.getSource());
1194
    assertEquals("The default value literal '256' must be a valid literal of the attribute's type", removeObjectHashCode(diagnostic126.getMessage()));
1194
    assertEquals("The default value literal '256' must be a valid literal of the attribute's type", removeObjectHashCode(diagnostic126.getMessage()));
1195
    assertEquals(39, diagnostic126.getCode());
1195
    assertEquals(38, diagnostic126.getCode());
1196
    assertEquals(1, diagnostic126.getChildren().size());
1196
    assertEquals(1, diagnostic126.getChildren().size());
1197
    assertEquals(1, diagnostic126.getData().size());
1197
    assertEquals(1, diagnostic126.getData().size());
1198
    assertNull(diagnostic126.getException());
1198
    assertNull(diagnostic126.getException());
Lines 1210-1216 Link Here
1210
    assertEquals(Diagnostic.ERROR, diagnostic128.getSeverity());
1210
    assertEquals(Diagnostic.ERROR, diagnostic128.getSeverity());
1211
    assertEquals("org.eclipse.emf.ecore.model", diagnostic128.getSource());
1211
    assertEquals("org.eclipse.emf.ecore.model", diagnostic128.getSource());
1212
    assertEquals("The default value literal '' must be a valid literal of the attribute's type", removeObjectHashCode(diagnostic128.getMessage()));
1212
    assertEquals("The default value literal '' must be a valid literal of the attribute's type", removeObjectHashCode(diagnostic128.getMessage()));
1213
    assertEquals(39, diagnostic128.getCode());
1213
    assertEquals(38, diagnostic128.getCode());
1214
    assertEquals(0, diagnostic128.getChildren().size());
1214
    assertEquals(0, diagnostic128.getChildren().size());
1215
    assertEquals(1, diagnostic128.getData().size());
1215
    assertEquals(1, diagnostic128.getData().size());
1216
    assertNull(diagnostic128.getException());
1216
    assertNull(diagnostic128.getException());

Return to bug 354245