|
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 2127-2162
Link Here
|
| 2127 |
@Override |
2138 |
@Override |
| 2128 |
public void setImportManager(ImportManager importManager) |
2139 |
public void setImportManager(ImportManager importManager) |
| 2129 |
{ |
2140 |
{ |
| 2130 |
this.importManager = importManager; |
2141 |
// Avoid doing this cyclically. |
| 2131 |
|
|
|
| 2132 |
// We also need to set it on any GenModels holding any used or static packages that may be refered to. |
| 2133 |
// |
| 2134 |
for (GenPackage genPackage : getUsedGenPackages()) |
| 2135 |
{ |
| 2136 |
genPackage.getGenModel().setImportManager(importManager); |
| 2137 |
} |
| 2138 |
|
| 2139 |
for (GenPackage genPackage : getStaticGenPackages()) |
| 2140 |
{ |
| 2141 |
genPackage.getGenModel().setImportManager(importManager); |
| 2142 |
} |
| 2143 |
|
| 2144 |
// And we need to set it on any cached GenModels holding the special Ecore and XML packages. |
| 2145 |
// |
2142 |
// |
| 2146 |
GenPackage ecore = getEcoreGenPackage(); |
2143 |
if (this.importManager != importManager) |
| 2147 |
if (ecore != null && ecore.getGenModel().getImportManager() != importManager) |
|
|
| 2148 |
{ |
| 2149 |
ecore.getGenModel().setImportManager(importManager); |
| 2150 |
} |
| 2151 |
GenPackage xmlType = getXMLTypeGenPackage(); |
| 2152 |
if (xmlType != null && xmlType.getGenModel().getImportManager() != importManager) |
| 2153 |
{ |
| 2154 |
xmlType.getGenModel().setImportManager(importManager); |
| 2155 |
} |
| 2156 |
GenPackage xmlNamespace = getXMLNamespaceGenPackage(); |
| 2157 |
if (xmlNamespace != null && xmlNamespace.getGenModel().getImportManager() != importManager) |
| 2158 |
{ |
2144 |
{ |
| 2159 |
xmlNamespace.getGenModel().setImportManager(importManager); |
2145 |
this.importManager = importManager; |
|
|
2146 |
|
| 2147 |
// We also need to set it on any GenModels holding any used or static packages that may be refered to. |
| 2148 |
// |
| 2149 |
for (GenPackage genPackage : getUsedGenPackages()) |
| 2150 |
{ |
| 2151 |
genPackage.getGenModel().setImportManager(importManager); |
| 2152 |
} |
| 2153 |
|
| 2154 |
for (GenPackage genPackage : getStaticGenPackages()) |
| 2155 |
{ |
| 2156 |
genPackage.getGenModel().setImportManager(importManager); |
| 2157 |
} |
| 2158 |
|
| 2159 |
// And we need to set it on any cached GenModels holding the special Ecore and XML packages. |
| 2160 |
// |
| 2161 |
GenPackage ecore = getEcoreGenPackage(); |
| 2162 |
if (ecore != null && ecore.getGenModel().getImportManager() != importManager) |
| 2163 |
{ |
| 2164 |
ecore.getGenModel().setImportManager(importManager); |
| 2165 |
} |
| 2166 |
GenPackage xmlType = getXMLTypeGenPackage(); |
| 2167 |
if (xmlType != null && xmlType.getGenModel().getImportManager() != importManager) |
| 2168 |
{ |
| 2169 |
xmlType.getGenModel().setImportManager(importManager); |
| 2170 |
} |
| 2171 |
GenPackage xmlNamespace = getXMLNamespaceGenPackage(); |
| 2172 |
if (xmlNamespace != null && xmlNamespace.getGenModel().getImportManager() != importManager) |
| 2173 |
{ |
| 2174 |
xmlNamespace.getGenModel().setImportManager(importManager); |
| 2175 |
} |
| 2160 |
} |
2176 |
} |
| 2161 |
} |
2177 |
} |
| 2162 |
|
2178 |
|
|
Lines 2173-2198
Link Here
|
| 2173 |
|
2189 |
|
| 2174 |
public void setLineDelimiter(String lineDelimiter) |
2190 |
public void setLineDelimiter(String lineDelimiter) |
| 2175 |
{ |
2191 |
{ |
| 2176 |
this.lineDelimiter = lineDelimiter; |
2192 |
// Avoid cycles |
| 2177 |
if (importManager != null) |
|
|
| 2178 |
{ |
| 2179 |
importManager.setLineDelimiter(lineDelimiter); |
| 2180 |
} |
| 2181 |
|
| 2182 |
// We also need to set it on any GenModels holding any used or static packages that may be refered to. |
| 2183 |
// |
2193 |
// |
| 2184 |
for (GenPackage genPackage : getUsedGenPackages()) |
2194 |
if (this.lineDelimiter != lineDelimiter) |
| 2185 |
{ |
2195 |
{ |
| 2186 |
genPackage.getGenModel().setLineDelimiter(lineDelimiter); |
2196 |
this.lineDelimiter = lineDelimiter; |
| 2187 |
} |
2197 |
if (importManager != null) |
| 2188 |
|
2198 |
{ |
| 2189 |
for (GenPackage genPackage : getStaticGenPackages()) |
2199 |
importManager.setLineDelimiter(lineDelimiter); |
| 2190 |
{ |
2200 |
} |
| 2191 |
genPackage.getGenModel().setLineDelimiter(lineDelimiter); |
2201 |
|
|
|
2202 |
// We also need to set it on any GenModels holding any used or static packages that may be refered to. |
| 2203 |
// |
| 2204 |
for (GenPackage genPackage : getUsedGenPackages()) |
| 2205 |
{ |
| 2206 |
genPackage.getGenModel().setLineDelimiter(lineDelimiter); |
| 2207 |
} |
| 2208 |
|
| 2209 |
for (GenPackage genPackage : getStaticGenPackages()) |
| 2210 |
{ |
| 2211 |
genPackage.getGenModel().setLineDelimiter(lineDelimiter); |
| 2212 |
} |
| 2213 |
|
| 2214 |
// There was previously code intended to set it on the cached GenModels holding the special Ecore and XML packages, |
| 2215 |
// but it erroneously set the import manager. So, it seems that was not necessary. |
| 2192 |
} |
2216 |
} |
| 2193 |
|
|
|
| 2194 |
// There was previously code intended to set it on the cached GenModels holding the special Ecore and XML packages, |
| 2195 |
// but it erroneously set the import manager. So, it seems that was not necessary. |
| 2196 |
} |
2217 |
} |
| 2197 |
|
2218 |
|
| 2198 |
public String getDriverNumber() |
2219 |
public String getDriverNumber() |
|
Lines 8995-9000
Link Here
|
| 8995 |
{ |
9016 |
{ |
| 8996 |
return super.findGenClassifier(classifier); |
9017 |
return super.findGenClassifier(classifier); |
| 8997 |
} |
9018 |
} |
|
|
9019 |
|
| 9020 |
@Override |
| 9021 |
public GenFeature findGenFeature(EStructuralFeature feature) |
| 9022 |
{ |
| 9023 |
return super.findGenFeature(feature); |
| 9024 |
} |
| 9025 |
|
| 9026 |
@Override |
| 9027 |
public GenOperation findGenOperation(EOperation operation) |
| 9028 |
{ |
| 9029 |
return super.findGenOperation(operation); |
| 9030 |
} |
| 9031 |
|
| 9032 |
public GenTypeParameter findGenTypeParameter(ETypeParameter eTypeParameter) |
| 9033 |
{ |
| 9034 |
for (EObject eObject = eTypeParameter.eContainer(); eObject != null; eObject = eObject.eContainer()) |
| 9035 |
{ |
| 9036 |
if (eObject instanceof EOperation) |
| 9037 |
{ |
| 9038 |
EOperation eOperation = (EOperation)eObject; |
| 9039 |
int index = eOperation.getETypeParameters().indexOf(eTypeParameter); |
| 9040 |
if (index != -1) |
| 9041 |
{ |
| 9042 |
GenOperation genOperation = findGenOperation(eOperation); |
| 9043 |
return genOperation.getGenTypeParameters().get(index); |
| 9044 |
} |
| 9045 |
} |
| 9046 |
else if (eObject instanceof EClassifier) |
| 9047 |
{ |
| 9048 |
EClassifier eClassifier = (EClassifier)eObject; |
| 9049 |
int index = eClassifier.getETypeParameters().indexOf(eTypeParameter); |
| 9050 |
if (index != -1) |
| 9051 |
{ |
| 9052 |
GenClassifier genClassifier = findGenClassifier(eClassifier); |
| 9053 |
return genClassifier.getGenTypeParameters().get(index); |
| 9054 |
} |
| 9055 |
} |
| 9056 |
} |
| 9057 |
return null; |
| 9058 |
} |
| 8998 |
|
9059 |
|
| 8999 |
public boolean isSuppressedAnnotation(String source) |
9060 |
public boolean isSuppressedAnnotation(String source) |
| 9000 |
{ |
9061 |
{ |
|
Lines 9201-9207
Link Here
|
| 9201 |
|
9262 |
|
| 9202 |
public void setMainGenModel(GenModel genModel) |
9263 |
public void setMainGenModel(GenModel genModel) |
| 9203 |
{ |
9264 |
{ |
| 9204 |
mainGenModel = genModel; |
9265 |
// Avoid creating a cycle. |
|
|
9266 |
// |
| 9267 |
if (genModel == null || genModel.getMainGenModel() != this) |
| 9268 |
{ |
| 9269 |
mainGenModel = genModel; |
| 9270 |
} |
| 9205 |
} |
9271 |
} |
| 9206 |
|
9272 |
|
| 9207 |
protected boolean isMainGenModel() |
9273 |
protected boolean isMainGenModel() |
|
Lines 9378-9381
Link Here
|
| 9378 |
return getEditorModuleName(); |
9444 |
return getEditorModuleName(); |
| 9379 |
} |
9445 |
} |
| 9380 |
|
9446 |
|
|
|
9447 |
public void initialize() |
| 9448 |
{ |
| 9449 |
Resource resource = eResource(); |
| 9450 |
if (resource != null) |
| 9451 |
{ |
| 9452 |
URI uri = resource.getURI(); |
| 9453 |
setModelDirectory(EclipseHelper.getModelDirectory(uri)); |
| 9454 |
setComplianceLevel(EclipseHelper.getComplianceLevel(uri)); |
| 9455 |
} |
| 9456 |
setUpdateClasspath(false); |
| 9457 |
setOperationReflection(true); |
| 9458 |
setMinimalReflectiveMethods(true); |
| 9459 |
setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"); |
| 9460 |
GenPackage mainGenPackage = getMainGenPackage(); |
| 9461 |
setModelName(mainGenPackage.getPrefix()); |
| 9462 |
GenRuntimeVersion[] values = GenRuntimeVersion.values(); |
| 9463 |
setRuntimeVersion(values[values.length - 1]); |
| 9464 |
|
| 9465 |
handleAnnotations(this, mainGenPackage.getEcorePackage()); |
| 9466 |
for (TreeIterator<EObject> i = eAllContents(); i.hasNext();) |
| 9467 |
{ |
| 9468 |
EObject content = i.next(); |
| 9469 |
if (content instanceof GenBase) |
| 9470 |
{ |
| 9471 |
GenBase genBase = (GenBase)content; |
| 9472 |
EModelElement eModelElement = genBase.getEcoreModelElement(); |
| 9473 |
if (eModelElement != null) |
| 9474 |
{ |
| 9475 |
handleAnnotations(genBase, eModelElement); |
| 9476 |
} |
| 9477 |
} |
| 9478 |
} |
| 9479 |
} |
| 9480 |
|
| 9481 |
protected void handleAnnotations(GenBase genBase, EModelElement eModelElement) |
| 9482 |
{ |
| 9483 |
EAnnotation eAnnotation = eModelElement.getEAnnotation(GenModelPackage.eNS_URI); |
| 9484 |
if (eAnnotation != null) |
| 9485 |
{ |
| 9486 |
EClass eClass = genBase.eClass(); |
| 9487 |
for (Map.Entry<String, String> entry : eAnnotation.getDetails()) |
| 9488 |
{ |
| 9489 |
EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(entry.getKey()); |
| 9490 |
if (eStructuralFeature instanceof EAttribute) |
| 9491 |
{ |
| 9492 |
EAttribute eAttribute = (EAttribute)eStructuralFeature; |
| 9493 |
genBase.eSet(eStructuralFeature, EcoreUtil.createFromString(eAttribute.getEAttributeType(), entry.getValue())); |
| 9494 |
} |
| 9495 |
} |
| 9496 |
} |
| 9497 |
} |
| 9498 |
|
| 9499 |
private static class EclipseHelper |
| 9500 |
{ |
| 9501 |
static String getModelDirectory(URI uri) |
| 9502 |
{ |
| 9503 |
if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) |
| 9504 |
{ |
| 9505 |
try |
| 9506 |
{ |
| 9507 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 9508 |
IProject project = workspace.getRoot().getProject(uri.segment(1)); |
| 9509 |
IJavaProject javaProject = JavaCore.create(project); |
| 9510 |
IClasspathEntry[] classpath = javaProject.getRawClasspath(); |
| 9511 |
IClasspathEntry bestEntry = null; |
| 9512 |
for (IClasspathEntry classpathEntry : classpath) |
| 9513 |
{ |
| 9514 |
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) |
| 9515 |
{ |
| 9516 |
// Look for the first entry that's Java source. |
| 9517 |
if (bestEntry == null) |
| 9518 |
{ |
| 9519 |
bestEntry = classpathEntry; |
| 9520 |
} |
| 9521 |
// If there's a src-gen entry, prefer that over all others. |
| 9522 |
// |
| 9523 |
else if (classpathEntry.getPath().toString().endsWith("src-gen")) |
| 9524 |
{ |
| 9525 |
bestEntry = classpathEntry; |
| 9526 |
} |
| 9527 |
} |
| 9528 |
} |
| 9529 |
return bestEntry == null ? project.getFullPath() + "/src" : bestEntry.getPath().toString(); |
| 9530 |
} |
| 9531 |
catch (Exception exception) |
| 9532 |
{ |
| 9533 |
CodeGenEcorePlugin.INSTANCE.log(exception); |
| 9534 |
} |
| 9535 |
} |
| 9536 |
return null; |
| 9537 |
} |
| 9538 |
|
| 9539 |
static GenJDKLevel getComplianceLevel(URI uri) |
| 9540 |
{ |
| 9541 |
if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) |
| 9542 |
{ |
| 9543 |
try |
| 9544 |
{ |
| 9545 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 9546 |
IProject project = workspace.getRoot().getProject(uri.segment(2)); |
| 9547 |
String complianceLevel = CodeGenUtil.EclipseUtil.getJavaComplianceLevel(project); |
| 9548 |
if ("1.5".equals(complianceLevel)) |
| 9549 |
{ |
| 9550 |
return GenJDKLevel.JDK50_LITERAL; |
| 9551 |
} |
| 9552 |
else if ("1.6".equals(complianceLevel)) |
| 9553 |
{ |
| 9554 |
return GenJDKLevel.JDK60_LITERAL; |
| 9555 |
} |
| 9556 |
else if ("1.4".equals(complianceLevel)) |
| 9557 |
{ |
| 9558 |
return GenJDKLevel.JDK14_LITERAL; |
| 9559 |
} |
| 9560 |
} |
| 9561 |
catch (Exception exception) |
| 9562 |
{ |
| 9563 |
CodeGenEcorePlugin.INSTANCE.log(exception); |
| 9564 |
} |
| 9565 |
} |
| 9566 |
return GenJDKLevel.JDK50_LITERAL; |
| 9567 |
} |
| 9568 |
} |
| 9569 |
|
| 9381 |
} //GenModelImpl |
9570 |
} //GenModelImpl |