Examples of ClassFileReader


Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

          // find the type declaration that corresponds to the original source type
          typeDeclaration = new ASTNodeFinder(parsedUnit).findType(context);
        }
      } else { // binary type
        ClassFile classFile = (ClassFile) context.getClassFile();
        ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo((IFile) classFile.resource(), false/*don't fully initialize so as to keep constant pool (used below)*/);
        CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1, this.compilerOptions.maxProblemsPerUnit);
        parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0);
        HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray();

        BinaryTypeConverter converter = new BinaryTypeConverter(this.parser.problemReporter(), result, typeNames);
        typeDeclaration = converter.buildTypeDeclaration(context, parsedUnit);
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

  Argument[] arguments = method.arguments;
  int argCount = arguments == null ? 0 : arguments.length;
  if (type.isBinary()) {
    // don't cache the methods of the binary type
    // fall thru if its a constructor with a synthetic argument... find it the slower way
    ClassFileReader reader = classFileReader(type);
    if (reader != null) {
      // build arguments names
      boolean firstIsSynthetic = false;
      if (reader.isMember() && method.isConstructor() && !Flags.isStatic(reader.getModifiers())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48261
        firstIsSynthetic = true;
        argCount++;
      }
      char[][] argumentTypeNames = new char[argCount][];
      for (int i = 0; i < argCount; i++) {
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

}
/*
* Create binary method handle
*/
IMethod createBinaryMethodHandle(IType type, char[] methodSelector, char[][] argumentTypeNames) {
  ClassFileReader reader = MatchLocator.classFileReader(type);
  if (reader != null) {
    IBinaryMethod[] methods = reader.getMethods();
    if (methods != null) {
      int argCount = argumentTypeNames == null ? 0 : argumentTypeNames.length;
      nextMethod : for (int i = 0, methodsLength = methods.length; i < methodsLength; i++) {
        IBinaryMethod binaryMethod = methods[i];
        char[] selector = binaryMethod.isConstructor() ? type.getElementName().toCharArray() : binaryMethod.getSelector();
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

  if (this.sourceFileName != null) return this.sourceFileName;

  this.sourceFileName = NO_SOURCE_FILE_NAME;
  if (this.openable.getSourceMapper() != null) {
    BinaryType type = (BinaryType) ((ClassFile) this.openable).getType();
    ClassFileReader reader = MatchLocator.classFileReader(type);
    if (reader != null) {
      String fileName = type.sourceFileName(reader);
      this.sourceFileName = fileName == null ? NO_SOURCE_FILE_NAME : fileName;
    }
  }
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

      }
    }
  } else {
    byte[] contents = Util.getResourceContentsAsByteArray(file);
    try {
      return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize);
    } catch (ClassFormatException cfe) {
      //the structure remains unknown
      return null;
    }
  }
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

    String entryName = Util.concatWith(pkg.names, getElementName(), '/');
    ZipEntry ze = zip.getEntry(entryName);
    if (ze != null) {
      byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
      String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName;
      return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize);
    }
  } finally {
    JavaModelManager.getJavaModelManager().closeZipFile(zip);
  }
  return null;
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

      final byte[] contents = this.document.getByteContents();
      // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=107124
      // contents can potentially be null if a IOException occurs while retrieving the contents
      if (contents == null) return;
      final String path = this.document.getPath();
      ClassFileReader reader = new ClassFileReader(contents, path == null ? null : path.toCharArray());

      // first add type references
      char[] className = replace('/', '.', reader.getName()); // looks like java/lang/String
      // need to extract the package name and the simple name
      int packageNameIndex = CharOperation.lastIndexOf('.', className);
      char[] packageName = null;
      char[] name = null;
      if (packageNameIndex >= 0) {
        packageName = CharOperation.subarray(className, 0, packageNameIndex);
        name = CharOperation.subarray(className, packageNameIndex + 1, className.length);
      } else {
        packageName = CharOperation.NO_CHAR;
        name = className;
      }
      char[] enclosingTypeName = null;
      boolean isNestedType = reader.isNestedType();
      if (isNestedType) {
        if (reader.isAnonymous()) {
          name = CharOperation.NO_CHAR;
        } else {
          name = reader.getInnerSourceName();
        }
        if (reader.isLocal() || reader.isAnonymous()) {
          // set specific ['0'] value for local and anonymous to be able to filter them
          enclosingTypeName = ONE_ZERO;
        } else {
          char[] fullEnclosingName = reader.getEnclosingTypeName();
          int nameLength = fullEnclosingName.length - packageNameIndex - 1;
          if (nameLength <= 0) {
            // See PR 1GIR345: ITPJCORE:ALL - Indexer: NegativeArraySizeException
            return;
          }
          enclosingTypeName = new char[nameLength];
          System.arraycopy(fullEnclosingName, packageNameIndex + 1, enclosingTypeName, 0, nameLength);
        }
      }
      // type parameters
      char[][] typeParameterSignatures = null;
      char[] genericSignature = reader.getGenericSignature();
      if (genericSignature != null) {
        CharOperation.replace(genericSignature, '/', '.');
        typeParameterSignatures = Signature.getTypeParameters(genericSignature);
      }

      // eliminate invalid innerclasses (1G4KCF7)
      if (name == null) return;

      char[][] superinterfaces = replace('/', '.', reader.getInterfaceNames());
      char[][] enclosingTypeNames = enclosingTypeName == null ? null : new char[][] {enclosingTypeName};
      int modifiers = reader.getModifiers();
      switch (TypeDeclaration.kind(modifiers)) {
        case TypeDeclaration.CLASS_DECL :
          char[] superclass = replace('/', '.', reader.getSuperclassName());
          addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures, false);
          break;
        case TypeDeclaration.INTERFACE_DECL :
          addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false);
          break;
        case TypeDeclaration.ENUM_DECL :
          superclass = replace('/', '.', reader.getSuperclassName());
          addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, false);
          break;
        case TypeDeclaration.ANNOTATION_TYPE_DECL :
          addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false);
          break;
      }

      // Look for references in class annotations
      IBinaryAnnotation[] annotations = reader.getAnnotations();
      if (annotations != null) {
        for (int a=0, length=annotations.length; a<length; a++) {
          IBinaryAnnotation annotation = annotations[a];
          addBinaryAnnotation(annotation);
        }
      }
      long tagBits = reader.getTagBits() & TagBits.AllStandardAnnotationsMask;
      if (tagBits != 0) {
        addBinaryStandardAnnotations(tagBits);
      }
     
      int extraFlags = ExtraFlags.getExtraFlags(reader);

      // first reference all methods declarations and field declarations
      MethodInfo[] methods = (MethodInfo[]) reader.getMethods();
      boolean noConstructor = true;
      if (methods != null) {
        for (int i = 0, max = methods.length; i < max; i++) {
          MethodInfo method = methods[i];
          boolean isConstructor = method.isConstructor();
          char[] descriptor = method.getMethodDescriptor();
          char[][] parameterTypes = decodeParameterTypes(descriptor, isConstructor && isNestedType);
          char[] returnType = decodeReturnType(descriptor);
          char[][] exceptionTypes = replace('/', '.', method.getExceptionTypeNames());
          if (isConstructor) {
            noConstructor = false;
            char[] signature = method.getGenericSignature();
            if (signature == null) {
              if (reader.isNestedType() && ((modifiers & ClassFileConstants.AccStatic) == 0)) {
                signature = removeFirstSyntheticParameter(descriptor);
              } else {
                signature = descriptor;
              }
            }
            addConstructorDeclaration(
                name,
                parameterTypes == null ? 0 : parameterTypes.length,
                signature, 
                parameterTypes,
                method.getArgumentNames(),
                method.getModifiers(),
                packageName,
                modifiers,
                exceptionTypes,
                extraFlags);
          } else {
            if (!method.isClinit()) {
              addMethodDeclaration(method.getSelector(), parameterTypes, returnType, exceptionTypes);
            }
          }
          // look for references in method annotations
          annotations = method.getAnnotations();
          if (annotations != null) {
            for (int a=0, length=annotations.length; a<length; a++) {
              IBinaryAnnotation annotation = annotations[a];
              addBinaryAnnotation(annotation);
            }
          }
          tagBits = method.getTagBits() & TagBits.AllStandardAnnotationsMask;
          if (tagBits != 0) {
            addBinaryStandardAnnotations(tagBits);
          }
        }
      }
      if (noConstructor) {
        addDefaultConstructorDeclaration(className, packageName, modifiers, extraFlags);
      }
      FieldInfo[] fields = (FieldInfo[]) reader.getFields();
      if (fields != null) {
        for (int i = 0, max = fields.length; i < max; i++) {
          FieldInfo field = fields[i];
          char[] fieldName = field.getName();
          char[] fieldType = decodeFieldType(replace('/', '.', field.getTypeName()));
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

   * </ul>
   * Returns the jdk level
   */
  public static long getJdkLevel(Object targetLibrary) {
    try {
      ClassFileReader reader = null;
      if (targetLibrary instanceof IFolder) {
        IFile classFile = findFirstClassFile((IFolder) targetLibrary); // only internal classfolders are allowed
        if (classFile != null)
          reader = Util.newClassFileReader(classFile);
      } else {
        // root is a jar file or a zip file
        ZipFile jar = null;
        try {
          IPath path = null;
          if (targetLibrary instanceof IResource) {
            path = ((IResource)targetLibrary).getFullPath();
          } else if (targetLibrary instanceof File){
            File f = (File) targetLibrary;
            if (!f.isDirectory()) {
              path = new Path(((File)targetLibrary).getPath());
            }
          }
          if (path != null) {
            jar = JavaModelManager.getJavaModelManager().getZipFile(path);
            for (Enumeration e= jar.entries(); e.hasMoreElements();) {
              ZipEntry member= (ZipEntry) e.nextElement();
              String entryName= member.getName();
              if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
                reader = ClassFileReader.read(jar, entryName);
                break;
              }
            }
          }
        } catch (CoreException e) {
          // ignore
        } finally {
          JavaModelManager.getJavaModelManager().closeZipFile(jar);
        }
      }
      if (reader != null) {
        return reader.getVersion();
      }
    } catch (CoreException e) {
      // ignore
    } catch(ClassFormatException e) {
      // ignore
View Full Code Here

Examples of org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader

               
                final byte[] clazzBytes = pStore.read( resourceName );
                if (clazzBytes != null) {
                    final char[] fileName = pClazzName.toCharArray();
                    try {
                        final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true);
                        return new NameEnvironmentAnswer(classFileReader, null);
                    } catch (final ClassFormatException e) {
                        throw new RuntimeException( "ClassFormatException in loading class '" + fileName + "' with JCI." );
                    }
                }
               
                InputStream is = null;
                ByteArrayOutputStream baos = null;
                try {
                    is = pClassLoader.getResourceAsStream(resourceName);
                    if (is == null) {
                        return null;
                    }
   
                    final byte[] buffer = new byte[8192];
                    baos = new ByteArrayOutputStream(buffer.length);
                    int count;
                        while ((count = is.read(buffer, 0, buffer.length)) > 0) {
                            baos.write(buffer, 0, count);
                        }
                        baos.flush();
                        final char[] fileName = pClazzName.toCharArray();
                        final ClassFileReader classFileReader = new ClassFileReader(baos.toByteArray(), fileName, true);
                        return new NameEnvironmentAnswer(classFileReader, null);
                } catch ( final IOException e ) {
                    throw new RuntimeException( "could not read class",
                                                e );
                } catch ( final ClassFormatException e ) {
View Full Code Here

Examples of org.eclipse.jdt.internal.core.util.ClassFileReader

   * @see IClassFileReader
   * @since 3.2
   */
  public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) {
    try {
      return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag);
    } catch(ClassFormatException e) {
      return null;
    } catch(IOException e) {
      return null;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.