Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 201408 Details for
Bug 354245
Enhanced support for XCore
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Enhanced GenModel APIs and hacked reflective editor
354245.patch (text/plain), 16.19 KB, created by
Ed Merks
on 2011-08-12 11:43:03 EDT
(
hide
)
Description:
Enhanced GenModel APIs and hacked reflective editor
Filename:
MIME Type:
Creator:
Ed Merks
Created:
2011-08-12 11:43:03 EDT
Size:
16.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.codegen.ecore >Index: src/org/eclipse/emf/codegen/ecore/genmodel/GenClass.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/GenClass.java,v >retrieving revision 1.36 >diff -u -r1.36 GenClass.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/GenClass.java 21 Jan 2011 07:19:08 -0000 1.36 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/GenClass.java 12 Aug 2011 15:40:53 -0000 >@@ -624,4 +624,11 @@ > * @since 2.4 > */ > boolean hasCollidingUnsetAccessorOperation(GenFeature genFeature); >+ >+ /** >+ * Returns as list that corresponds to {@link #getInterfaceExtends()}. >+ * @since 2.8 >+ */ >+ List<String >getQualifiedInterfaceExtendsList(); >+ > } >Index: src/org/eclipse/emf/codegen/ecore/genmodel/GenModel.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/GenModel.java,v >retrieving revision 1.69 >diff -u -r1.69 GenModel.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/GenModel.java 24 Aug 2010 16:59:38 -0000 1.69 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/GenModel.java 12 Aug 2011 15:40:54 -0000 >@@ -32,7 +32,10 @@ > import org.eclipse.emf.common.util.EList; > import org.eclipse.emf.ecore.EClass; > import org.eclipse.emf.ecore.EClassifier; >+import org.eclipse.emf.ecore.EOperation; > import org.eclipse.emf.ecore.EPackage; >+import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.ETypeParameter; > import org.eclipse.emf.ecore.util.ExtendedMetaData; > import org.eclipse.jdt.core.formatter.CodeFormatter; > >@@ -2794,4 +2797,25 @@ > * @since 2.7 > */ > String getQualifiedEditorEntryPointClassName(); >+ >+ /** >+ * Set up reasonable initial defaults. >+ * @since 2.8 >+ */ >+ void initialize(); >+ >+ /** >+ * @since 2.8 >+ */ >+ GenTypeParameter findGenTypeParameter(ETypeParameter eTypeParameter); >+ >+ /** >+ * @since 2.8 >+ */ >+ GenFeature findGenFeature(EStructuralFeature eStructuralFeature); >+ >+ /** >+ * @since 2.8 >+ */ >+ GenOperation findGenOperation(EOperation eOperation); > } >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelImpl.java,v >retrieving revision 1.117 >diff -u -r1.117 GenModelImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelImpl.java 6 Jan 2011 21:03:33 -0000 1.117 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenModelImpl.java 12 Aug 2011 15:40:57 -0000 >@@ -30,7 +30,13 @@ > import java.util.Map; > import java.util.Set; > >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.ToolFactory; > import org.eclipse.jdt.core.formatter.CodeFormatter; > >@@ -75,13 +81,18 @@ > import org.eclipse.emf.common.util.TreeIterator; > import org.eclipse.emf.common.util.URI; > import org.eclipse.emf.common.util.UniqueEList; >+import org.eclipse.emf.ecore.EAnnotation; >+import org.eclipse.emf.ecore.EAttribute; > import org.eclipse.emf.ecore.EClass; > import org.eclipse.emf.ecore.EClassifier; > import org.eclipse.emf.ecore.EDataType; > import org.eclipse.emf.ecore.EEnum; >+import org.eclipse.emf.ecore.EModelElement; > import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EOperation; > import org.eclipse.emf.ecore.EPackage; > import org.eclipse.emf.ecore.EStructuralFeature; >+import org.eclipse.emf.ecore.ETypeParameter; > import org.eclipse.emf.ecore.EValidator; > import org.eclipse.emf.ecore.EcorePackage; > import org.eclipse.emf.ecore.InternalEObject; >@@ -8995,6 +9006,46 @@ > { > return super.findGenClassifier(classifier); > } >+ >+ @Override >+ public GenFeature findGenFeature(EStructuralFeature feature) >+ { >+ return super.findGenFeature(feature); >+ } >+ >+ @Override >+ public GenOperation findGenOperation(EOperation operation) >+ { >+ return super.findGenOperation(operation); >+ } >+ >+ public GenTypeParameter findGenTypeParameter(ETypeParameter eTypeParameter) >+ { >+ for (EObject eObject = eTypeParameter.eContainer(); eObject != null; eObject = eObject.eContainer()) >+ { >+ if (eObject instanceof EOperation) >+ { >+ EOperation eOperation = (EOperation)eObject; >+ int index = eOperation.getETypeParameters().indexOf(eTypeParameter); >+ if (index != -1) >+ { >+ GenOperation genOperation = findGenOperation(eOperation); >+ return genOperation.getGenTypeParameters().get(index); >+ } >+ } >+ else if (eObject instanceof EClassifier) >+ { >+ EClassifier eClassifier = (EClassifier)eObject; >+ int index = eClassifier.getETypeParameters().indexOf(eTypeParameter); >+ if (index != -1) >+ { >+ GenClassifier genClassifier = findGenClassifier(eClassifier); >+ return genClassifier.getGenTypeParameters().get(index); >+ } >+ } >+ } >+ return null; >+ } > > public boolean isSuppressedAnnotation(String source) > { >@@ -9378,4 +9429,127 @@ > return getEditorModuleName(); > } > >+ public void initialize() >+ { >+ Resource resource = eResource(); >+ if (resource != null) >+ { >+ URI uri = resource.getURI(); >+ setModelDirectory(EclipseHelper.getModelDirectory(uri)); >+ setComplianceLevel(EclipseHelper.getComplianceLevel(uri)); >+ } >+ setUpdateClasspath(false); >+ setOperationReflection(true); >+ setMinimalReflectiveMethods(true); >+ setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"); >+ GenPackage mainGenPackage = getMainGenPackage(); >+ setModelName(mainGenPackage.getPrefix()); >+ GenRuntimeVersion[] values = GenRuntimeVersion.values(); >+ setRuntimeVersion(values[values.length - 1]); >+ >+ handleAnnotations(this, mainGenPackage.getEcorePackage()); >+ for (TreeIterator<EObject> i = eAllContents(); i.hasNext();) >+ { >+ EObject content = i.next(); >+ if (content instanceof GenBase) >+ { >+ GenBase genBase = (GenBase)content; >+ EModelElement eModelElement = genBase.getEcoreModelElement(); >+ if (eModelElement != null) >+ { >+ handleAnnotations(genBase, eModelElement); >+ } >+ } >+ } >+ } >+ >+ protected void handleAnnotations(GenBase genBase, EModelElement eModelElement) >+ { >+ EAnnotation eAnnotation = eModelElement.getEAnnotation(GenModelPackage.eNS_URI); >+ if (eAnnotation != null) >+ { >+ EClass eClass = genBase.eClass(); >+ for (Map.Entry<String, String> entry : eAnnotation.getDetails()) >+ { >+ EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(entry.getKey()); >+ if (eStructuralFeature instanceof EAttribute) >+ { >+ EAttribute eAttribute = (EAttribute)eStructuralFeature; >+ genBase.eSet(eStructuralFeature, EcoreUtil.createFromString(eAttribute.getEAttributeType(), entry.getValue())); >+ } >+ } >+ } >+ } >+ >+ private static class EclipseHelper >+ { >+ static String getModelDirectory(URI uri) >+ { >+ if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) >+ { >+ try >+ { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = workspace.getRoot().getProject(uri.segment(1)); >+ IJavaProject javaProject = JavaCore.create(project); >+ IClasspathEntry[] classpath = javaProject.getRawClasspath(); >+ IClasspathEntry bestEntry = null; >+ for (IClasspathEntry classpathEntry : classpath) >+ { >+ if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) >+ { >+ // Look for the first entry that's Java source. >+ if (bestEntry == null) >+ { >+ bestEntry = classpathEntry; >+ } >+ // If there's a src-gen entry, prefer that over all others. >+ // >+ else if (classpathEntry.getPath().toString().endsWith("src-gen")) >+ { >+ bestEntry = classpathEntry; >+ } >+ } >+ } >+ return bestEntry == null ? project.getFullPath() + "/src" : bestEntry.getPath().toString(); >+ } >+ catch (Exception exception) >+ { >+ CodeGenEcorePlugin.INSTANCE.log(exception); >+ } >+ } >+ return null; >+ } >+ >+ static GenJDKLevel getComplianceLevel(URI uri) >+ { >+ if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) >+ { >+ try >+ { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = workspace.getRoot().getProject(uri.segment(2)); >+ String complianceLevel = CodeGenUtil.EclipseUtil.getJavaComplianceLevel(project); >+ if ("1.5".equals(complianceLevel)) >+ { >+ return GenJDKLevel.JDK50_LITERAL; >+ } >+ else if ("1.6".equals(complianceLevel)) >+ { >+ return GenJDKLevel.JDK60_LITERAL; >+ } >+ else if ("1.4".equals(complianceLevel)) >+ { >+ return GenJDKLevel.JDK14_LITERAL; >+ } >+ } >+ catch (Exception exception) >+ { >+ CodeGenEcorePlugin.INSTANCE.log(exception); >+ } >+ } >+ return GenJDKLevel.JDK50_LITERAL; >+ } >+ } >+ > } //GenModelImpl >Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenTypeParameterImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenTypeParameterImpl.java,v >retrieving revision 1.5 >diff -u -r1.5 GenTypeParameterImpl.java >--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenTypeParameterImpl.java 11 Jun 2007 21:09:49 -0000 1.5 >+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenTypeParameterImpl.java 12 Aug 2011 15:40:57 -0000 >@@ -23,6 +23,7 @@ > import org.eclipse.emf.common.notify.Notification; > import org.eclipse.emf.ecore.EClass; > import org.eclipse.emf.ecore.EGenericType; >+import org.eclipse.emf.ecore.EModelElement; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecore.ETypeParameter; > import org.eclipse.emf.ecore.InternalEObject; >@@ -252,5 +253,11 @@ > } > return result.toString().trim(); > } >+ >+ @Override >+ public EModelElement getEcoreModelElement() >+ { >+ return getEcoreTypeParameter(); >+ } > > } //GenTypeParameterImpl >#P org.eclipse.emf.ecore >Index: src/org/eclipse/emf/ecore/util/EcoreValidator.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/EcoreValidator.java,v >retrieving revision 1.45 >diff -u -r1.45 EcoreValidator.java >--- src/org/eclipse/emf/ecore/util/EcoreValidator.java 13 May 2011 15:08:08 -0000 1.45 >+++ src/org/eclipse/emf/ecore/util/EcoreValidator.java 12 Aug 2011 15:41:00 -0000 >@@ -2580,7 +2580,7 @@ > createDiagnostic > (Diagnostic.ERROR, > DIAGNOSTIC_SOURCE, >- VALID_LOWER_BOUND, >+ VALID_DEFAULT_VALUE_LITERAL, > "_UI_EStructuralFeatureValidDefaultValueLiteral_diagnostic", > new Object[] { defaultValueLiteral }, > new Object[] { eStructuralFeature }, >#P org.eclipse.emf.ecore.editor >Index: src/org/eclipse/emf/ecore/presentation/EcoreEditor.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.ecore.editor/src/org/eclipse/emf/ecore/presentation/EcoreEditor.java,v >retrieving revision 1.62 >diff -u -r1.62 EcoreEditor.java >--- src/org/eclipse/emf/ecore/presentation/EcoreEditor.java 12 May 2011 20:21:12 -0000 1.62 >+++ src/org/eclipse/emf/ecore/presentation/EcoreEditor.java 12 Aug 2011 15:41:01 -0000 >@@ -19,6 +19,7 @@ > > import java.io.IOException; > import java.io.InputStream; >+import java.lang.reflect.Method; > > import java.util.ArrayList; > import java.util.Collection; >@@ -32,6 +33,7 @@ > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IResourceChangeEvent; > import org.eclipse.core.resources.IResourceChangeListener; >@@ -113,6 +115,7 @@ > > import org.eclipse.emf.common.notify.AdapterFactory; > import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.impl.AdapterImpl; > > import org.eclipse.emf.common.ui.MarkerHelper; > >@@ -762,7 +765,7 @@ > * This sets up the editing domain for the model editor. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @generated >+ * @generated NOT > */ > protected void initializeEditingDomain() > { >@@ -808,9 +811,49 @@ > } > }); > >+ ResourceSet resourceSet = null; >+ try >+ { >+ Class<?> xtextResourceSetClass = CommonPlugin.loadClass("org.eclipse.xtext", "org.eclipse.xtext.resource.XtextResourceSet"); >+ >+ resourceSet = (ResourceSet)xtextResourceSetClass.newInstance(); >+ class EditingDomainProvider extends AdapterImpl implements IEditingDomainProvider >+ { >+ public EditingDomain getEditingDomain() >+ { >+ return editingDomain; >+ } >+ @Override >+ public boolean isAdapterForType(Object type) >+ { >+ return IEditingDomainProvider.class.equals(type); >+ } >+ } >+ resourceSet.eAdapters().add(new EditingDomainProvider()); >+ } >+ catch (Exception e) >+ { >+ e.printStackTrace(); >+ // ignore missing Xtext >+ } >+ > // Create the editing domain with a special command stack. > // >- editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>()); >+ editingDomain = >+ new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet) >+ { >+ { >+ resourceToReadOnlyMap = new HashMap<Resource, Boolean>(); >+ } >+ @Override >+ public boolean isReadOnly(Resource resource) >+ { >+ return >+ "java".equals(resource.getURI().scheme()) || >+ "xcore".equals(resource.getURI().fileExtension()) || >+ super.isReadOnly(resource); >+ } >+ }; > } > > /** >@@ -1637,7 +1680,7 @@ > * This is called during startup. > * <!-- begin-user-doc --> > * <!-- end-user-doc --> >- * @generated >+ * @generated NOT > */ > @Override > public void init(IEditorSite site, IEditorInput editorInput) >@@ -1648,6 +1691,22 @@ > site.setSelectionProvider(this); > site.getPage().addPartListener(partListener); > ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE); >+ >+ try >+ { >+ ResourceSet resourceSet = editingDomain.getResourceSet(); >+ Method setClasspathURIContextMethod = resourceSet.getClass().getMethod("setClasspathURIContext", Object.class); >+ Class<?> javaCoreClass = CommonPlugin.loadClass("org.eclipse.jdt.core", "org.eclipse.jdt.core.JavaCore"); >+ IProject project = ((IFileEditorInput)editorInput).getFile().getProject(); >+ Method createMethod = javaCoreClass.getMethod("create", IProject.class); >+ Object javaProject = createMethod.invoke(null, project); >+ setClasspathURIContextMethod.invoke(resourceSet, javaProject); >+ } >+ catch (Exception e) >+ { >+ e.printStackTrace(); >+ // ignore missing Xtext >+ } > } > > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 354245
:
201141
|
201408
|
201453
|
201873
|
201883
|
202635
|
202849
|
202955
|
203077
|
205521
|
205526