Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2006 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM - Initial API and implementation
 
 package org.eclipse.emf.java.util;
 
 
 import java.util.List;
 import java.util.Map;
 
 
 public class JavaPackageResourceImpl extends ResourceImpl 
 {
   public JavaPackageResourceImpl(URI uri)
   {
     super(uri);
 
     // The no-name compilation unit
     //
     jCompilationUnit.setName(".class");
     getContents().add(jCompilationUnit);
   }
 
   @Override
   protected void doLoad(InputStream inputStreamMap<?, ?> optionsthrows IOException
   {
     // Ignore
   }
 
   @Override
   protected void doSave(OutputStream outputStreamMap<?, ?> optionsthrows IOException
   {
     throw new UnsupportedOperationException();
   }
 
   @Override
   public EObject getEObject(String uriFragment)
   {
     return super.getEObject(uriFragment);
   }
 
   @Override
   protected EObject getEObjectForURIFragmentRootSegment(String uriFragmentRootSegment)
   {
     for (Object object : getContents())
     {
       if (object instanceof JPackage)
       {
         JPackage jPackage = (JPackage)object;
         if (uriFragmentRootSegment.equals(jPackage.getName()))
         {
           return jPackage;
         }
       }
     }
 
     return null;
   }
 
   @Override
   protected EObject getEObject(List<StringuriFragmentPath)
   {
     Iterator<Stringfragments = uriFragmentPath.iterator(); 
     String packageName = !fragments.hasNext() ? "" : (String)fragments.next();
 
     EObject eObject = getEObjectForURIFragmentRootSegment(packageName);
     if (fragments.hasNext())
     {
       JPackage jPackage = (JPackage)eObject;
       String typeName = fragments.next();
       if (eObject == null || (eObject = ((InternalEObject)eObject).eObjectForURIFragmentSegment(typeName)) == null)
       {
         JClass jClass = demandLoad(packageNametypeName);
         if (jClass != null)
         {
           if (jClass.getUnit() == null)
          {
            ((JCompilationUnit)getContents().get(0)).getTypes().add(jClass);
          }
          if (jPackage == null)
          {
            jPackage = ..createJPackage();
            jPackage.setName(packageName);
            getContents().add(jPackage);
          }
          jPackage.getTypes().add(jClass);
          eObject = jClass;
        }
      }
      while (fragments.hasNext() && eObject != null)
      {
        eObject = ((InternalEObject)eObject).eObjectForURIFragmentSegment(fragments.next());
      }
    }
    else if (eObject == null)
    {
      JPackage jPackage = ..createJPackage();
      jPackage.setName(packageName);
      getContents().add(jPackage);
      eObject = jPackage;
    }
    return eObject;
  }
  protected JClass demandLoad(String packageNameString typeName)
  {
    int index = typeName.indexOf("["); 
    String className;
    if (index == -1)
    {
      className = packageName.length() == 0 ? typeName : packageName + "." + typeName;
    }
    else
    {
      int dimensions = (typeName.length() - index) / 2;
      typeName = typeName.substring(0, index);
      if ("java.lang".equals(packageName))
      {
        if (typeName.equals("int"))
        {
          className = "I";
        }
        else if (typeName.equals("boolean"))
        {
          className = "B";
        }
        else if (typeName.equals("char"))
        {
          className = "C";
        }
        else if (typeName.equals("double"))
        {
          className = "D";
        }
        else if (typeName.equals("float"))
        {
          className = "F";
        }
        else if (typeName.equals("byte"))
        {
          className = "B";
        }
        else if (typeName.equals("short"))
        {
          className = "S";
        }
        else if (typeName.equals("long"))
        {
          className = "J";
        }
        else
        {
          className = "Ljava.lang." + typeName + ";";
        }
      }
      else
      {
        className = "L" + (packageName.length() == 0 ? typeName + ";" :  packageName + "." + typeName + ";");
      }
      while (--dimensions >= 0)
      {
        className = "[" + className;
      }
    }
    try
    {
      Class<?> theClass = null;
      if ("java.lang".equals(packageName) && index == -1)
      {
        if (typeName.equals("int"))
        {
          theClass = .;
        }
        else if (typeName.equals("boolean"))
        {
          theClass = .;
        }
        else if (typeName.equals("char"))
        {
          theClass = .;
        }
        else if (typeName.equals("double"))
        {
          theClass = .;
        }
        else if (typeName.equals("float"))
        {
          theClass = .;
        }
        else if (typeName.equals("byte"))
        {
          theClass = .;
        }
        else if (typeName.equals("short"))
        {
          theClass = .;
        }
        else if (typeName.equals("long"))
        {
          theClass = .;
        }
        else if (typeName.equals("void"))
        {
          theClass = .;
        }
        else
        {
          theClass = getClassLoader().loadClass(className);
        }
      }
      else
      {
        theClass = getClassLoader().loadClass(className);
      }
      JClass jClass = ..createJClass();
      jClass.setJavaClass(theClass);
      return jClass;
    }
    catch (ClassNotFoundException exception)
    {
      // Ignore
    }
    for (String sourceURI : getSourceURIs())
    {
      URI resolvedSourceURI = 
        URI.createURI
          (sourceURI.toString() + (packageName.length() == 0 ? "" : packageName.replace('.','/') + '/')  + typeName + ".java");
      try
      {
        InputStream inputStream = .getURIConverter().createInputStream(resolvedSourceURI);
        inputStream.close();
        JClass jClass = (JClass).getEObject(JavaUtil.createJClassProxyURI(resolvedSourceURI), true);
        return jClass;
      }
      catch (IOException exception)
      {
        // Ignore
      }
    }
    return null;
  }
  protected ClassLoader classLoader;
  {
    if ( ==  null)
    {
      try
      {
         = 
          new java.net.URLClassLoader
            (new java.net.URL [] 
             { 
             }, 
             null);
      }
      catch (Exception exception)
      {
        exception.printStackTrace();
      }
    }
    return ;
  }
  public void setClassLoader(ClassLoader classLoader)
  {
    this. = classLoader;
  }
  protected List<StringsourceURIs = new ArrayList<String>();
  public List<StringgetSourceURIs()
  {
    return ;
  }
New to GrepCode? Check out our FAQ X