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

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


            }

            private NameEnvironmentAnswer createNameEnvironmentAnswer(final String pClazzName, final byte[] clazzBytes) throws ClassFormatException {
                final char[] fileName = pClazzName.toCharArray();
                final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true);
                return new NameEnvironmentAnswer(classFileReader, null);
            }

            private boolean isSourceAvailable(final String pClazzName, final ResourceReader pReader) {
                // FIXME: this should not be tied to the extension
                final String javaSource = pClazzName.replace('.', '/') + ".java";
View Full Code Here


    public void cleanup() {
    }

    private NameEnvironmentAnswer findType(String fullName) {
      if (this.fullName.equals(fullName))
        return new NameEnvironmentAnswer(unit, null);

      try {
        InputStream is = getClass().getClassLoader()
            .getResourceAsStream(
                fullName.replace('.', '/') + ".class");
        if (is != null) {
          byte[] buffer = new byte[8192];
          int bytes = 0;
          ByteArrayOutputStream os = new ByteArrayOutputStream(
              buffer.length);
          while ((bytes = is.read(buffer, 0, buffer.length)) > 0)
            os.write(buffer, 0, bytes);

          os.flush();
          ClassFileReader classFileReader = new ClassFileReader(
              os.toByteArray(), fullName.toCharArray(), true);
          return new NameEnvironmentAnswer(classFileReader, null);
        }
        return null;
      } catch (IOException e) {
        throw new RuntimeException(e);
      } catch (ClassFormatException e) {
View Full Code Here

        byte[] classBytes = byteCode.getBytes();
        char[] loc = byteCode.getLocation().toCharArray();
        try {
          logger.log(TreeLogger.SPAM, "Found cached bytes", null);
          ClassFileReader cfr = new ClassFileReader(classBytes, loc);
          NameEnvironmentAnswer out = new NameEnvironmentAnswer(cfr, null);
          nameEnvironmentAnswerForTypeName.put(qname, out);
          return out;
        } catch (ClassFormatException e) {
          // Bad bytecode in the cache. Remove it from the cache.
          //
          String msg = "Bad bytecode for '" + qname + "'";
          compiler.problemReporter.abortDueToInternalError(msg);
          return null;
        }
      }

      // Didn't find it in the cache, so let's compile from source.
      // Strip off the inner types, if any
      //
      int pos = qname.indexOf('$');
      if (pos >= 0) {
        qname = qname.substring(0, pos);
      }
      CompilationUnitProvider cup;
      try {
        cup = sourceOracle.findCompilationUnit(logger, qname);
        if (cup != null) {
          logger.log(TreeLogger.SPAM, "Found type in compilation unit: "
              + cup.getLocation(), null);
          ICompilationUnitAdapter unit = new ICompilationUnitAdapter(cup);
          NameEnvironmentAnswer out = new NameEnvironmentAnswer(unit, null);
          nameEnvironmentAnswerForTypeName.put(qname, out);
          return out;
        } else {
          logger.log(TreeLogger.SPAM, "Not a known type", null);
          return null;
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

                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." );
                    }
                }
               
               
                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 ) {
                    throw new RuntimeException( "wrong class format",
View Full Code Here

                {
                    ICompilationUnit compilationUnit = new CompilationUnit( f.getAbsolutePath(),
                                                                            className,
                                                                            errors);

                    return new NameEnvironmentAnswer( compilationUnit, null );
                }

                String resourceName = className.replace( '.', '/' ) + ".class";

                InputStream is = classLoader.getResourceAsStream( resourceName );

                if ( is == null )
                {
                    return null;
                }

                byte[] classBytes = IOUtil.toByteArray( is );

                char[] fileName = className.toCharArray();

                ClassFileReader classFileReader = new ClassFileReader( classBytes, fileName, true );

                return new NameEnvironmentAnswer( classFileReader, null );
            }
            catch ( IOException e )
            {
                errors.add( handleError( className, -1, -1, e.getMessage() ) );
View Full Code Here

    public void cleanup() {
    }

    private NameEnvironmentAnswer findType(String fullName) {
      if (this.fullName.equals(fullName))
        return new NameEnvironmentAnswer(unit, null);

      try {
        InputStream is = getClass().getClassLoader()
            .getResourceAsStream(
                fullName.replace('.', '/') + ".class");
        if (is != null) {
          byte[] buffer = new byte[8192];
          int bytes = 0;
          ByteArrayOutputStream os = new ByteArrayOutputStream(
              buffer.length);
          while ((bytes = is.read(buffer, 0, buffer.length)) > 0)
            os.write(buffer, 0, bytes);

          os.flush();
          ClassFileReader classFileReader = new ClassFileReader(
              os.toByteArray(), fullName.toCharArray(), true);
          return new NameEnvironmentAnswer(classFileReader, null);
        }
        return null;
      } catch (IOException e) {
        throw new RuntimeException(e);
      } catch (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

    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

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.