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

Return to bug 354245