org.eclipse.pde.api.tools_1.0.301.v20111129-2053

 //   230: pop
    //   231: aload 6
    //   233: athrow
    //   234: aload 4
    //   236: ifnull +12 -> 248
    //   239: aload 4
    //   241: invokevirtual 1614	java/io/BufferedOutputStream:close	()V
    //   244: goto +4 -> 248
    //   247: pop
    //   248: iconst_1
    //   249: ireturn
    //   250: iconst_0
    //   251: ireturn
    // Line number table:
    //   Java source line #406	-> byte code offset #0
    //   Java source line #407	-> byte code offset #5
    //   Java source line #409	-> byte code offset #7
    //   Java source line #410	-> byte code offset #23
    //   Java source line #411	-> byte code offset #32
    //   Java source line #412	-> byte code offset #34
    //   Java source line #416	-> byte code offset #39
    //   Java source line #418	-> byte code offset #43
    //   Java source line #419	-> byte code offset #50
    //   Java source line #420	-> byte code offset #52
    //   Java source line #413	-> byte code offset #60
    //   Java source line #414	-> byte code offset #62
    //   Java source line #416	-> byte code offset #67
    //   Java source line #418	-> byte code offset #71
    //   Java source line #419	-> byte code offset #78
    //   Java source line #420	-> byte code offset #80
    //   Java source line #415	-> byte code offset #88
    //   Java source line #416	-> byte code offset #90
    //   Java source line #418	-> byte code offset #94
    //   Java source line #419	-> byte code offset #101
    //   Java source line #420	-> byte code offset #103
    //   Java source line #423	-> byte code offset #108
    //   Java source line #416	-> byte code offset #111
    //   Java source line #418	-> byte code offset #115
    //   Java source line #419	-> byte code offset #122
    //   Java source line #420	-> byte code offset #124
    //   Java source line #424	-> byte code offset #129
    //   Java source line #425	-> byte code offset #133
    //   Java source line #427	-> byte code offset #136
    //   Java source line #428	-> byte code offset #153
    //   Java source line #429	-> byte code offset #159
    //   Java source line #430	-> byte code offset #167
    //   Java source line #431	-> byte code offset #169
    //   Java source line #435	-> byte code offset #174
    //   Java source line #437	-> byte code offset #179
    //   Java source line #438	-> byte code offset #187
    //   Java source line #432	-> byte code offset #191
    //   Java source line #433	-> byte code offset #193
    //   Java source line #435	-> byte code offset #198
    //   Java source line #437	-> byte code offset #203
    //   Java source line #438	-> byte code offset #211
    //   Java source line #434	-> byte code offset #215
    //   Java source line #435	-> byte code offset #217
    //   Java source line #437	-> byte code offset #222
    //   Java source line #438	-> byte code offset #230
    //   Java source line #442	-> byte code offset #231
    //   Java source line #435	-> byte code offset #234
    //   Java source line #437	-> byte code offset #239
    //   Java source line #438	-> byte code offset #247
    //   Java source line #443	-> byte code offset #248
    //   Java source line #445	-> byte code offset #250
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	252	0	file	File
    //   0	252	1	newFile	File
    //   4	152	2	bytes	byte[]
    //   6	110	3	inputStream	BufferedInputStream
    //   32	3	4	e	java.io.FileNotFoundException
    //   60	3	4	e	IOException
    //   134	106	4	outputStream	BufferedOutputStream
    //   88	21	5	localObject	Object
    //   167	3	5	e	java.io.FileNotFoundException
    //   191	3	5	e	IOException
    //   50	3	6	e	IOException
    //   78	3	6	e	IOException
    //   101	3	6	e	IOException
    //   122	110	6	e	IOException
    //   187	1	14	localIOException1	IOException
    //   211	1	15	localIOException2	IOException
    //   230	1	16	localIOException3	IOException
    //   247	1	17	localIOException4	IOException
    // Exception table:
    //   from	to	target	type
    //   7	29	32	java/io/FileNotFoundException
    //   43	47	50	java/io/IOException
    //   7	29	60	java/io/IOException
    //   71	75	78	java/io/IOException
    //   7	39	88	finally
    //   60	67	88	finally
    //   94	98	101	java/io/IOException
    //   115	119	122	java/io/IOException
    //   136	164	167	java/io/FileNotFoundException
    //   179	184	187	java/io/IOException
    //   136	164	191	java/io/IOException
    //   203	208	211	java/io/IOException
    //   136	174	215	finally
    //   191	198	215	finally
    //   222	227	230	java/io/IOException
    //   239	244	247	java/io/IOException
  }
  
  /* Error */
  public static File createEEFile(IVMInstall jre, String eeid)
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: aload_1
    //   2: invokestatic 1809	org/eclipse/pde/api/tools/internal/util/Util:generateEEContents	(Lorg/eclipse/jdt/launching/IVMInstall;Ljava/lang/String;)Ljava/lang/String;
    //   5: astore_2
    //   6: ldc_w 946
    //   9: ldc_w 822
    //   12: invokestatic 1806	org/eclipse/pde/api/tools/internal/util/Util:createTempFile	(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;
    //   15: astore_3
    //   16: aconst_null
    //   17: astore 4
    //   19: new 985	java/io/FileOutputStream
    //   22: dup
    //   23: aload_3
    //   24: invokespecial 1647	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   27: astore 4
    //   29: aload 4
    //   31: aload_2
    //   32: ldc_w 927
    //   35: invokevirtual 1689	java/lang/String:getBytes	(Ljava/lang/String;)[B
    //   38: invokevirtual 1646	java/io/FileOutputStream:write	([B)V
    //   41: goto +18 -> 59
    //   44: astore 5
    //   46: aload 4
    //   48: ifnull +8 -> 56
    //   51: aload 4
    //   53: invokevirtual 1645	java/io/FileOutputStream:close	()V
    //   56: aload 5
    //   58: athrow
    //   59: aload 4
    //   61: ifnull +8 -> 69
    //   64: aload 4
    //   66: invokevirtual 1645	java/io/FileOutputStream:close	()V
    //   69: aload_3
    //   70: areturn
    // Line number table:
    //   Java source line #456	-> byte code offset #0
    //   Java source line #457	-> byte code offset #6
    //   Java source line #458	-> byte code offset #16
    //   Java source line #460	-> byte code offset #19
    //   Java source line #461	-> byte code offset #29
    //   Java source line #462	-> byte code offset #44
    //   Java source line #463	-> byte code offset #46
    //   Java source line #464	-> byte code offset #51
    //   Java source line #466	-> byte code offset #56
    //   Java source line #463	-> byte code offset #59
    //   Java source line #464	-> byte code offset #64
    //   Java source line #467	-> byte code offset #69
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	71	0	jre	IVMInstall
    //   0	71	1	eeid	String
    //   5	27	2	string	String
    //   15	55	3	eeFile	File
    //   17	48	4	outputStream	FileOutputStream
    //   44	13	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   19	44	44	finally
  }
  
  public static boolean equalsOrNull(Object o1, Object o2)
  {
    if (o1 == null) {
      return o2 == null;
    }
    return o1.equals(o2);
  }
  
  public static String generateEEContents(IVMInstall vm, String eeId)
    throws IOException
  {
    StringBuffer buffer = new StringBuffer();
    appendProperty(buffer, "-Djava.home", vm.getInstallLocation().getCanonicalPath());
    StringBuffer paths = new StringBuffer();
    LibraryLocation[] libraryLocations = JavaRuntime.getLibraryLocations(vm);
    for (int i = 0; i < libraryLocations.length; i++)
    {
      LibraryLocation lib = libraryLocations[i];
      paths.append(lib.getSystemLibraryPath().toOSString());
      if (i < libraryLocations.length - 1) {
        paths.append(File.pathSeparatorChar);
      }
    }
    appendProperty(buffer, "-Dee.bootclasspath", paths.toString());
    appendProperty(buffer, "-Dee.class.library.level", eeId);
    return buffer.toString();
  }
  
  public static File[] getAllFiles(File root, FileFilter fileFilter)
  {
    ArrayList files = new ArrayList();
    if (root.isDirectory())
    {
      collectAllFiles(root, files, fileFilter);
      File[] result = new File[files.size()];
      files.toArray(result);
      return result;
    }
    return null;
  }
  
  public static Job getBuildJob(IProject[] projects)
  {
    Assert.isNotNull(projects);
    Job buildJob = new BuildJob(UtilMessages.Util_4, projects);
    buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
    buildJob.setUser(true);
    return buildJob;
  }
  
  public static Job getBuildJob(IProject[] projects, int buildKind)
  {
    Assert.isNotNull(projects);
    Job buildJob = new BuildJob(UtilMessages.Util_4, projects, buildKind);
    buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
    buildJob.setUser(true);
    return buildJob;
  }
  
  public static IApiTypeRoot getClassFile(IApiComponent[] components, String typeName)
  {
    if (components == null) {
      return null;
    }
    int i = 0;
    for (int max = components.length; i < max; i++)
    {
      IApiComponent apiComponent = components[i];
      if (apiComponent != null) {
        try
        {
          IApiTypeRoot classFile = apiComponent.findTypeRoot(typeName);
          if (classFile != null) {
            return classFile;
          }
        }
        catch (CoreException localCoreException) {}
      }
    }
    return null;
  }
  
  public static String getDeltaElementType(IDelta delta)
  {
    return getDeltaElementType(delta.getElementType());
  }
  
  public static String getSeverity(int severity)
  {
    switch (severity)
    {
    case 2: 
      return "ERROR";
    case 0: 
      return "INFO";
    case 1: 
      return "WARNING";
    }
    return "UNKNOWN_SEVERITY";
  }
  
  public static int getDeltaElementTypeValue(String elementType)
  {
    Class IDeltaClass = IDelta.class;
    try
    {
      Field field = IDeltaClass.getField(elementType);
      return field.getInt(null);
    }
    catch (SecurityException localSecurityException) {}catch (IllegalArgumentException localIllegalArgumentException) {}catch (NoSuchFieldException localNoSuchFieldException) {}catch (IllegalAccessException localIllegalAccessException) {}
    return -1;
  }
  
  public static String getDeltaElementType(int elementType)
  {
    switch (elementType)
    {
    case 1: 
      return "ANNOTATION_ELEMENT_TYPE";
    case 8: 
      return "INTERFACE_ELEMENT_TYPE";
    case 6: 
      return "ENUM_ELEMENT_TYPE";
    case 2: 
      return "API_COMPONENT_ELEMENT_TYPE";
    case 3: 
      return "API_BASELINE_ELEMENT_TYPE";
    case 5: 
      return "CONSTRUCTOR_ELEMENT_TYPE";
    case 9: 
      return "METHOD_ELEMENT_TYPE";
    case 7: 
      return "FIELD_ELEMENT_TYPE";
    case 4: 
      return "CLASS_ELEMENT_TYPE";
    case 10: 
      return "TYPE_PARAMETER_ELEMENT_TYPE";
    }
    return "UNKNOWN_ELEMENT_KIND";
  }
  
  public static String getDeltaFlagsName(int flags)
  {
    switch (flags)
    {
    case 1: 
      return "ABSTRACT_TO_NON_ABSTRACT";
    case 2: 
      return "ANNOTATION_DEFAULT_VALUE";
    case 3: 
      return "API_COMPONENT";
    case 4: 
      return "ARRAY_TO_VARARGS";
    case 5: 
      return "CHECKED_EXCEPTION";
    case 6: 
      return "CLASS_BOUND";
    case 7: 
      return "CLINIT";
    case 8: 
      return "CONSTRUCTOR";
    case 10: 
      return "CONTRACTED_SUPERINTERFACES_SET";
    case 11: 
      return "DECREASE_ACCESS";
    case 12: 
      return "ENUM_CONSTANT";
    case 13: 
      return "EXECUTION_ENVIRONMENT";
    case 15: 
      return "EXPANDED_SUPERINTERFACES_SET";
    case 16: 
      return "FIELD";
    case 17: 
      return "FIELD_MOVED_UP";
    case 18: 
      return "FINAL_TO_NON_FINAL";
    case 19: 
      return "FINAL_TO_NON_FINAL_NON_STATIC";
    case 20: 
      return "FINAL_TO_NON_FINAL_STATIC_CONSTANT";
    case 21: 
      return "FINAL_TO_NON_FINAL_STATIC_NON_CONSTANT";
    case 22: 
      return "INCREASE_ACCESS";
    case 23: 
      return "INTERFACE_BOUND";
    case 25: 
      return "METHOD";
    case 26: 
      return "METHOD_MOVED_UP";
    case 27: 
      return "METHOD_WITH_DEFAULT_VALUE";
    case 28: 
      return "METHOD_WITHOUT_DEFAULT_VALUE";
    case 29: 
      return "NATIVE_TO_NON_NATIVE";
    case 30: 
      return "NON_ABSTRACT_TO_ABSTRACT";
    case 31: 
      return "NON_FINAL_TO_FINAL";
    case 32: 
      return "NON_NATIVE_TO_NATIVE";
    case 33: 
      return "NON_STATIC_TO_STATIC";
    case 34: 
      return "NON_SYNCHRONIZED_TO_SYNCHRONIZED";
    case 35: 
      return "NON_TRANSIENT_TO_TRANSIENT";
    case 36: 
      return "OVERRIDEN_METHOD";
    case 38: 
      return "STATIC_TO_NON_STATIC";
    case 39: 
      return "SUPERCLASS";
    case 40: 
      return "SYNCHRONIZED_TO_NON_SYNCHRONIZED";
    case 41: 
      return "TYPE_CONVERSION";
    case 45: 
      return "TRANSIENT_TO_NON_TRANSIENT";
    case 46: 
      return "TYPE";
    case 47: 
      return "TYPE_ARGUMENTS";
    case 48: 
      return "TYPE_MEMBER";
    case 49: 
      return "TYPE_PARAMETER";
    case 50: 
      return "TYPE_PARAMETER_NAME";
    case 51: 
      return "TYPE_PARAMETERS";
    case 52: 
      return "TYPE_VISIBILITY";
    case 53: 
      return "UNCHECKED_EXCEPTION";
    case 54: 
      return "VALUE";
    case 55: 
      return "VARARGS_TO_ARRAY";
    case 37: 
      return "RESTRICTIONS";
    case 56: 
      return "API_TYPE";
    case 57: 
      return "NON_VOLATILE_TO_VOLATILE";
    case 58: 
      return "VOLATILE_TO_NON_VOLATILE";
    case 60: 
      return "MINOR_VERSION";
    case 59: 
      return "MAJOR_VERSION";
    case 61: 
      return "API_FIELD";
    case 62: 
      return "API_METHOD";
    case 63: 
      return "API_CONSTRUCTOR";
    case 64: 
      return "API_ENUM_CONSTANT";
    case 65: 
      return "API_METHOD_WITH_DEFAULT_VALUE";
    case 66: 
      return "API_METHOD_WITHOUT_DEFAULT_VALUE";
    case 68: 
      return "TYPE_ARGUMENT";
    case 69: 
      return "SUPER_INTERFACE_WITH_METHODS";
    case 71: 
      return "REEXPORTED_API_TYPE";
    case 70: 
      return "REEXPORTED_TYPE";
    case 67: 
      return "METHOD_MOVED_DOWN";
    case 72: 
      return "DEPRECATION";
    }
    return "UNKNOWN_FLAGS";
  }
  
  public static String getDeltaKindName(IDelta delta)
  {
    return getDeltaKindName(delta.getKind());
  }
  
  public static String getDeltaKindName(int kind)
  {
    switch (kind)
    {
    case 1: 
      return "ADDED";
    case 2: 
      return "CHANGED";
    case 3: 
      return "REMOVED";
    }
    return "UNKNOWN_KIND";
  }
  
  public static String getDeltaPrefererenceKey(int elementType, int kind, int flags)
  {
    StringBuffer buffer = new StringBuffer(getDeltaElementType(elementType));
    buffer.append('_').append(getDeltaKindName(kind));
    if (flags != -1)
    {
      buffer.append('_');
      switch (flags)
      {
      case 61: 
        buffer.append(getDeltaFlagsName(16));
        break;
      case 64: 
        buffer.append(getDeltaFlagsName(12));
        break;
      case 63: 
        buffer.append(getDeltaFlagsName(8));
        break;
      case 62: 
        buffer.append(getDeltaFlagsName(25));
        break;
      case 65: 
        if (kind == 3) {
          buffer.append(getDeltaFlagsName(25));
        } else {
          buffer.append(getDeltaFlagsName(27));
        }
        break;
      case 66: 
        if (kind == 3) {
          buffer.append(getDeltaFlagsName(25));
        } else {
          buffer.append(getDeltaFlagsName(28));
        }
        break;
      case 27: 
        if (kind == 3) {
          buffer.append(getDeltaFlagsName(25));
        } else {
          buffer.append(getDeltaFlagsName(27));
        }
        break;
      case 28: 
        if (kind == 3) {
          buffer.append(getDeltaFlagsName(25));
        } else {
          buffer.append(getDeltaFlagsName(28));
        }
        break;
      default: 
        buffer.append(getDeltaFlagsName(flags));
      }
    }
    return String.valueOf(buffer);
  }
  
  public static String getDetail(IDelta delta)
  {
    StringBuffer buffer = new StringBuffer();
    switch (delta.getElementType())
    {
    case 4: 
      buffer.append("class");
      break;
    case 1: 
      buffer.append("annotation");
      break;
    case 8: 
      buffer.append("interface");
      break;
    case 2: 
      buffer.append("api component");
      break;
    case 3: 
      buffer.append("api baseline");
      break;
    case 9: 
      buffer.append("method");
      break;
    case 5: 
      buffer.append("constructor");
      break;
    case 6: 
      buffer.append("enum");
      break;
    case 7: 
      buffer.append("field");
    }
    buffer.append(' ');
    switch (delta.getKind())
    {
    case 1: 
      buffer.append("added");
      break;
    case 3: 
      buffer.append("removed");
      break;
    case 2: 
      buffer.append("changed");
      break;
    default: 
      buffer.append("unknown kind");
    }
    buffer.append(' ').append(getDeltaFlagsName(delta.getFlags())).append(' ').append(delta.getTypeName()).append("#").append(delta.getKey());
    return String.valueOf(buffer);
  }
  
  public static IDocument getDocument(ICompilationUnit cu)
    throws CoreException
  {
    if (cu.getOwner() == null)
    {
      IFile file = (IFile)cu.getResource();
      if (file.exists())
      {
        ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
        IPath path = cu.getPath();
        bufferManager.connect(path, LocationKind.IFILE, new NullProgressMonitor());
        try
        {
          return bufferManager.getTextFileBuffer(path, LocationKind.IFILE).getDocument();
        }
        finally
        {
          bufferManager.disconnect(path, LocationKind.IFILE, null);
        }
      }
    }
    return new org.eclipse.jface.text.Document(cu.getSource());
  }
  
  public static Properties getEEProfile(String eeId)
  {
    String profileName = eeId + ".profile";
    InputStream stream = Util.class.getResourceAsStream("profiles/" + profileName);
    if (stream != null) {
      try
      {
        Properties profile = new Properties();
        profile.load(stream);
        return profile;
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
      finally
      {
        try
        {
          stream.close();
        }
        catch (IOException e)
        {
          ApiPlugin.log(e);
        }
      }
    }
    return null;
  }
  
  public static final int getFragmentNumber(String version)
  {
    if (version == null) {
      throw new IllegalArgumentException("The given version should not be null");
    }
    int index = version.indexOf(' ');
    char[] charArray = version.toCharArray();
    int length = charArray.length;
    if (index + 1 >= length) {
      return -1;
    }
    int counter = 1;
    for (int i = index + 1; i < length; i++) {
      switch (charArray[i])
      {
      case '0': 
      case '1': 
      case '2': 
      case '3': 
      case '4': 
      case '5': 
      case '6': 
      case '7': 
      case '8': 
      case '9': 
        break;
      case '.': 
        counter++;
        break;
      case '/': 
      default: 
        return -1;
      }
    }
    return counter;
  }
  
  public static IMember getIMember(IDelta delta, IJavaProject javaProject)
  {
    String typeName = delta.getTypeName();
    if (typeName == null) {
      return null;
    }
    IType type = null;
    try
    {
      type = javaProject.findType(typeName.replace('$', '.'));
    }
    catch (JavaModelException localJavaModelException) {}
    if (type == null) {
      return null;
    }
    String key = delta.getKey();
    switch (delta.getElementType())
    {
    case 7: 
      IField field = type.getField(key);
      if (field.exists()) {
        return field;
      }
      break;
    case 1: 
    case 4: 
    case 6: 
    case 8: 
      switch (delta.getKind())
      {
      case 1: 
        switch (delta.getFlags())
        {
        case 12: 
        case 16: 
          IField field = type.getField(key);
          if (field.exists()) {
            return field;
          }
          break;
        case 8: 
        case 25: 
        case 27: 
        case 28: 
          return getMethod(type, key);
        case 48: 
          IType type2 = type.getType(key);
          if (type2.exists()) {
            return type2;
          }
          break;
        }
        break;
      case 3: 
        switch (delta.getFlags())
        {
        case 61: 
        case 64: 
          IField field = type.getField(key);
          if (field.exists()) {
            return field;
          }
          break;
        case 62: 
        case 63: 
        case 65: 
        case 66: 
          return getMethod(type, key);
        }
        break;
      }
      return type;
    case 5: 
    case 9: 
      return getMethod(type, key);
    case 2: 
      return type;
    }
    return null;
  }
  
  public static void updateMonitor(IProgressMonitor monitor, int work)
    throws OperationCanceledException
  {
    if (monitor == null) {
      return;
    }
    if (monitor.isCanceled()) {
      throw new OperationCanceledException();
    }
    monitor.worked(work);
  }
  
  public static void updateMonitor(IProgressMonitor monitor)
    throws OperationCanceledException
  {
    updateMonitor(monitor, 0);
  }
  
  private static IMember getMethod(IType type, String key)
  {
    boolean isGeneric = false;
    int indexOfTypeVariable = key.indexOf('<');
    int index = 0;
    if (indexOfTypeVariable == -1)
    {
      int indexOfParen = key.indexOf('(');
      if (indexOfParen == -1) {
        return null;
      }
      index = indexOfParen;
    }
    else
    {
      int indexOfParen = key.indexOf('(');
      if (indexOfParen == -1) {
        return null;
      }
      if (indexOfParen < indexOfTypeVariable)
      {
        index = indexOfParen;
      }
      else
      {
        index = indexOfTypeVariable;
        isGeneric = true;
      }
    }
    String selector = key.substring(0, index);
    String descriptor = key.substring(index, key.length());
    IMethod method = null;
    String signature = descriptor.replace('/', '.');
    String[] parameterTypes = (String[])null;
    if (isGeneric)
    {
      signature = signature.substring(signature.indexOf('('));
      parameterTypes = Signature.getParameterTypes(signature);
    }
    else
    {
      parameterTypes = Signature.getParameterTypes(signature);
    }
    try
    {
      method = type.getMethod(selector, parameterTypes);
    }
    catch (IllegalArgumentException e)
    {
      ApiPlugin.log(e);
    }
    if (method == null) {
      return null;
    }
    if (method.exists()) {
      return method;
    }
    if ((selector.equals(type.getElementName())) && (parameterTypes.length == 0)) {
      return null;
    }
    IMethod[] methods = (IMethod[])null;
    try
    {
      methods = type.getMethods();
    }
    catch (JavaModelException e)
    {
      ApiPlugin.log(e);
      
      ApiPlugin.log(
        new Status(4, 
        "org.eclipse.pde.api.tools", 
        NLS.bind(UtilMessages.Util_6, new String[] { selector, descriptor })));
      return null;
    }
    List list = new ArrayList();
    int i = 0;
    for (int max = methods.length; i < max; i++)
    {
      IMethod method2 = methods[i];
      if (selector.equals(method2.getElementName())) {
        list.add(method2);
      }
    }
    switch (list.size())
    {
    case 0: 
      ApiPlugin.log(
        new Status(4, 
        "org.eclipse.pde.api.tools", 
        NLS.bind(UtilMessages.Util_6, new String[] { selector, descriptor })));
      return null;
    case 1: 
      return (IMember)list.get(0);
    }
    for (Iterator iterator = list.iterator(); iterator.hasNext();)
    {
      IMethod method2 = (IMethod)iterator.next();
      try
      {
        if (Signatures.matchesSignatures(method2.getSignature(), signature)) {
          return method2;
        }
      }
      catch (JavaModelException localJavaModelException1) {}
    }
    ApiPlugin.log(
      new Status(4, 
      "org.eclipse.pde.api.tools", 
      NLS.bind(UtilMessages.Util_6, new String[] { selector, descriptor })));
    return null;
  }
  
  public static byte[] getInputStreamAsByteArray(InputStream stream, int length)
    throws IOException
  {
    byte[] contents;
    if (length == -1)
    {
      byte[] contents = new byte[0];
      int contentsLength = 0;
      int amountRead = -1;
      do
      {
        int amountRequested = Math.max(stream.available(), 8192);
        if (contentsLength + amountRequested > contents.length) {
          System.arraycopy(contents, 
            0, 
            contents = new byte[contentsLength + amountRequested], 
            0, 
            contentsLength);
        }
        amountRead = stream.read(contents, contentsLength, amountRequested);
        if (amountRead > 0) {
          contentsLength += amountRead;
        }
      } while (amountRead != -1);
      if (contentsLength < contents.length) {
        System.arraycopy(contents, 0, contents = new byte[contentsLength], 0, contentsLength);
      }
    }
    else
    {
      contents = new byte[length];
      int len = 0;
      int readSize = 0;
      while ((readSize != -1) && (len != length))
      {
        len += readSize;
        readSize = stream.read(contents, len, length - len);
      }
    }
    return contents;
  }
  
  public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding)
    throws IOException
  {
    Charset charset = null;
    try
    {
      charset = Charset.forName(encoding);
    }
    catch (IllegalCharsetNameException localIllegalCharsetNameException)
    {
      System.err.println("Illegal charset name : " + encoding);
      return null;
    }
    catch (UnsupportedCharsetException localUnsupportedCharsetException)
    {
      System.err.println("Unsupported charset : " + encoding);
      return null;
    }
    CharsetDecoder charsetDecoder = charset.newDecoder();
    
    charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
    byte[] contents = getInputStreamAsByteArray(stream, length);
    ByteBuffer byteBuffer = ByteBuffer.allocate(contents.length);
    byteBuffer.put(contents);
    byteBuffer.flip();
    CharBuffer charBuffer = charsetDecoder.decode(byteBuffer);
    charBuffer.compact();
    char[] array = charBuffer.array();
    int lengthToBe = charBuffer.position();
    if (array.length > lengthToBe) {
      System.arraycopy(array, 0, array = new char[lengthToBe], 0, lengthToBe);
    }
    return array;
  }
  
  public static IResource getManifestFile(IProject currentProject)
  {
    return currentProject.findMember("META-INF/MANIFEST.MF");
  }
  
  public static boolean isApiProblemMarker(IMarker marker)
  {
    return marker.getAttribute("apiMarkerID", -1) > 0;
  }
  
  public static IReferenceTypeDescriptor getType(String fullyQualifiedName)
  {
    int index = fullyQualifiedName.lastIndexOf('.');
    String pkg = index == -1 ? "" : fullyQualifiedName.substring(0, index);
    String type = index == -1 ? fullyQualifiedName : fullyQualifiedName.substring(index + 1);
    return Factory.packageDescriptor(pkg).getType(type);
  }
  
  public static boolean isApiProject(IProject project)
  {
    try
    {
      return project.hasNature("org.eclipse.pde.api.tools.apiAnalysisNature");
    }
    catch (CoreException localCoreException) {}
    return false;
  }
  
  public static boolean isJavaProject(IProject project)
  {
    try
    {
      return project.hasNature("org.eclipse.jdt.core.javanature");
    }
    catch (CoreException localCoreException) {}
    return false;
  }
  
  public static boolean isApiProject(IJavaProject project)
  {
    return isApiProject(project.getProject());
  }
  
  public static boolean isApiToolsComponent(IApiComponent apiComponent)
  {
    File file = new File(apiComponent.getLocation());
    if (file.exists())
    {
      if (file.isDirectory())
      {
        File apiDescription = new File(file, ".api_description");
        return apiDescription.exists();
      }
      ZipFile zipFile = null;
      try
      {
        zipFile = new ZipFile(file);
        return zipFile.getEntry(".api_description") != null;
      }
      catch (ZipException localZipException) {}catch (IOException localIOException3) {}finally
      {
        try
        {
          if (zipFile != null) {
            zipFile.close();
          }
        }
        catch (IOException localIOException5) {}
      }
    }
    return false;
  }
  
  public static boolean isArchive(String fileName)
  {
    return (isZipJarFile(fileName)) || (isTGZFile(fileName));
  }
  
  public static boolean isZipJarFile(String fileName)
  {
    String normalizedFileName = fileName.toLowerCase();
    
    return (normalizedFileName.endsWith(".zip")) || (normalizedFileName.endsWith(".jar"));
  }
  
  public static boolean isTGZFile(String fileName)
  {
    String normalizedFileName = fileName.toLowerCase();
    
    return (normalizedFileName.endsWith(".tar.gz")) || (normalizedFileName.endsWith(".tgz"));
  }
  
  public static boolean isClass(int accessFlags)
  {
    return (accessFlags & 0x6200) == 0;
  }
  
  public static boolean isClassFile(String fileName)
  {
    return fileName.toLowerCase().endsWith(".class");
  }
  
  public static boolean isDefault(int accessFlags)
  {
    return (accessFlags & 0x7) == 0;
  }
  
  public static final boolean isDifferentVersion(String versionToBeChecked, String referenceVersion)
  {
    SinceTagVersion sinceTagVersion1 = null;
    SinceTagVersion sinceTagVersion2 = null;
    try
    {
      sinceTagVersion1 = new SinceTagVersion(versionToBeChecked);
      sinceTagVersion2 = new SinceTagVersion(referenceVersion);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      return false;
    }
    Version version1 = sinceTagVersion1.getVersion();
    Version version2 = sinceTagVersion2.getVersion();
    if (version1.getMajor() != version2.getMajor()) {
      return true;
    }
    if (version1.getMinor() != version2.getMinor()) {
      return true;
    }
    if (version1.getMicro() != version2.getMicro()) {
      return true;
    }
    return false;
  }
  
  public static boolean isJavaFileName(String fileName)
  {
    return fileName.toLowerCase().endsWith(".java");
  }
  
  public static boolean isJavaLangObject(String name)
  {
    return (name != null) && (name.equals("java.lang.Object"));
  }
  
  public static boolean isJavaLangRuntimeException(String name)
  {
    return (name != null) && (name.equals("java.lang.RuntimeException"));
  }
  
  public static boolean isVisible(int modifiers)
  {
    return (Flags.isProtected(modifiers)) || (Flags.isPublic(modifiers));
  }
  
  public static boolean isBinaryProject(IProject project)
  {
    return WorkspaceModelManager.isBinaryProject(project);
  }
  
  public static org.w3c.dom.Document newDocument()
    throws CoreException
  {
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = null;
    try
    {
      docBuilder = dfactory.newDocumentBuilder();
    }
    catch (ParserConfigurationException e)
    {
      abort("Unable to create new XML document.", e);
    }
    org.w3c.dom.Document doc = docBuilder.newDocument();
    return doc;
  }
  
  /* Error */
  public static org.w3c.dom.Element parseDocument(String document)
    throws CoreException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aconst_null
    //   3: astore_2
    //   4: invokestatic 1742	javax/xml/parsers/DocumentBuilderFactory:newInstance	()Ljavax/xml/parsers/DocumentBuilderFactory;
    //   7: invokevirtual 1741	javax/xml/parsers/DocumentBuilderFactory:newDocumentBuilder	()Ljavax/xml/parsers/DocumentBuilder;
    //   10: astore_3
    //   11: aload_3
    //   12: new 1107	org/xml/sax/helpers/DefaultHandler
    //   15: dup
    //   16: invokespecial 1824	org/xml/sax/helpers/DefaultHandler:<init>	()V
    //   19: invokevirtual 1739	javax/xml/parsers/DocumentBuilder:setErrorHandler	(Lorg/xml/sax/ErrorHandler;)V
    //   22: new 980	java/io/ByteArrayInputStream
    //   25: dup
    //   26: aload_0
    //   27: ldc_w 927
    //   30: invokevirtual 1689	java/lang/String:getBytes	(Ljava/lang/String;)[B
    //   33: invokespecial 1623	java/io/ByteArrayInputStream:<init>	([B)V
    //   36: astore_2
    //   37: aload_3
    //   38: aload_2
    //   39: invokevirtual 1740	javax/xml/parsers/DocumentBuilder:parse	(Ljava/io/InputStream;)Lorg/w3c/dom/Document;
    //   42: invokeinterface 1895 1 0
    //   47: astore_1
    //   48: goto +157 -> 205
    //   51: astore_3
    //   52: ldc_w 929
    //   55: aload_3
    //   56: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   59: aload_2
    //   60: ifnull +166 -> 226
    //   63: aload_2
    //   64: invokevirtual 1650	java/io/InputStream:close	()V
    //   67: goto +159 -> 226
    //   70: astore 5
    //   72: ldc_w 929
    //   75: aload 5
    //   77: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   80: goto +146 -> 226
    //   83: astore_3
    //   84: ldc_w 929
    //   87: aload_3
    //   88: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   91: aload_2
    //   92: ifnull +134 -> 226
    //   95: aload_2
    //   96: invokevirtual 1650	java/io/InputStream:close	()V
    //   99: goto +127 -> 226
    //   102: astore 5
    //   104: ldc_w 929
    //   107: aload 5
    //   109: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   112: goto +114 -> 226
    //   115: astore_3
    //   116: ldc_w 929
    //   119: aload_3
    //   120: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   123: aload_2
    //   124: ifnull +102 -> 226
    //   127: aload_2
    //   128: invokevirtual 1650	java/io/InputStream:close	()V
    //   131: goto +95 -> 226
    //   134: astore 5
    //   136: ldc_w 929
    //   139: aload 5
    //   141: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   144: goto +82 -> 226
    //   147: astore_3
    //   148: ldc_w 929
    //   151: aload_3
    //   152: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   155: aload_2
    //   156: ifnull +70 -> 226
    //   159: aload_2
    //   160: invokevirtual 1650	java/io/InputStream:close	()V
    //   163: goto +63 -> 226
    //   166: astore 5
    //   168: ldc_w 929
    //   171: aload 5
    //   173: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   176: goto +50 -> 226
    //   179: astore 4
    //   181: aload_2
    //   182: ifnull +20 -> 202
    //   185: aload_2
    //   186: invokevirtual 1650	java/io/InputStream:close	()V
    //   189: goto +13 -> 202
    //   192: astore 5
    //   194: ldc_w 929
    //   197: aload 5
    //   199: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   202: aload 4
    //   204: athrow
    //   205: aload_2
    //   206: ifnull +20 -> 226
    //   209: aload_2
    //   210: invokevirtual 1650	java/io/InputStream:close	()V
    //   213: goto +13 -> 226
    //   216: astore 5
    //   218: ldc_w 929
    //   221: aload 5
    //   223: invokestatic 1804	org/eclipse/pde/api/tools/internal/util/Util:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   226: aload_1
    //   227: areturn
    // Line number table:
    //   Java source line #1539	-> byte code offset #0
    //   Java source line #1540	-> byte code offset #2
    //   Java source line #1542	-> byte code offset #4
    //   Java source line #1543	-> byte code offset #11
    //   Java source line #1544	-> byte code offset #22
    //   Java source line #1545	-> byte code offset #37
    //   Java source line #1546	-> byte code offset #51
    //   Java source line #1547	-> byte code offset #52
    //   Java source line #1556	-> byte code offset #59
    //   Java source line #1557	-> byte code offset #63
    //   Java source line #1559	-> byte code offset #70
    //   Java source line #1560	-> byte code offset #72
    //   Java source line #1548	-> byte code offset #83
    //   Java source line #1549	-> byte code offset #84
    //   Java source line #1556	-> byte code offset #91
    //   Java source line #1557	-> byte code offset #95
    //   Java source line #1559	-> byte code offset #102
    //   Java source line #1560	-> byte code offset #104
    //   Java source line #1550	-> byte code offset #115
    //   Java source line #1551	-> byte code offset #116
    //   Java source line #1556	-> byte code offset #123
    //   Java source line #1557	-> byte code offset #127
    //   Java source line #1559	-> byte code offset #134
    //   Java source line #1560	-> byte code offset #136
    //   Java source line #1552	-> byte code offset #147
    //   Java source line #1553	-> byte code offset #148
    //   Java source line #1556	-> byte code offset #155
    //   Java source line #1557	-> byte code offset #159
    //   Java source line #1559	-> byte code offset #166
    //   Java source line #1560	-> byte code offset #168
    //   Java source line #1554	-> byte code offset #179
    //   Java source line #1556	-> byte code offset #181
    //   Java source line #1557	-> byte code offset #185
    //   Java source line #1559	-> byte code offset #192
    //   Java source line #1560	-> byte code offset #194
    //   Java source line #1562	-> byte code offset #202
    //   Java source line #1556	-> byte code offset #205
    //   Java source line #1557	-> byte code offset #209
    //   Java source line #1559	-> byte code offset #216
    //   Java source line #1560	-> byte code offset #218
    //   Java source line #1563	-> byte code offset #226
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	228	0	document	String
    //   1	226	1	root	org.w3c.dom.Element
    //   3	207	2	stream	InputStream
    //   10	28	3	parser	DocumentBuilder
    //   51	5	3	e	ParserConfigurationException
    //   83	5	3	e	javax.xml.parsers.FactoryConfigurationError
    //   115	5	3	e	org.xml.sax.SAXException
    //   147	5	3	e	IOException
    //   179	24	4	localObject	Object
    //   70	6	5	e	IOException
    //   102	6	5	e	IOException
    //   134	6	5	e	IOException
    //   166	6	5	e	IOException
    //   192	6	5	e	IOException
    //   216	6	5	e	IOException
    // Exception table:
    //   from	to	target	type
    //   4	48	51	javax/xml/parsers/ParserConfigurationException
    //   59	67	70	java/io/IOException
    //   4	48	83	javax/xml/parsers/FactoryConfigurationError
    //   91	99	102	java/io/IOException
    //   4	48	115	org/xml/sax/SAXException
    //   123	131	134	java/io/IOException
    //   4	48	147	java/io/IOException
    //   155	163	166	java/io/IOException
    //   4	59	179	finally
    //   83	91	179	finally
    //   115	123	179	finally
    //   147	155	179	finally
    //   181	189	192	java/io/IOException
    //   205	213	216	java/io/IOException
  }
  
  /* Error */
  public static void saveFile(File file, String contents)
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_2
    //   2: new 979	java/io/BufferedWriter
    //   5: dup
    //   6: new 986	java/io/FileWriter
    //   9: dup
    //   10: aload_0
    //
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

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-2019. Infinite Loop Ltd