org.eclipse.emf.importer.java_2.6.0.v20120130-0943

16:43:39.380 INFO  jd.cli.Main - Decompiling org.eclipse.emf.importer.java_2.6.0.v20120130-0943.jar
package org.eclipse.emf.importer.java;

import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.importer.ModelImporter;
import org.eclipse.emf.importer.java.builder.JavaEcoreBuilder;

public class JavaImporter
  extends ModelImporter
{
  public String getID()
  {
    return "org.eclipse.emf.importer.java";
  }
  
  public boolean canImport()
  {
    IFile genModelFile = getGenModelFile();
    if (genModelFile != null)
    {
      IProject project = genModelFile.getProject();
      try
      {
        if (project.hasNature("org.eclipse.jdt.core.javanature")) {
          return true;
        }
        if (originalGenModel != null)
        {
          String modelDirectory = originalGenModel.getModelDirectory();
          if (modelDirectory != null)
          {
            IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(modelDirectory));
            if ((folder.exists()) && (folder.getProject().hasNature("org.eclipse.jdt.core.javanature"))) {
              return true;
            }
          }
        }
      }
      catch (CoreException e)
      {
        JavaImporterPlugin.INSTANCE.log(e);
      }
    }
    return false;
  }
  
  protected IFile getGenModelFile()
  {
    IPath path = getGenModelPath();
    if (path != null) {
      return getWorkspaceRoot().getFile(path);
    }
    return null;
  }
  
  public EPackage getReferredEPackage(GenPackage genPackage)
  {
    return genPackage.getEcorePackage();
  }
  
  protected Diagnostic doComputeEPackages(Monitor monitor)
    throws Exception
  {
    monitor.beginTask("", 2);
    monitor.subTask(JavaImporterPlugin.INSTANCE.getString("_UI_CreatingPackages_message"));
    
    JavaEcoreBuilder javaEcoreBuilder = new JavaEcoreBuilder(getGenModelFile(), getOriginalGenModel());
    javaEcoreBuilder.computeEPackages(monitor, this);
    getReferencedGenPackages().clear();
    getReferencedGenPackages().addAll(javaEcoreBuilder.getUsedGenPackages());
    return javaEcoreBuilder.getDiagnostic();
  }
  
  protected void adjustGenModel(Monitor monitor)
  {
    super.adjustGenModel(monitor);
    getGenModel().getForeignModel().add("@model");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.JavaImporter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java;

public class JavaImporterApplication$PackageInfo
{
  public String nsURI;
  public String base;
  public String prefix;
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.JavaImporterApplication.PackageInfo
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.importer.ModelImporter;
import org.eclipse.emf.importer.ModelImporter.EPackageImportInfo;
import org.eclipse.emf.importer.ModelImporterApplication;

public class JavaImporterApplication
  extends ModelImporterApplication
{
  protected Map<String, PackageInfo> nameToPackageInfo;
  protected IPath genModelLocation;
  
  public JavaImporter getJavaImporter()
  {
    return (JavaImporter)getModelImporter();
  }
  
  protected ModelImporter createModelImporter()
  {
    return new JavaImporter();
  }
  
  protected StringBuffer getUsage()
  {
    StringBuffer result = new StringBuffer();
    appendLine(result, "Usage: <workspace absolute path of model.genmodel> [ -reload ] <OPTION>");
    appendLine(result, "<OPTION>          ::= [ <PROJECT-OPTION> ]  [ <PATHMAP> ]");
    appendLine(result, "                      { <PACKAGE> }+  { <REF-PACKAGE> }* { <REF-GEN-MODEL> }*");
    appendLine(result, "                      [ <TEMPLATE-PATH> ] [ <MODEL-PLUGIN-ID> ] [ <COPYRIGHT> ]");
    appendLine(result, "                      [ <SDO> ] [ <QUIET> ]");
    appendLine(result, "<PROJECT-OPTION>  ::= <MODEL-PROJECT> [ <EDIT-PROJECT> ] [ <EDITOR-PROJECT> ]");
    appendLine(result, "                      [ <TESTS-PROJECT> ]");
    appendLine(result, "<MODEL-PROJECT>   ::= -modelProject <model-directory>");
    appendLine(result, "<EDIT-PROJECT>    ::= -editProject <edit-directory> <fragment-path>");
    appendLine(result, "<EDITOR-PROJECT>  ::= -editorProject <editor-directory> <fragment-path>");
    appendLine(result, "<TESTS-PROJECT>   ::= -testsProject <tests-directory> <fragment-path>");
    appendLine(result, "<PACKAGE>         ::= -package <nsURI> [ <base> <prefix> ]");
    appendLine(result, "<REF-GEN-MODEL>   ::= -refGenModel <model.genmodel> { <nsURI> }+");
    appendLine(result, "<TEMPLATE-PATH>   ::= -templatePath <template-directory>");
    appendLine(result, "<MODEL-PLUGIN-ID> ::= -modelPluginID <plugin-ID>");
    appendLine(result, "<COPYRIGHT>       ::= -copyright <copyright-string>");
    appendLine(result, "<JDK-LEVEL>       ::= -jdkLevel <jdk level: 1.4 5.0 6.0>");
    appendLine(result, "<VALIDATE-MODEL>  ::= -validateModel <true|false>");
    appendLine(result, "<SDO>             ::= -sdo");
    appendLine(result, "<QUIET>           ::= -quiet");
    appendLine(result, "");
    appendLine(result, "For example:");
    appendLine(result, "");
    appendLine(result, "");
    appendLine(result, "  java2genmodel");
    appendLine(result, "    /library/model/lib.genmodel");
    appendLine(result, "    -modelProject result");
    appendLine(result, "    -editProject result.edit src");
    appendLine(result, "    -editorProject result.editor src");
    return result;
  }
  
  protected int processModelAndGenModelLocationArguments(String[] arguments, int index)
  {
    if (arguments.length > 0)
    {
      String arg = arguments[(index++)];
      if (arg.endsWith(".genmodel"))
      {
        genModelFullPath = new Path(arg);
        return index;
      }
    }
    throw new IllegalArgumentException("Invalid arguments.  Run this application without arguments for the usage help.");
  }
  
  protected int processModelProjectArguments(String[] arguments, int index)
  {
    modelProjectLocationPath = new Path(new File(arguments[(++index)]).getAbsolutePath());
    return index;
  }
  
  protected int processArgument(String[] arguments, int index)
  {
    if (arguments[index].equalsIgnoreCase("-package"))
    {
      if (nameToPackageInfo == null) {
        nameToPackageInfo = new HashMap();
      }
      index = processPackageInformation(arguments, index, nameToPackageInfo);
    }
    else
    {
      return super.processArgument(arguments, index);
    }
    return index + 1;
  }
  
  protected int processPackageInformation(String[] arguments, int index, Map<String, PackageInfo> nsURIToPackageInfo)
  {
    int start = index;
    PackageInfo packageInfo = new PackageInfo();
    if ((index + 1 < arguments.length) && (!arguments[(index + 1)].startsWith("-")))
    {
      nsURI = arguments[(++index)];
      if ((index + 1 < arguments.length) && (!arguments[(index + 1)].startsWith("-")))
      {
        base = arguments[(++index)];
        if ((index + 1 < arguments.length) && (!arguments[(index + 1)].startsWith("-"))) {
          prefix = arguments[(++index)];
        }
      }
      if ((index - start != 1) && (index - start != 3)) {
        throw new IllegalArgumentException("Error: Expecting either 1 or 3 arguments for " + arguments[start]);
      }
      nsURIToPackageInfo.put(nsURI, packageInfo);
      nsURIToPackageInfo.put(nsURI.toLowerCase(), packageInfo);
      return index;
    }
    throw new IllegalArgumentException("Error: No package name was specified for " + arguments[start]);
  }
  
  protected boolean usePlatformURI()
  {
    return true;
  }
  
  protected void adjustModelImporter(Monitor monitor)
  {
    super.adjustModelImporter(monitor);
    
    IFile genModelFile = getJavaImporter().getGenModelFile();
    if (!genModelFile.getProject().exists()) {
      try
      {
        IProject project = genModelFile.getProject();
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
        projectDescription.setLocation(modelProjectLocationPath);
        project.create(projectDescription, BasicMonitor.toIProgressMonitor(monitor));
      }
      catch (CoreException e)
      {
        JavaImporterPlugin.INSTANCE.log(e);
        throw new RuntimeException(e);
      }
    }
  }
  
  protected void adjustModelImporterAfterPrepare()
  {
    if (genJDKLevel != null) {
      getModelImporter().getGenModel().setComplianceLevel(genJDKLevel);
    }
  }
  
  /* Error */
  protected void adjustEPackages(Monitor monitor)
  {
    // Byte code:
    //   0: aload_1
    //   1: ldc 1
    //   3: iconst_2
    //   4: invokeinterface 377 3 0
    //   9: aload_0
    //   10: aload_1
    //   11: iconst_1
    //   12: invokestatic 339	org/eclipse/emf/codegen/util/CodeGenUtil:createMonitor	(Lorg/eclipse/emf/common/util/Monitor;I)Lorg/eclipse/emf/common/util/Monitor;
    //   15: invokespecial 348	org/eclipse/emf/importer/ModelImporterApplication:adjustEPackages	(Lorg/eclipse/emf/common/util/Monitor;)V
    //   18: aload_0
    //   19: invokevirtual 359	org/eclipse/emf/importer/java/JavaImporterApplication:getJavaImporter	()Lorg/eclipse/emf/importer/java/JavaImporter;
    //   22: invokevirtual 351	org/eclipse/emf/importer/java/JavaImporter:getEPackages	()Ljava/util/List;
    //   25: astore_2
    //   26: aload_0
    //   27: aload_2
    //   28: invokevirtual 355	org/eclipse/emf/importer/java/JavaImporterApplication:traverseEPackages	(Ljava/util/List;)V
    //   31: aload_0
    //   32: invokevirtual 359	org/eclipse/emf/importer/java/JavaImporterApplication:getJavaImporter	()Lorg/eclipse/emf/importer/java/JavaImporter;
    //   35: aload_1
    //   36: iconst_1
    //   37: invokestatic 339	org/eclipse/emf/codegen/util/CodeGenUtil:createMonitor	(Lorg/eclipse/emf/common/util/Monitor;I)Lorg/eclipse/emf/common/util/Monitor;
    //   40: invokevirtual 353	org/eclipse/emf/importer/java/JavaImporter:adjustEPackages	(Lorg/eclipse/emf/common/util/Monitor;)V
    //   43: goto +12 -> 55
    //   46: astore_3
    //   47: aload_1
    //   48: invokeinterface 376 1 0
    //   53: aload_3
    //   54: athrow
    //   55: aload_1
    //   56: invokeinterface 376 1 0
    //   61: return
    // Line number table:
    //   Java source line #216	-> byte code offset #0
    //   Java source line #217	-> byte code offset #9
    //   Java source line #219	-> byte code offset #18
    //   Java source line #220	-> byte code offset #26
    //   Java source line #221	-> byte code offset #31
    //   Java source line #224	-> byte code offset #46
    //   Java source line #225	-> byte code offset #47
    //   Java source line #226	-> byte code offset #53
    //   Java source line #225	-> byte code offset #55
    //   Java source line #227	-> byte code offset #61
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	62	0	this	JavaImporterApplication
    //   0	62	1	monitor	Monitor
    //   25	3	2	ePackages	List<EPackage>
    //   46	8	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   0	46	46	finally
  }
  
  protected void traverseEPackages(List<EPackage> ePackages)
  {
    for (EPackage ePackage : ePackages)
    {
      if (nameToPackageInfo != null)
      {
        PackageInfo packageInfo = (PackageInfo)nameToPackageInfo.get(ePackage.getNsURI());
        if (packageInfo != null)
        {
          handleEPackage(ePackage, true);
          
          ModelImporter.EPackageImportInfo ePackageInfo = getJavaImporter().getEPackageImportInfo(ePackage);
          if (ePackageInfo.getBasePackage() == null) {
            ePackageInfo.setBasePackage(base);
          }
          if (ePackageInfo.getPrefix() == null) {
            ePackageInfo.setPrefix(prefix);
          }
        }
      }
      handleQualifiedEPackageName(ePackage);
      traverseEPackages(ePackage.getESubpackages());
    }
  }
  
  public static class PackageInfo
  {
    public String nsURI;
    public String base;
    public String prefix;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.JavaImporterApplication
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java;

import org.eclipse.emf.common.EMFPlugin.EclipsePlugin;

public class JavaImporterPlugin$Implementation
  extends EMFPlugin.EclipsePlugin
{
  public JavaImporterPlugin$Implementation()
  {
    JavaImporterPlugin.access$0(this);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.JavaImporterPlugin.Implementation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java;

import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.EMFPlugin.EclipsePlugin;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.importer.ImporterPlugin;

public final class JavaImporterPlugin
  extends EMFPlugin
{
  public static final JavaImporterPlugin INSTANCE = new JavaImporterPlugin();
  private static Implementation plugin;
  
  private JavaImporterPlugin()
  {
    super(new ResourceLocator[] { ImporterPlugin.INSTANCE });
  }
  
  public ResourceLocator getPluginResourceLocator()
  {
    return plugin;
  }
  
  public static Implementation getPlugin()
  {
    return plugin;
  }
  
  public static class Implementation
    extends EMFPlugin.EclipsePlugin
  {
    public Implementation()
    {
      JavaImporterPlugin.plugin = this;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.JavaImporterPlugin
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EcoreUtil.EGenericTypeConverter;

class JavaEcoreBuilder$1
  extends EcoreUtil.EGenericTypeConverter
{
  JavaEcoreBuilder$1(JavaEcoreBuilder paramJavaEcoreBuilder) {}
  
  protected String getInstanceTypeName(EClassifier eClassifier)
  {
    String result = super.getInstanceTypeName(eClassifier);
    if (result == null)
    {
      EPackage ePackage = eClassifier.getEPackage();
      for (Map.Entry<String, EPackage> entry : this$0.packageNameToEPackageMap.entrySet()) {
        if (entry.getValue() == ePackage) {
          return (String)entry.getKey() + '.' + eClassifier.getName();
        }
      }
      for (Map.Entry<String, EPackage> entry : this$0.externalPackageNameToEPackageMap.entrySet()) {
        if (entry.getValue() == ePackage) {
          return (String)entry.getKey() + '.' + eClassifier.getName();
        }
      }
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import java.util.Comparator;
import java.util.Map;

class JavaEcoreBuilder$2
  implements Comparator<T>
{
  JavaEcoreBuilder$2(JavaEcoreBuilder paramJavaEcoreBuilder, Map paramMap) {}
  
  public boolean equals(Object object)
  {
    return object == this;
  }
  
  public int compare(T firstObject, T secondObject)
  {
    int firstValue = this$0.getOrderingValue(firstObject, val$nameToIDMap);
    int secondValue = this$0.getOrderingValue(secondObject, val$nameToIDMap);
    return firstValue - secondValue;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import org.eclipse.emf.ecore.EClassifier;

 enum JavaEcoreBuilder$RequiredClassifierType$1
{
  JavaEcoreBuilder$RequiredClassifierType$1()
  {
    super(paramString, paramInt, null);
  }
  
  boolean isValid(EClassifier eClassifier)
  {
    return eClassifier != null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.RequiredClassifierType.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;

 enum JavaEcoreBuilder$RequiredClassifierType$2
{
  JavaEcoreBuilder$RequiredClassifierType$2()
  {
    super(paramString, paramInt, null);
  }
  
  boolean isValid(EClassifier eClassifier)
  {
    return eClassifier instanceof EClass;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.RequiredClassifierType.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;

 enum JavaEcoreBuilder$RequiredClassifierType$3
{
  JavaEcoreBuilder$RequiredClassifierType$3()
  {
    super(paramString, paramInt, null);
  }
  
  boolean isValid(EClassifier eClassifier)
  {
    return eClassifier instanceof EDataType;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.RequiredClassifierType.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;

public enum JavaEcoreBuilder$RequiredClassifierType
{
  NONE,  CLASS,  DATA_TYPE;
  
  abstract boolean isValid(EClassifier paramEClassifier);
}

/* Location:
 * Qualified Name:     org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.RequiredClassifierType
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.emf.importer.java.builder;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.codegen.merge.java.JMerger;
import org.eclipse.emf.codegen.merge.java.facade.FacadeHelper;
import org.eclipse.emf.codegen.merge.java.facade.JAbstractType;
import org.eclipse.emf.codegen.merge.java.facade.JAnnotationType;
import org.eclipse.emf.codegen.merge.java.facade.JCompilationUnit;
import org.eclipse.emf.codegen.merge.java.facade.JEnum;
import org.eclipse.emf.codegen.merge.java.facade.JEnumConstant;
import org.eclipse.emf.codegen.merge.java.facade.JField;
import org.eclipse.emf.codegen.merge.java.facade.JImport;
import org.eclipse.emf.codegen.merge.java.facade.JMember;
import org.eclipse.emf.codegen.merge.java.facade.JMethod;
import org.eclipse.emf.codegen.merge.java.facade.JNode;
import org.eclipse.emf.codegen.merge.java.facade.JPackage;
import org.eclipse.emf.codegen.merge.java.facade.JType;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.Monitor;
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.EEnumLiteral;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.EcorePackage.Literals;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.EGenericTypeConverter;
import org.eclipse.emf.ecore.util.EcoreValidator.EGenericTypeBuilder;
import org.eclipse.emf.ecore.xml.namespace.XMLNamespacePackage;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
import org.eclipse.emf.importer.ModelImporter;
import org.eclipse.emf.importer.ModelImporter.EPackageImportInfo;
import org.eclipse.emf.importer.java.JavaImporterPlugin;
import org.eclipse.emf.importer.java.JavaImporterPlugin.Implementation;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;

public class JavaEcoreBuilder
{
  protected static FacadeHelper facadeHelper = CodeGenUtil.instantiateFacadeHelper(JMerger.DEFAULT_FACADE_HELPER_CLASS);
  protected IFile genModelFile;
  protected GenModel genModel;
  protected Map<String, EPackage> externalPackageNameToEPackageMap = new LinkedHashMap();
  protected Map<String, EPackage> packageNameToEPackageMap = new LinkedHashMap();
  protected Map<EPackage, Map<Object, Integer>> ePackageToOrderingMap = new LinkedHashMap();
  protected Map<EPackage, String> ePackageToPrefixMap = new LinkedHashMap();
  protected Map<EModelElement, JNode> eModelElementToJNodeMap = new LinkedHashMap();
  protected Set<EStructuralFeature> eStructuralFeatures = new LinkedHashSet();
  protected Set<EAttribute> eAttributes = new LinkedHashSet();
  protected Map<EGenericType, EGenericType> ecoreEGenericTypeToJavaEGenericTypeMap = new LinkedHashMap();
  protected Set<EClassifier> demandCreatedEClassifiers = new LinkedHashSet();
  protected Map<EReference, String> eReferenceToOppositeNameMap = new LinkedHashMap();
  protected Set<EReference> transientEReferenceWithOpposite = new HashSet();
  protected Map<EReference, List<String>> eReferenceToKeyNamesMap = new LinkedHashMap();
  protected Collection<GenModel> externalGenModels = new UniqueEList();
  protected Collection<GenPackage> usedGenPackages = new ArrayList();
  protected BasicDiagnostic basicDiagnostic;
  protected boolean foundJava;
  protected GenModel oldGenModelVersion;
  protected EcoreUtil.EGenericTypeConverter eGenericTypeConverter = new EcoreUtil.EGenericTypeConverter()
  {
    protected String getInstanceTypeName(EClassifier eClassifier)
    {
      String result = super.getInstanceTypeName(eClassifier);
      if (result == null)
      {
        EPackage ePackage = eClassifier.getEPackage();
        for (Map.Entry<String, EPackage> entry : packageNameToEPackageMap.entrySet()) {
          if (entry.getValue() == ePackage) {
            return (String)entry.getKey() + '.' + eClassifier.getName();
          }
        }
        for (Map.Entry<String, EPackage> entry : externalPackageNameToEPackageMap.entrySet()) {
          if (entry.getValue() == ePackage) {
            return (String)entry.getKey() + '.' + eClassifier.getName();
          }
        }
      }
      return result;
    }
  };
  protected static final String MAP_ENTRY_CLASS_CONTAINER_ANNOTATION_SOURCE = "http://www.eclipse.org/emf/2002/Ecore#MapEntryClassContainer";
  
  public JavaEcoreBuilder(IFile genModelFile)
  {
    this.genModelFile = genModelFile;
    
    basicDiagnostic = new BasicDiagnostic(
      JavaImporterPlugin.getPlugin().getBundle().getSymbolicName(), 
      0, 
      CodeGenEcorePlugin.INSTANCE.getString("_UI_ErrorsWereDetectedJava_message"), 
      null);
  }
  
  public JavaEcoreBuilder(IFile genModelFile, GenModel oldGenModelVersion)
  {
    this(genModelFile);
    this.oldGenModelVersion = oldGenModelVersion;
  }
  
  public JavaEcoreBuilder(IFile genModelFile, GenModel oldGenModelVersion, GenModel genModel)
  {
    this(genModelFile, oldGenModelVersion);
    this.genModel = genModel;
  }
  
  protected ResourceSet createResourceSet()
  {
    ResourceSet result = new ResourceSetImpl();
    result.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
    return result;
  }
  
  protected IPath analyzeProject(IProject project)
    throws Exception
  {
    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = javaProject.getPackageFragmentRoots();
    Set<IResource> visited = new HashSet();
    for (int i = 0; i < packageFragmentRoots.length; i++) {
      if (packageFragmentRoots[i].getKind() == 1) {
        traverse((IContainer)packageFragmentRoots[i].getUnderlyingResource(), visited);
      }
    }
    for (Map.Entry<EGenericType, EGenericType> entry : ecoreEGenericTypeToJavaEGenericTypeMap.entrySet())
    {
      EGenericType ecoreEGenericType = (EGenericType)entry.getKey();
      EGenericType javaEGenericType = (EGenericType)entry.getValue();
      EModelElement eModelElement = null;
      for (EObject eObject = ecoreEGenericType.eContainer(); eObject != null; eObject = eObject.eContainer()) {
        if ((eObject instanceof EModelElement))
        {
          eModelElement = (EModelElement)eObject;
          break;
        }
      }
      RequiredClassifierType requiredClassifierType = 
      
        eAttributes.contains(ecoreEGenericType.eContainer()) ? 
        RequiredClassifierType.DATA_TYPE : ((ecoreEGenericType.eContainer() instanceof EClass)) || ((ecoreEGenericType.eContainer() instanceof EReference)) ? RequiredClassifierType.CLASS : 
        RequiredClassifierType.NONE;
      resolve(eModelElement, ecoreEGenericType, requiredClassifierType);
      if (javaEGenericType != null) {
        resolve(eModelElement, javaEGenericType, requiredClassifierType);
      }
      if (javaEGenericType != null) {
        resolve(eModelElement, ecoreEGenericType, javaEGenericType);
      }
    }
    for (Map.Entry<EGenericType, EGenericType> entry : ecoreEGenericTypeToJavaEGenericTypeMap.entrySet())
    {
      EGenericType ecoreEGenericType = (EGenericType)entry.getKey();
      EGenericType javaEGenericType = (EGenericType)entry.getValue();
      EModelElement eModelElement = null;
      for (EObject eObject = ecoreEGenericType.eContainer(); eObject != null; eObject = eObject.eContainer()) {
        if ((eObject instanceof EModelElement))
        {
          eModelElement = (EModelElement)eObject;
          break;
        }
      }
      if (javaEGenericType == null) {
        resolve(eModelElement, ecoreEGenericType, javaEGenericType);
      }
      used(ecoreEGenericType);
    }
    for (EStructuralFeature eStructuralFeature : eStructuralFeatures)
    {
      EGenericType eGenericType = eStructuralFeature.getEGenericType();
      EClassifier eClassifier = eGenericType.getERawType();
      if (((eClassifier instanceof EClass)) && ((eStructuralFeature instanceof EAttribute)))
      {
        EAttribute eAttribute = (EAttribute)eStructuralFeature;
        EClass container = eAttribute.getEContainingClass();
        EReference eReference = EcoreFactory.eINSTANCE.createEReference();
        eReference.setChangeable(eAttribute.isChangeable());
        eReference.setVolatile(eAttribute.isVolatile());
        eReference.setTransient(eAttribute.isTransient());
        eReference.setDerived(eAttribute.isDerived());
        eReference.setUnsettable(eAttribute.isUnsettable());
        eReference.setLowerBound(eAttribute.getLowerBound());
        eReference.setUpperBound(eAttribute.getUpperBound());
        eReference.setName(eStructuralFeature.getName());
        eReference.setEGenericType(eGenericType);
        eReference.getEAnnotations().addAll(eStructuralFeature.getEAnnotations());
        container.getEStructuralFeatures().add(container.getEStructuralFeatures().indexOf(eStructuralFeature), eReference);
        container.getEStructuralFeatures().remove(eStructuralFeature);
        eStructuralFeature = eReference;
      }
      else if (((eClassifier instanceof EDataType)) && ((eStructuralFeature instanceof EReference)))
      {
        EReference eReference = (EReference)eStructuralFeature;
        EClass container = eReference.getEContainingClass();
        EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
        eAttribute.setChangeable(eReference.isChangeable());
        eAttribute.setVolatile(eReference.isVolatile());
        eAttribute.setTransient(eReference.isTransient());
        eAttribute.setDerived(eReference.isDerived());
        eAttribute.setUnsettable(eReference.isUnsettable());
        eAttribute.setLowerBound(eReference.getLowerBound());
        eAttribute.setUpperBound(eReference.getUpperBound());
        eAttribute.setName(eStructuralFeature.getName());
        eAttribute.setEGenericType(eGenericType);
        eAttribute.getEAnnotations().addAll(eStructuralFeature.getEAnnotations());
        container.getEStructuralFeatures().remove(eStructuralFeature);
        eStructuralFeature = eAttribute;
        eReferenceToOppositeNameMap.remove(eReference);
      }
      if (eClassifier.getEPackage() == null)
      {
        error(CodeGenEcorePlugin.INSTANCE.getString("_UI_TheTypeDoesNotResolveCorrectly_message", new Object[] { eClassifier.getInstanceTypeName() }));
        
        eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
        eGenericType.setEClassifier((eClassifier instanceof EClass) ? EcorePackage.Literals.EOBJECT : EcorePackage.Literals.EJAVA_OBJECT);
      }
    }
    EReference eOpposite;
    for (Map.Entry<EReference, String> entry : eReferenceToOppositeNameMap.entrySet())
    {
      EReference eReference = (EReference)entry.getKey();
      String oppositeName = (String)entry.getValue();
      EClass eClass = (EClass)eReference.getEType();
      
      eOpposite = (EReference)eClass.getEStructuralFeature(oppositeName);
      if (eOpposite == null)
      {
        error(CodeGenEcorePlugin.INSTANCE.getString("_UI_TheAttributeIsNotAMemberOf_message", new Object[] { oppositeName, eClass.getName() }));
      }
      else if ((eOpposite.getEOpposite() != eReference) && (eOpposite.getEOpposite() != null))
      {
        error(
          CodeGenEcorePlugin.INSTANCE.getString(
          "_UI_TheOppositeAlreadyHasOpposite_message", 
          new Object[] { oppositeName, eOpposite.getEOpposite().getName(), eOpposite.getEOpposite().getEContainingClass().getName() }));
      }
      else
      {
        eReference.setEOpposite(eOpposite);
        eOpposite.setEOpposite(eReference);
        
        used(eOpposite);
        if ((eOpposite.isContainment()) && (!transientEReferenceWithOpposite.contains(eReference))) {
          eReference.setTransient(true);
        }
      }
    }
    for (??? = eReferenceToKeyNamesMap.entrySet().iterator(); ???.hasNext(); eOpposite.hasNext())
    {
      Map.Entry<EReference, List<String>> entry = (Map.Entry)???.next();
      
      EReference eReference = (EReference)entry.getKey();
      EClass eClass = (EClass)eReference.getEType();
      eOpposite = ((List)entry.getValue()).iterator(); continue;String keyName = (String)eOpposite.next();
      
      EStructuralFeature eKey = eClass.getEStructuralFeature(keyName);
      if (eKey == null)
      {
        error(CodeGenEcorePlugin.INSTANCE.getString("_UI_TheAttributeIsNotAMemberOf_message", new Object[] { keyName, eClass.getName() }));
      }
      else if ((eKey instanceof EAttribute))
      {
        eReference.getEKeys().add((EAttribute)eKey);
        used(eKey);
      }
    }
    for (EPackage ePackage : packageNameToEPackageMap.values())
    {
      EAnnotation eAnnotation = ePackage.getEAnnotation("http://www.eclipse.org/emf/2002/Ecore#MapEntryClassContainer");
      if (eAnnotation != null) {
        EcoreUtil.remove(eAnnotation);
      }
    }
    for (??? = ePackageToOrderingMap.entrySet().iterator(); ???.hasNext(); eOpposite.hasNext())
    {
      Map.Entry<EPackage, Map<Object, Integer>> entry = (Map.Entry)???.next();
      
      EPackage ePackage = (EPackage)entry.getKey();
      Map<Object, Integer> nameToIDMap = (Map)entry.getValue();
      
      sort(ePackage.getEClassifiers(), nameToIDMap);
      eOpposite = ePackage.getEClassifiers().iterator(); continue;EClassifier eClassifier = (EClassifier)eOpposite.next();
      if ((eClassifier instanceof EClass))
      {
        EClass eClass = (EClass)eClassifier;
        sort(eClass.getEStructuralFeatures(), nameToIDMap);
      }
    }
    IPath targetFragmentRoot = project.getFullPath();
    for (int i = 0; i < packageFragmentRoots.length; i++) {
      if (packageFragmentRoots[i].getKind() == 1)
      {
        IPath path = packageFragmentRoots[i].getUnderlyingResource().getFullPath();
        if (targetFragmentRoot.isPrefixOf(path))
        {
          targetFragmentRoot = path;
          break;
        }
      }
    }
    facadeHelper.reset();
    return targetFragmentRoot;
  }
  
  public void computeEPackages(Monitor monitor, ModelImporter modelImporter)
    throws Exception
  {
    IProject project = genModelFile.getProject();
    project.open(BasicMonitor.toIProgressMonitor(monitor));
    if ((!project.hasNature("org.eclipse.jdt.core.javanature")) && (oldGenModelVersion.getModelDirectory() != null)) {
      project = project.getWorkspace().getRoot().getFolder(new Path(oldGenModelVersion.getModelDirectory())).getProject();
    }
    Collection<IFile> allGenModelFiles = new ArrayList();
    Collection<IProject> allReferencedProjects = new ArrayList();
    getAllReferencedProjects(allReferencedProjects, project.getDescription().getReferencedProjects());
    getAllReferencedProjects(allReferencedProjects, project.getDescription().getDynamicReferences());
    for (IProject referencedProject : allReferencedProjects) {
      getAllGenModelFiles(allGenModelFiles, referencedProject);
    }
    ResourceSet resourceSet = modelImporter.createResourceSet();
    Resource resource;
    Iterator localIterator3;
    for (Iterator localIterator2 = allGenModelFiles.iterator(); localIterator2.hasNext(); localIterator3.hasNext())
    {
      IFile file = (IFile)localIterator2.next();
      
      resource = resourceSet.getResource(modelImporter.createFileURI(file.getFullPath().toString()), true);
      GenModel genModel = (GenModel)resource.getContents().get(0);
      externalGenModels.add(genModel);
      localIterator3 = genModel.getGenPackages().iterator(); continue;GenPackage genPackage = (GenPackage)localIterator3.next();
      
      determineExternalPackages(genPackage, modelImporter);
    }
    Object allReferencedPluginIDs = new UniqueEList();
    allReferencedProjects.add(project);
    String pluginID;
    for (IProject referencedProject : allReferencedProjects) {
      try
      {
        URI manifestURI = URI.createURI(referencedProject.getFullPath() + "/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(resourceSet.getURIConverter().createInputStream(manifestURI));
        String requires = manifest.getMainAttributes().getValue("Require-Bundle");
        if (requires != null)
        {
          ManifestElement[] elements = ManifestElement.parseHeader("Require-Bundle", requires);
          for (int j = 0; j < elements.length; j++)
          {
            ManifestElement element = elements[j];
            if ((project == referencedProject) || ("reexport".equals(element.getDirective("visibility"))))
            {
              pluginID = element.getValue();
              ((List)allReferencedPluginIDs).add(pluginID);
            }
          }
        }
      }
      catch (IOException localIOException) {}
    }
    for (int i = 0; i < ((List)allReferencedPluginIDs).size(); i++)
    {
      String pluginID = (String)((List)allReferencedPluginIDs).get(i);
      bundle = Platform.getBundle(pluginID);
      if (bundle != null)
      {
        String requires = (String)bundle.getHeaders().get("Require-Bundle");
        if (requires != null)
        {
          ManifestElement[] elements = ManifestElement.parseHeader("Require-Bundle", requires);
          for (int j = 0; j < elements.length; j++)
          {
            ManifestElement element = elements[j];
            String value = element.getValue();
            if ("reexport".equals(element.getDirective("visibility"))) {
              ((List)allReferencedPluginIDs).add(value);
            }
          }
        }
      }
    }
    Object allPluginsWithGenModels = new HashMap();
    Object uris;
    for (Map.Entry<String, URI> entry : EcorePlugin.getEPackageNsURIToGenModelLocationMap().entrySet())
    {
      URI genModelLocation = (URI)entry.getValue();
      if (genModelLocation.isPlatformPlugin())
      {
        uris = (List)((Map)allPluginsWithGenModels).get(genModelLocation.segment(1));
        if (uris == null) {
          uris = new UniqueEList();
        }
        ((List)uris).add(genModelLocation);
        ((Map)allPluginsWithGenModels).put(genModelLocation.segment(1), uris);
      }
    }
    ((List)allReferencedPluginIDs).retainAll(((Map)allPluginsWithGenModels).keySet());
    URI uri;
    GenModel genModel;
    for (Bundle bundle = ((List)allReferencedPluginIDs).iterator(); bundle.hasNext(); ((Iterator)uris).hasNext())
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd