Package org.eclipse.jdt.internal.compiler.env

Examples of org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer


                    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." );
                    }
                }

                final InputStream is = pClassLoader.getResourceAsStream( resourceName );
                if ( is == null ) {
                    return null;
                }

                final byte[] buffer = new byte[8192];
                final ByteArrayOutputStream baos = new ByteArrayOutputStream( buffer.length );
                int count;
                try {
                    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


                    try {
                        if (className.equals(targetClassName)) {
                            ICompilationUnit compilationUnit =
                                new CompilationUnit(sourceFile, className);
                            return
                                new NameEnvironmentAnswer(compilationUnit, null);
                        }
                        String resourceName =
                            className.replace('.', '/') + ".class";
                        is = classLoader.getResourceAsStream(resourceName);
                        if (is != null) {
                            byte[] classBytes;
                            byte[] buf = new byte[8192];
                            ByteArrayOutputStream baos =
                                new ByteArrayOutputStream(buf.length);
                            int count;
                            while ((count = is.read(buf, 0, buf.length)) > 0) {
                                baos.write(buf, 0, count);
                            }
                            baos.flush();
                            classBytes = baos.toByteArray();
                            char[] fileName = className.toCharArray();
                            ClassFileReader classFileReader =
                                new ClassFileReader(classBytes, fileName,
                                                    true);
                            return
                                new NameEnvironmentAnswer(classFileReader, null);
                        }
                    } catch (IOException exc) {
                        log.error("Compilation error", exc);
                    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException exc) {
                        log.error("Compilation error", exc);
View Full Code Here

                    if (name.startsWith("play.") || name.startsWith("java.") || name.startsWith("javax.")) {
                        byte[] bytes = Play.classloader.getClassDefinition(name);
                        if (bytes != null) {
                            ClassFileReader classFileReader = new ClassFileReader(bytes, name.toCharArray(), true);
                            return new NameEnvironmentAnswer(classFileReader, null);
                        }
                        return null;
                    }

                    char[] fileName = name.toCharArray();
                    ApplicationClass applicationClass = applicationClasses.getApplicationClass(name);

                    // ApplicationClass exists
                    if (applicationClass != null) {

                        if (applicationClass.javaByteCode != null) {
                            ClassFileReader classFileReader = new ClassFileReader(applicationClass.javaByteCode, fileName, true);
                            return new NameEnvironmentAnswer(classFileReader, null);
                        }
                        // Cascade compilation
                        ICompilationUnit compilationUnit = new CompilationUnit(name);
                        return new NameEnvironmentAnswer(compilationUnit, null);
                    }

                    // So it's a standard class
                    byte[] bytes = Play.classloader.getClassDefinition(name);
                    if (bytes != null) {
                        ClassFileReader classFileReader = new ClassFileReader(bytes, fileName, true);
                        return new NameEnvironmentAnswer(classFileReader, null);
                    }

                    // So it does not exist
                    return null;
                } catch (ClassFormatException e) {
View Full Code Here

}
/**
* @see INameEnvironment#findType(char[][])
*/
public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
  NameEnvironmentAnswer result = this.env.findType(compoundTypeName);
  if (result != null) {
    return result;
  }
  if (CharOperation.equals(compoundTypeName, ROOT_COMPOUND_NAME)) {
    IBinaryType binary = this.context.getRootCodeSnippetBinary();
    if (binary == null) {
      return null;
    } else {
      return new NameEnvironmentAnswer(binary, null /*no access restriction*/);
    }
  }
  VariablesInfo installedVars = this.context.installedVars;
  ClassFile[] classFiles = installedVars.classFiles;
  for (int i = 0; i < classFiles.length; i++) {
    ClassFile classFile = classFiles[i];
    if (CharOperation.equals(compoundTypeName, classFile.getCompoundName())) {
      ClassFileReader binary = null;
      try {
        binary = new ClassFileReader(classFile.getBytes(), null);
      } catch (ClassFormatException e) {
        e.printStackTrace()// Should never happen since we compiled this type
        return null;
      }
      return new NameEnvironmentAnswer(binary, null /*no access restriction*/);
    }
  }
  return null;
}
View Full Code Here

}
/**
* @see INameEnvironment#findType(char[], char[][])
*/
public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
  NameEnvironmentAnswer result = this.env.findType(typeName, packageName);
  if (result != null) {
    return result;
  }
  return findType(CharOperation.arrayConcat(packageName, typeName));
}
View Full Code Here

  } catch (IOException e) {
    return null;
  }
  if (reader != null) {
    if (this.accessRuleSet == null)
      return new NameEnvironmentAnswer(reader, null);
    String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length);
    return new NameEnvironmentAnswer(reader, this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
  }
  return null;
}
View Full Code Here

  String qualifiedPackageName =
    qualifiedTypeName.length() == typeName.length
      ? Util.EMPTY_STRING
      : qualifiedBinaryFileName.substring(0, qualifiedTypeName.length() - typeName.length - 1);
  String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar);
  NameEnvironmentAnswer suggestedAnswer = null;
  if (qualifiedPackageName == qp2) {
    for (int i = 0, length = this.classpaths.length; i < length; i++) {
      NameEnvironmentAnswer answer = this.classpaths[i].findClass(typeName, qualifiedPackageName, qualifiedBinaryFileName, asBinaryOnly);
      if (answer != null) {
        if (!answer.ignoreIfBetter()) {
          if (answer.isBetter(suggestedAnswer))
            return answer;
        } else if (answer.isBetter(suggestedAnswer))
          // remember suggestion and keep looking
          suggestedAnswer = answer;
      }
    }
  } else {
    String qb2 = qualifiedBinaryFileName.replace('/', File.separatorChar);
    for (int i = 0, length = this.classpaths.length; i < length; i++) {
      Classpath p = this.classpaths[i];
      NameEnvironmentAnswer answer = (p instanceof ClasspathJar)
        ? p.findClass(typeName, qualifiedPackageName, qualifiedBinaryFileName, asBinaryOnly)
        : p.findClass(typeName, qp2, qb2, asBinaryOnly);
      if (answer != null) {
        if (!answer.ignoreIfBetter()) {
          if (answer.isBetter(suggestedAnswer))
            return answer;
        } else if (answer.isBetter(suggestedAnswer))
          // remember suggestion and keep looking
          suggestedAnswer = answer;
      }
    }
  }
