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
(-)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/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
  /**

Return to bug 354245