Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] Creating an IClassFileReader

Actually, it doesn't quite handle internal classfiles. Will add instead the
following:

      public static IClassFileReader
createDefaultClassFileReader(IClassFile classfile, int decodingFlag){

            IPath filePath = classfile.getPath();
            IPackageFragmentRoot root = (IPackageFragmentRoot)
classfile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            if (root != null){
                  try {
                        IPath rootPath = root.getPath();
                        if (root instanceof JarPackageFragmentRoot) {

                              String archiveName =
((JarPackageFragmentRoot)root).getJar().getName();
                              String entryName = classfile.getParent
().getElementName();
                              entryName = entryName.replace('.', '/');
                              if (entryName.equals("")) { //$NON-NLS-1$
                                    entryName += classfile.getElementName
();
                              } else {
                                    entryName += '/' +
classfile.getElementName();
                              }
                              return
createDefaultClassFileReader(archiveName, entryName, decodingFlag);
                        } else {
                              return
createDefaultClassFileReader(classfile.getCorrespondingResource
().getLocation().toOSString(), decodingFlag);
                        }
                  } catch(CoreException e){
                  }
            }
            return null;
      }


                                                                                                                                            
                      Philippe Mulet                                                                                                        
                                               To:      jdt-core-dev@xxxxxxxxxxx                                                            
                      05/17/2002 11:55         cc:      jdt-core-dev@xxxxxxxxxxx                                                            
                      AM                       Subject: Re: [jdt-core-dev] Creating an IClassFileReader(Document link: Philippe Mulet)      
                                                                                                                                            
                                                                                                                                            



You're right, this should do the trick. I'll add it onto the ToolFactory.

      /**
       * Helper method to create a classfile reader onto a classfile Java
element.
       * Create a default classfile reader, able to expose the internal
representation of a given classfile
       * according to the decoding flag used to initialize the reader.
       * Answer null if the file named fileName doesn't represent a valid
.class file.
       *
       * The decoding flags are described in IClassFileReader.
       *
       * @param classfile the classfile element to introspect
       * @param decodingFlag the flag used to decode the class file reader.
       * @return a default classfile reader
       *
       * @see IClassFileReader
       */
      public static IClassFileReader
createDefaultClassFileReader(IClassFile classfile, int decodingFlag){

            IPath filePath = classfile.getPath();
            IPackageFragmentRoot root = (IPackageFragmentRoot)
classfile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            if (root != null) {
                  try {
                        IResource rootRsc = root.getCorrespondingResource
();
                        IPath rootPath = root.getPath();
                        if ((rootRsc == null || rootRsc.getType() ==
IResource.FILE)
                              &&
Util.isArchiveFileName(rootPath.lastSegment())) {

                              String archiveName = filePath.toString();
                              String entryName = classfile.getParent
().getElementName();
                              entryName = entryName.replace('.', '/');
                              if (entryName.equals("")) { //$NON-NLS-1$
                                    entryName += classfile.getElementName
();
                              } else {
                                    entryName += '/' +
classfile.getElementName();
                              }
                              return
createDefaultClassFileReader(archiveName, entryName, decodingFlag);
                        }
                  } catch(JavaModelException e){
                        return null;
                  }
            }
            return createDefaultClassFileReader(filePath.toString(),
decodingFlag);
      }



                                                                                                                                               
                      Kai-Uwe Maetzel                                                                                                          
                      <maetzel@xxxxxxx>           To:      jdt-core-dev@xxxxxxxxxxx                                                            
                      Sent by:                    cc:                                                                                          
                      jdt-core-dev-admin@         Subject: Re: [jdt-core-dev] Creating an IClassFileReader                                     
                      eclipse.org                                                                                                              
                                                                                                                                               
                                                                                                                                               
                      05/16/2002 04:59 PM                                                                                                      
                      Please respond to                                                                                                        
                      jdt-core-dev                                                                                                             
                                                                                                                                               
                                                                                                                                               



In the case of a jar, the current implementation returns the file path of
the enclosing jar for classfile.getPath().


At 04:31 PM 5/16/2002 +0200, you wrote:

>Would something like this work ?
>
>IClassFileReader classFileReader;
>IPath filePath = classfile.getPath();
>IPackageFragmentRoot root = (IPackageFragmentRoot)
>classfile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
>if (root != null && root.isExternal()){
>       classFileReader =
>ToolFactory.createDefaultClassFileReader(root.getPath().toOSString(),
>filePath.toOSString(), IClassFileReader.ALL);
>} else {
>       classFileReader =
>ToolFactory.createDefaultClassFileReader(filePath.toOSString(),
>IClassFileReader.ALL);
>}
>
>
>
>
>
>
>                       Kai-Uwe
> Maetzel
>
>                       <maetzel@xxxxxxx>           To:
> jdt-core-dev@xxxxxxxxxxx
>
>                       Sent
> by:                    cc:
>
>                       jdt-core-dev-admin@         Subject: [jdt-core-dev]

> Creating an IClassFileReader
>                       eclipse.org
>
>
>
>
>
>                       05/16/2002 01:11
> PM
>
>                       Please respond
> to
>
>                       jdt-core-dev
>
>
>
>
>
>
>
>
>Having an IClassFile, is there any simple way to create an
IClassFileReader
>
>for this class file.
>Thanks.
>
>_______________________________________________
>jdt-core-dev mailing list
>jdt-core-dev@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/jdt-core-dev
>
>
>
>
>_______________________________________________
>jdt-core-dev mailing list
>jdt-core-dev@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/jdt-core-dev


_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev








Back to the top