Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IClassFile


      IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
      if (pkgFragment == null) {
        pkgFragment= this.lastPkgFragmentRoot.getPackageFragment(pkgName);
        this.packageHandles.put(pkgName, pkgFragment);
      }
      IClassFile classFile= pkgFragment.getClassFile(simpleNames[length]);
      return (Openable) classFile;
    } else {
      // path to a file in a directory
      // Optimization: cache package fragment root handle and package handles
      int rootPathLength = -1;
      if (this.lastPkgFragmentRootPath == null
        || !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
          && !org.eclipse.jdt.internal.compiler.util.Util.isExcluded(resourcePath.toCharArray(), this.lastPkgFragmentRoot.fullInclusionPatternChars(), this.lastPkgFragmentRoot.fullExclusionPatternChars(), false)
          && (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
          && resourcePath.charAt(rootPathLength) == '/')) {
        PackageFragmentRoot root= getPkgFragmentRoot(resourcePath);
        if (root == null)
          return null; // match is outside classpath
        this.lastPkgFragmentRoot = root;
        this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.internalPath().toString();
        this.packageHandles = new HashtableOfArrayToObject(5);
      }
      // create handle
      resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
      String[] simpleNames = new Path(resourcePath).segments();
      String[] pkgName;
      int length = simpleNames.length-1;
      if (length > 0) {
        pkgName = new String[length];
        System.arraycopy(simpleNames, 0, pkgName, 0, length);
      } else {
        pkgName = CharOperation.NO_STRINGS;
      }
      IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
      if (pkgFragment == null) {
        pkgFragment= this.lastPkgFragmentRoot.getPackageFragment(pkgName);
        this.packageHandles.put(pkgName, pkgFragment);
      }
      String simpleName= simpleNames[length];
      if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) {
        ICompilationUnit unit= pkgFragment.getCompilationUnit(simpleName);
        return (Openable) unit;
      } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(simpleName)){
        IClassFile classFile= pkgFragment.getClassFile(simpleName);
        return (Openable) classFile;
      }
      return null;
    }
  }
View Full Code Here


  }
  return result;
}

public static ClassFileReader classFileReader(IType type) {
  IClassFile classFile = type.getClassFile();
  JavaModelManager manager = JavaModelManager.getJavaModelManager();
  if (classFile.isOpen())
    return (ClassFileReader) manager.getInfo(type);

  PackageFragment pkg = (PackageFragment) type.getPackageFragment();
  IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
  try {
    if (!root.isArchive())
      return Util.newClassFileReader(((JavaElement) type).resource());

    ZipFile zipFile = null;
    try {
      IPath zipPath = root.getPath();
      if (JavaModelManager.ZIP_ACCESS_VERBOSE)
        System.out.println("(" + Thread.currentThread() + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$  //$NON-NLS-2$
      zipFile = manager.getZipFile(zipPath);
      String classFileName = classFile.getElementName();
      String path = Util.concatWith(pkg.names, classFileName, '/');
      return ClassFileReader.read(zipFile, path);
    } finally {
      manager.closeZipFile(zipFile);
    }
View Full Code Here

  if (simpleTypeName.equals(binaryTypeQualifiedName))
    return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type

  // type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791)
  String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName;
  IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class);
  return classFile.getType();
}
View Full Code Here

      char[][] parameterTypes = methodInfo.parameterTypes;
      if (methodInfo.isConstructor && currentType.getDeclaringType() != null && !Flags.isStatic(currenTypeModifiers)) {
        IType declaringType = currentType.getDeclaringType();
        String declaringTypeName = declaringType.getElementName();
        if (declaringTypeName.length() == 0) {
          IClassFile classFile = declaringType.getClassFile();
          int length = parameterTypes != null ? parameterTypes.length : 0;
          char[][] newParameterTypes = new char[length+1][];
          declaringTypeName = classFile.getElementName();
          declaringTypeName = declaringTypeName.substring(0, declaringTypeName.indexOf('.'));
          newParameterTypes[0] = declaringTypeName.toCharArray();
          if (length != 0) {
            System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
          }
View Full Code Here

   
    if( ! doc.isInJar() )
      return super.getEditorInput(doc);
 
    if( "class".equals(doc.getFileExtension()) ) {
      IClassFile classFile = getClassFile(doc);

      if( classFile == null )
        return null;

      return EditorUtility.getEditorInput(classFile);
View Full Code Here

  public IStorage getStorage(SearchResultDoc doc) throws Exception {
    if( !doc.isInJar() )
      return super.getStorage(doc); // return file
   
    if( "class".equals(doc.getFileExtension())) {
      IClassFile classFile = getClassFile(doc);

      if( classFile == null )
        return null;

      ClassFileSourceStorage storage = new ClassFileSourceStorage(classFile);
View Full Code Here

    IPackageFragment pkg = jar.getPackageFragment(pkgName);
   
    if( pkg == null )
      throw new Exception("Package " + pkgName + " not found  in " + doc.getProjectName());
   
    IClassFile classFile = pkg.getClassFile(fileName);
   
    return classFile;
  }
View Full Code Here

    final IPackageFragmentRoot root = javaProject.createJAR(
        "testdata/bin/signatureresolver.jar", "/signatureresolver.jar",
        new Path("/UnitTestProject/signatureresolver.jar"), null);
    JavaProjectKit.waitForBuild();
    javaProject.assertNoErrors();
    final IClassFile classFile = root.getPackageFragment("signatureresolver")
        .getClassFile("Samples.class");
    type = classFile.getType();
    createMethodIndex();
  }
View Full Code Here

  private static Object computeScope(Object element) throws JavaModelException {
    if(element instanceof IResource) {
      element = JavaCore.create((IResource) element);
    }
    if(element instanceof IClassFile) {
      IClassFile cf = (IClassFile) element;
      element = cf.getType();
    }

    return element;
  }
View Full Code Here

            }
          }
          return false;
        }
        else if (fileExtension.equals("class")) {
          IClassFile classFile = JavaCore.createClassFileFrom(file);
          IType type = classFile.getType();
          if (type != null) {
            if (NameMatcher.isSimilarName(type.getElementName(), toMatch)) {
              suggestedClassNames.add(type.getFullyQualifiedName());
            }
          }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IClassFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.