View Full Code Here

    return null; // most common case

  try {
    ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
    if (reader != null)
      return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName));
  } catch(ClassFormatException e) {
    // treat as if class file is missing
  } catch (IOException e) {
    // treat as if class file is missing
  }
View Full Code Here

          contents = Util.getInputStreamAsCharArray(stream, -1, this.encoding);
        } finally {
          if (stream != null)
            stream.close();
        }
        return new NameEnvironmentAnswer(
          new CompilationUnit(
            contents,
            qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java,
            this.encoding,
            this.destinationPath),
View Full Code Here

  boolean binaryExists = ((this.mode & BINARY) != 0) && doesFileExist(fileName + SUFFIX_STRING_class, qualifiedPackageName);
  boolean sourceExists = ((this.mode & SOURCE) != 0) && doesFileExist(fileName + SUFFIX_STRING_java, qualifiedPackageName);
  if (sourceExists && !asBinaryOnly) {
    String fullSourcePath = this.path + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6+ SUFFIX_STRING_java;
    if (!binaryExists)
      return new NameEnvironmentAnswer(new CompilationUnit(null,
          fullSourcePath, this.encoding, this.destinationPath),
          fetchAccessRestriction(qualifiedBinaryFileName));
    String fullBinaryPath = this.path + qualifiedBinaryFileName;
    long binaryModified = new File(fullBinaryPath).lastModified();
    long sourceModified = new File(fullSourcePath).lastModified();
    if (sourceModified > binaryModified)
      return new NameEnvironmentAnswer(new CompilationUnit(null,
          fullSourcePath, this.encoding, this.destinationPath),
          fetchAccessRestriction(qualifiedBinaryFileName));
  }
  if (binaryExists) {
    try {
      ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName);
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321115, package names are to be treated case sensitive.
      String typeSearched = qualifiedPackageName.length() > 0 ?
          qualifiedPackageName.replace(File.separatorChar, '/') + "/" + fileName //$NON-NLS-1$
          : fileName;
      if (!CharOperation.equals(reader.getName(), typeSearched.toCharArray())) {
        reader = null;
      }
      if (reader != null)
        return new NameEnvironmentAnswer(
            reader,
            fetchAccessRestriction(qualifiedBinaryFileName));
    } catch (IOException e) {
      // treat as if file is missing
    } catch (ClassFormatException e) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer

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.