| 1 17 package org.eclipse.emf.codegen.ecore.genmodel.impl; 18 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.DataInputStream ; 23 import java.io.DataOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.text.MessageFormat ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 import java.util.Collection ; 30 import java.util.Collections ; 31 import java.util.HashMap ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 import org.eclipse.core.resources.IContainer; 39 import org.eclipse.core.resources.IFile; 40 import org.eclipse.core.resources.IFolder; 41 import org.eclipse.core.resources.IProject; 42 import org.eclipse.core.resources.IWorkspace; 43 import org.eclipse.core.resources.ResourceAttributes; 44 import org.eclipse.core.resources.ResourcesPlugin; 45 import org.eclipse.core.runtime.CoreException; 46 import org.eclipse.core.runtime.IPath; 47 import org.eclipse.core.runtime.IProgressMonitor; 48 import org.eclipse.core.runtime.Path; 49 import org.eclipse.core.runtime.SubProgressMonitor; 50 import org.eclipse.jdt.core.IJavaProject; 51 import org.eclipse.jdt.core.JavaCore; 52 import org.eclipse.jdt.core.formatter.CodeFormatter; 53 import org.eclipse.jface.text.Document; 54 import org.eclipse.jface.text.IDocument; 55 import org.eclipse.text.edits.TextEdit; 56 57 import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin; 58 import org.eclipse.emf.codegen.ecore.Generator; 59 import org.eclipse.emf.codegen.ecore.genmodel.GenBase; 60 import org.eclipse.emf.codegen.ecore.genmodel.GenClass; 61 import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier; 62 import org.eclipse.emf.codegen.ecore.genmodel.GenDataType; 63 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum; 64 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature; 65 import org.eclipse.emf.codegen.ecore.genmodel.GenModel; 66 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 67 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation; 68 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; 69 import org.eclipse.emf.codegen.jet.JETCompiler; 70 import org.eclipse.emf.codegen.jet.JETEmitter; 71 import org.eclipse.emf.codegen.jet.JETException; 72 import org.eclipse.emf.codegen.jmerge.JMerger; 73 import org.eclipse.emf.codegen.jmerge.PropertyMerger; 74 import org.eclipse.emf.codegen.util.CodeGenUtil; 75 import org.eclipse.emf.codegen.util.ImportManager; 76 import org.eclipse.emf.common.util.URI; 77 import org.eclipse.emf.common.util.UniqueEList; 78 import org.eclipse.emf.common.util.WrappedException; 79 import org.eclipse.emf.ecore.EAnnotation; 80 import org.eclipse.emf.ecore.EClass; 81 import org.eclipse.emf.ecore.EClassifier; 82 import org.eclipse.emf.ecore.EDataType; 83 import org.eclipse.emf.ecore.EEnum; 84 import org.eclipse.emf.ecore.EModelElement; 85 import org.eclipse.emf.ecore.ENamedElement; 86 import org.eclipse.emf.ecore.EObject; 87 import org.eclipse.emf.ecore.EOperation; 88 import org.eclipse.emf.ecore.EPackage; 89 import org.eclipse.emf.ecore.EParameter; 90 import org.eclipse.emf.ecore.EStructuralFeature; 91 import org.eclipse.emf.ecore.EcorePackage; 92 import org.eclipse.emf.ecore.impl.EObjectImpl; 93 import org.eclipse.emf.ecore.util.EcoreUtil; 94 import org.eclipse.emf.ecore.util.ExtendedMetaData; 95 import org.eclipse.emf.ecore.xml.namespace.XMLNamespacePackage; 96 import org.eclipse.emf.ecore.xml.type.XMLTypePackage; 97 98 99 108 public abstract class GenBaseImpl extends EObjectImpl implements GenBase 109 { 110 115 protected GenBaseImpl() 116 { 117 super(); 118 } 119 120 125 protected EClass eStaticClass() 126 { 127 return GenModelPackage.eINSTANCE.getGenBase(); 128 } 129 130 public GenModel getGenModel() 131 { 132 if (this instanceof GenModel) 133 return (GenModel)this; 134 else 135 return ((GenBase)eContainer()).getGenModel(); 136 } 137 138 public abstract String getName(); 139 140 public String capName(String name) 141 { 142 return CodeGenUtil.capName(name); 143 } 144 145 public String uncapName(String name) 146 { 147 return CodeGenUtil.uncapName(name); 148 } 149 150 public String uncapPrefixedName(String name) 151 { 152 return CodeGenUtil.uncapPrefixedName(name, false); 153 154 } 155 156 public String uncapPrefixedName(String name, boolean forceDifferent) 157 { 158 return CodeGenUtil.uncapPrefixedName(name, forceDifferent); 159 } 160 161 public String safeName(String name) 162 { 163 return CodeGenUtil.safeName(name); 164 } 165 166 protected String getImplClassName(String interfaceName) 167 { 168 return interfaceName + "Impl"; 169 } 170 171 public boolean canGenerate() 172 { 173 return getGenModel() != null && getGenModel().canGenerate() && hasModelContribution(); 174 } 175 176 protected boolean hasModelContribution() 177 { 178 return false; 179 } 180 181 public void generate(IProgressMonitor progressMonitor) 182 { 183 } 184 185 protected void generate(IProgressMonitor progressMonitor, int style, List pluginVariables, String outputFilePath, JETEmitter jetEmitter) 186 { 187 try 188 { 189 IPath outputPath = new Path(outputFilePath.substring(0, outputFilePath.lastIndexOf("/"))); 190 progressMonitor.beginTask("", 3); 191 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingFile_message", new Object [] { outputFilePath })); 192 IContainer container = findOrCreateContainer(new SubProgressMonitor(progressMonitor, 1), style, pluginVariables, outputPath, false); 193 if (container != null) 194 { 195 IFile targetFile = container.getFile(new Path(outputFilePath.substring(outputFilePath.lastIndexOf("/") + 1))); 196 if (targetFile.exists() && (outputFilePath.endsWith("/build.properties") || !outputFilePath.endsWith(".properties"))) 197 { 198 return; 199 } 200 201 if (outputFilePath.endsWith("/META-INF/MANIFEST.MF") && targetFile.getParent().getParent().exists(new Path("plugin.xml"))) 204 { 205 return; 206 } 207 208 boolean changed = false; 209 boolean isUnicodeEscapeEncoded = outputFilePath.endsWith(".properties"); 210 String emitterResult = jetEmitter.generate(new SubProgressMonitor(progressMonitor, 1), new Object [] { this }); 211 if (isUnicodeEscapeEncoded) 212 { 213 emitterResult = unicodeEscapeEncode(emitterResult); 214 } 215 216 progressMonitor.worked(1); 217 InputStream contents = new ByteArrayInputStream (emitterResult.toString().getBytes(isUnicodeEscapeEncoded ? "ISO-8859-1" : "UTF-8")); 218 if (targetFile.exists()) 219 { 220 PropertyMerger propertyMerger = new PropertyMerger(); 222 propertyMerger.setSourceProperties(emitterResult); 223 progressMonitor.subTask 224 (CodeGenEcorePlugin.INSTANCE.getString("_UI_ExaminingOld_message", new Object [] { targetFile.getFullPath() })); 225 String oldProperties = propertyMerger.createPropertiesForInputStream(targetFile.getContents(true)); 226 propertyMerger.setTargetProperties(oldProperties); 227 progressMonitor.subTask 228 (CodeGenEcorePlugin.INSTANCE.getString("_UI_PreparingNew_message", new Object [] { targetFile.getFullPath() })); 229 propertyMerger.merge(); 230 progressMonitor.worked(1); 231 232 String mergedResult = propertyMerger.getTargetProperties(); 233 changed = !mergedResult.equals(oldProperties); 234 if (changed) 235 { 236 if (targetFile.isReadOnly() && 237 targetFile.getWorkspace().validateEdit(new IFile [] { targetFile }, new SubProgressMonitor(progressMonitor, 1)).isOK()) 238 { 239 propertyMerger.setTargetProperties(propertyMerger.createPropertiesForInputStream(targetFile.getContents(true))); 240 propertyMerger.merge(); 241 mergedResult = propertyMerger.getTargetProperties(); 242 } 243 244 contents = new ByteArrayInputStream (mergedResult.getBytes(isUnicodeEscapeEncoded ? "ISO-8859-1" : "UTF-8")); 245 } 246 } 247 else 248 { 249 changed = true; 250 } 251 252 if (changed) 253 { 254 String redirection = getGenModel().getRedirection(); 255 boolean redirect = redirection != null && redirection.indexOf("{0}") != -1; 256 257 if (redirect) 260 { 261 String baseName = MessageFormat.format(redirection, new Object [] { targetFile.getName() }); 262 targetFile = container.getFile(new Path(baseName)); 263 progressMonitor.subTask 264 (CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingAlternate_message", new Object [] { targetFile.getFullPath() })); 265 } 266 267 if (targetFile.isReadOnly()) 268 { 269 if (getGenModel().isForceOverwrite()) 270 { 271 ResourceAttributes resourceAttributes = targetFile.getResourceAttributes(); 272 if (resourceAttributes != null) 273 { 274 resourceAttributes.setReadOnly(false); 275 targetFile.setResourceAttributes(resourceAttributes); 276 } 277 } 278 else 279 { 280 targetFile = container.getFile(new Path("." + targetFile.getName() + ".new")); 281 progressMonitor.subTask 282 (CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingDefaultAlternate_message", new Object [] { targetFile.getFullPath() })); 283 } 284 } 285 286 if (targetFile.exists()) 287 { 288 targetFile.setContents(contents, true, true, new SubProgressMonitor(progressMonitor, 1)); 289 } 290 else 291 { 292 targetFile.create(contents, true, new SubProgressMonitor(progressMonitor, 1)); 293 } 294 } 295 } 296 } 297 catch (Exception exception) 298 { 299 CodeGenEcorePlugin.INSTANCE.log(exception); 300 } 301 finally 302 { 303 progressMonitor.done(); 304 } 305 } 306 307 protected void generate 308 (IProgressMonitor progressMonitor, 309 int style, 310 List pluginVariables, 311 String outputFilePath, 312 GIFEmitter gifEmitter, 313 String key) 314 { 315 generate(progressMonitor, style, pluginVariables, outputFilePath, gifEmitter, key, null); 316 } 317 318 protected void generate 319 (IProgressMonitor progressMonitor, 320 int style, 321 List pluginVariables, 322 String outputFilePath, 323 GIFEmitter gifEmitter, 324 String parentKey, 325 String childKey) 326 { 327 try 328 { 329 IPath outputPath = new Path(outputFilePath.substring(0, outputFilePath.lastIndexOf("/"))); 330 progressMonitor.beginTask("", 3); 331 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingImage_message", new Object [] { outputFilePath })); 332 IContainer container = 333 findOrCreateContainer(new SubProgressMonitor(progressMonitor, 1), style, pluginVariables, outputPath, false); 334 if (container != null) 335 { 336 IFile targetFile = container.getFile(new Path(outputFilePath.substring(outputFilePath.lastIndexOf("/") + 1))); 337 if (targetFile.exists()) 338 { 339 } 341 else 342 { 343 byte[] emitterResult = gifEmitter.generateGIF(parentKey, childKey); 344 progressMonitor.worked(1); 345 InputStream contents = new ByteArrayInputStream (emitterResult); 346 targetFile.create(contents, true, new SubProgressMonitor(progressMonitor, 1)); 347 } 348 } 349 } 350 catch (Exception exception) 351 { 352 CodeGenEcorePlugin.INSTANCE.log(exception); 353 } 354 progressMonitor.done(); 355 } 356 357 protected void generate 358 (IProgressMonitor progressMonitor, 359 int style, 360 List pluginVariables, 361 String targetDirectory, 362 String packageName, 363 String className, 364 JETEmitter jetEmitter) 365 { 366 try 367 { 368 IPath outputPath = new Path(targetDirectory + "/" + packageName.replace('.','/')); 369 progressMonitor.beginTask("", 4); 370 IContainer container = findOrCreateContainer(new SubProgressMonitor(progressMonitor, 1), style, pluginVariables, outputPath, false); 371 if (container != null) 372 { 373 ImportManager importManager = new ImportManager(packageName); 375 importManager.addMasterImport(packageName, className); 376 setImportManager(importManager); 377 378 CodeFormatter codeFormatter = getGenModel().isCodeFormatting() ? getGenModel().createCodeFormatter() : null; 380 381 String emitterResult = jetEmitter.generate(new SubProgressMonitor(progressMonitor, 1), new Object [] { this }); 382 progressMonitor.worked(1); 383 384 boolean changed = true; 385 IFile targetFile = container.getFile(new Path(className + ".java")); 386 progressMonitor.subTask 387 (CodeGenEcorePlugin.INSTANCE.getString("_UI_Generating_message", new Object [] { targetFile.getFullPath()})); 388 JMerger jMerger = new JMerger(); 389 jMerger.setControlModel(getGenModel().getJControlModel()); 390 jMerger.setSourceCompilationUnit(jMerger.createCompilationUnitForContents(emitterResult)); 391 String newContents = null; 392 if (targetFile.exists()) 393 { 394 progressMonitor.subTask 395 (CodeGenEcorePlugin.INSTANCE.getString("_UI_ExaminingOld_message", new Object [] { targetFile.getFullPath() })); 396 jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(targetFile.getContents(true))); 397 String oldContents = jMerger.getTargetCompilationUnitContents(); 398 399 progressMonitor.subTask 400 (CodeGenEcorePlugin.INSTANCE.getString("_UI_PreparingNew_message", new Object [] { targetFile.getFullPath() })); 401 jMerger.merge(); 402 progressMonitor.worked(1); 403 404 newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter); 405 changed = !oldContents.equals(newContents); 406 if (changed) 407 { 408 if (targetFile.isReadOnly() && 409 targetFile.getWorkspace().validateEdit(new IFile [] { targetFile }, new SubProgressMonitor(progressMonitor, 1)).isOK()) 410 { 411 jMerger.setTargetCompilationUnit(jMerger.createCompilationUnitForInputStream(targetFile.getContents(true))); 412 jMerger.remerge(); 413 newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter); 414 } 415 } 416 } 417 else 418 { 419 changed = true; 420 progressMonitor.subTask 421 (CodeGenEcorePlugin.INSTANCE.getString("_UI_PreparingNew_message", new Object [] { targetFile.getFullPath() })); 422 jMerger.merge(); 423 progressMonitor.worked(1); 424 newContents = formatCode(jMerger.getTargetCompilationUnitContents(), codeFormatter); 425 } 426 427 if (changed) 428 { 429 String encoding = null; 436 try 437 { 438 encoding = targetFile.getCharset(); 439 } 440 catch (CoreException ce) 441 { 442 } 444 byte[] bytes = encoding == null 445 ? newContents.getBytes() 446 : newContents.getBytes(encoding); 447 448 InputStream contents = new ByteArrayInputStream (bytes); 449 450 String redirection = getGenModel().getRedirection(); 451 boolean redirect = redirection != null && redirection.indexOf("{0}") != -1; 452 453 if (redirect) 456 { 457 String baseName = MessageFormat.format(redirection, new Object [] { className + ".java" }); 458 targetFile = container.getFile(new Path(baseName)); 459 progressMonitor.subTask 460 (CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingAlternate_message", new Object [] { targetFile.getFullPath() })); 461 } 462 463 if (targetFile.isReadOnly()) 464 { 465 if (getGenModel().isForceOverwrite()) 466 { 467 ResourceAttributes resourceAttributes = targetFile.getResourceAttributes(); 468 if (resourceAttributes != null) 469 { 470 resourceAttributes.setReadOnly(false); 471 targetFile.setResourceAttributes(resourceAttributes); 472 } 473 } 474 else 475 { 476 targetFile = container.getFile(new Path("." + className + ".java.new")); 477 progressMonitor.subTask 478 (CodeGenEcorePlugin.INSTANCE.getString("_UI_UsingDefaultAlternate_message", new Object [] { targetFile.getFullPath() })); 479 } 480 } 481 482 if (targetFile.exists()) 483 { 484 targetFile.setContents(contents, true, true, new SubProgressMonitor(progressMonitor, 1)); 485 } 486 else 487 { 488 targetFile.create(contents, true, new SubProgressMonitor(progressMonitor, 1)); 489 } 490 } 491 } 492 } 493 catch (JETException exception) 494 { 495 CodeGenEcorePlugin.INSTANCE.log(exception); 496 } 497 catch (Exception exception) 498 { 499 CodeGenEcorePlugin.INSTANCE.log(exception); 500 } 501 502 setImportManager(null); 504 505 progressMonitor.done(); 506 } 507 508 protected ImportManager getImportManager() 509 { 510 return ((GenBaseImpl)getGenModel()).getImportManager(); 511 } 512 513 protected void setImportManager(ImportManager importManager) 514 { 515 GenModelImpl genModel = (GenModelImpl)getGenModel(); 516 if (genModel != null) 517 { 518 genModel.setImportManager(importManager); 519 520 if (ecoreGenPackage != null && ((GenPackageImpl)ecoreGenPackage).getImportManager() != importManager) 523 { 524 ((GenPackageImpl)ecoreGenPackage).setImportManager(getImportManager()); 525 } 526 if (xmlTypeGenPackage != null && ((GenPackageImpl)xmlTypeGenPackage).getImportManager() != importManager) 527 { 528 ((GenPackageImpl)xmlTypeGenPackage).setImportManager(getImportManager()); 529 } 530 if (xmlNamespaceGenPackage != null && ((GenPackageImpl)xmlNamespaceGenPackage).getImportManager() != importManager) 531 { 532 ((GenPackageImpl)xmlNamespaceGenPackage).setImportManager(getImportManager()); 533 } 534 } 535 } 536 537 protected IContainer findOrCreateContainer 538 (IProgressMonitor progressMonitor, int style, List pluginVariables, IPath outputPath, boolean forceStyle) 539 { 540 IContainer container = null; 541 try 542 { 543 progressMonitor.beginTask("", outputPath.segmentCount() + 1); 544 progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_OpeningFolder_message", new Object [] { outputPath })); 545 if (outputPath.isAbsolute()) 546 { 547 IWorkspace workspace = ResourcesPlugin.getWorkspace(); 548 IProject project = workspace.getRoot().getProject(outputPath.segment(0)); 549 if (forceStyle || !project.exists()) 550 { 551 IPath projectLocation = null; 552 553 List referencedProjects = new UniqueEList(); 554 if (project.exists()) 555 { 556 referencedProjects.addAll(Arrays.asList(project.getDescription().getReferencedProjects())); 557 projectLocation = project.getDescription().getLocation(); 558 } 559 else 560 { 561 URI genModelURI = getGenModel().eResource().getURI(); 562 if (genModelURI.toString().startsWith("platform:/resource/")) 563 { 564 IProject genModelProject = workspace.getRoot().getProject(genModelURI.segments()[1]); 565 projectLocation = genModelProject.getDescription().getLocation(); 566 } 567 } 568 569 IProject modelProject = workspace.getRoot().getProject(getGenModel().getModelProjectDirectory()); 570 IPath javaSource = new Path(getGenModel().getModelDirectory()); 571 572 if ((style & Generator.EMF_TESTS_PROJECT_STYLE) != 0) 573 { 574 IProject testsProject = workspace.getRoot().getProject(getGenModel().getTestsProjectDirectory()); 575 576 if (!getGenModel().sameModelTestsProject()) 577 { 578 javaSource = new Path(getGenModel().getTestsDirectory()); 579 580 if (testsProject.exists()) 581 { 582 projectLocation = testsProject.getDescription().getLocation(); 583 } 584 585 referencedProjects.add(modelProject); 586 referencedProjects.addAll(Arrays.asList(modelProject.getDescription().getReferencedProjects())); 587 } 588 } 589 else if ((style & Generator.EMF_MODEL_PROJECT_STYLE) == 0 && getGenModel().hasEditSupport()) 590 { 591 IProject editProject = workspace.getRoot().getProject(getGenModel().getEditProjectDirectory()); 592 593 if (!getGenModel().sameModelEditProject()) 594 { 595 javaSource = new Path(getGenModel().getEditDirectory()); 596 if (editProject.exists()) 597 { 598 projectLocation = editProject.getDescription().getLocation(); 599 } 600 601 referencedProjects.add(modelProject); 602 } 603 604 for (Iterator i = getGenModel().getUsedGenPackages().iterator(); i.hasNext(); ) 605 { 606 GenModel otherGenModel = ((GenPackage)i.next()).getGenModel(); 607 if (otherGenModel.hasEditSupport()) 608 { 609 IProject otherEditProject = workspace.getRoot().getProject(otherGenModel.getEditProjectDirectory()); 610 if (otherEditProject.exists()) 611 { 612 referencedProjects.add(otherEditProject); 613 referencedProjects.addAll(Arrays.asList(otherEditProject.getDescription().getReferencedProjects())); 614 } 615 } 616 } 617 618 if ((style & Generator.EMF_EDIT_PROJECT_STYLE) == 0 && getGenModel().hasEditorSupport()) 619 { 620 javaSource = new Path(getGenModel().getEditorDirectory()); 621 if (!getGenModel().sameEditEditorProject()) 622 { 623 referencedProjects.add(editProject); 624 referencedProjects.addAll(Arrays.asList(editProject.getDescription().getReferencedProjects())); 625 } 626 } 627 } 628 629 for (Iterator i = referencedProjects.iterator(); i.hasNext(); ) 632 { 633 IProject referencedProject = (IProject)i.next(); 634 IJavaProject referencedJavaProject = JavaCore.create(referencedProject); 635 if (!referencedJavaProject.exists()) 636 { 637 i.remove(); 638 } 639 } 640 641 if (projectLocation != null) 642 { 643 projectLocation = projectLocation.removeLastSegments(1).append(javaSource.segment(0)); 644 } 645 646 if (getGenModel().hasXMLDependency()) 647 { 648 style |= Generator.EMF_XML_PROJECT_STYLE; 649 } 650 651 if ((style & Generator.EMF_MODEL_PROJECT_STYLE) == 0 || getGenModel().hasPluginSupport()) 652 { 653 style |= Generator.EMF_PLUGIN_PROJECT_STYLE; 654 } 655 656 Generator.createEMFProject 657 (javaSource, 658 projectLocation, 659 referencedProjects, 660 progressMonitor, 661 style, 662 pluginVariables); 663 } 664 else 665 { 666 if (!project.isOpen()) 667 { 668 project.open(new SubProgressMonitor(progressMonitor, 1)); 669 } 670 } 671 672 container = project; 673 for (int i = 1, length = outputPath.segmentCount(); i < length; ++ i) 674 { 675 IFolder folder = container.getFolder(new Path(outputPath.segment(i))); 676 if (!folder.exists()) 677 { 678 folder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); 679 } 680 container = folder; 681 } 682 } 683 } 684 catch (Exception exception) 685 { 686 CodeGenEcorePlugin.INSTANCE.log(exception); 687 } 688 progressMonitor.done(); 689 return container; 690 } 691 692 697 protected String formatCode(String contents, CodeFormatter codeFormatter) 698 { 699 if (getGenModel().isCodeFormatting()) 700 { 701 if (codeFormatter == null) 702 { 703 codeFormatter = getGenModel().createCodeFormatter(); 704 } 705 706 IDocument doc = new Document(contents); 707 TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0, doc.get().length(), 0, null); 708 709 try 710 { 711 edit.apply(doc); 712 contents = doc.get(); 713 } 714 catch (Exception exception) 715 { 716 CodeGenEcorePlugin.INSTANCE.log(exception); 717 } 718 } 719 return contents; 720 } 721 722 public String format(String name, char separator, String prefix, boolean includePrefix) 723 { 724 return CodeGenUtil.format(name, separator, prefix, includePrefix); 725 } 726 727 732 protected final List parseName(String sourceName, char sourceSeparator) 733 { 734 return Collections.EMPTY_LIST; 735 } 736 737 protected List getAllGenPackages() 738 { 739 List result = new ArrayList (); 740 result.addAll(getGenModel().getGenPackages()); 741 result.addAll(getGenModel().getUsedGenPackages()); 742 result.addAll(getGenModel().getStaticGenPackages()); 743 return result; 744 } 745 746 749 protected GenPackage findGenPackageHelper(GenPackage genPackage, EPackage ePackage) 750 { 751 if (ePackage.getNsURI() == null ? 752 genPackage.getEcorePackage().getNsURI() == null : 753 ePackage.getNsURI().equals(genPackage.getEcorePackage().getNsURI())) { 755 return genPackage; 756 } 757
|