Package sun.tools.java

Examples of sun.tools.java.Package


    id = id.getTopName();
      Type t = Type.tClass(id);
      try {
    ClassDeclaration c = (ClassDeclaration)classes.get(t);
    if (c == null) {
        Package pkg = getPackage(id.getQualifier());
        return pkg.getBinaryFile(id.getName()) != null;
    }
    return c.getName().equals(id);
      } catch (IOException e) {
    return false;
      }
View Full Code Here


      }
      return c;
  }

  public Package getPackage(Identifier pkg) throws IOException {
      Package p = (Package)packages.get(pkg);
      if (p == null) {
    p = new Package(noPath, path, pkg);
    packages.put(pkg, p);
      }
      return p;
  }
View Full Code Here

   */
  public void loadDefinition(ClassDeclaration c) {
      Identifier id = c.getName();
      if (c.getStatus() != CS_UNDEFINED)
    throw new IllegalArgumentException("No file for: " + id);
      Package pkg;
      try {
    pkg = getPackage(id.getQualifier());
      } catch (IOException e) {
    throw new IllegalArgumentException("IOException: " +
               e.getMessage());
      }
      ClassFile file = pkg.getBinaryFile(id.getName());
      if (file == null)
    throw new IllegalArgumentException("No file for: " +
               id.getName());
      BinaryClass bc;
      try {
View Full Code Here

        switch (c.getStatus()) {
          case CS_UNDEFINED: {
            if (tracing)
                dtEvent("loadDefinition: STATUS IS UNDEFINED");
            Identifier nm = c.getName();
            Package pkg;
            try {
                pkg = getPackage(nm.getQualifier());
            } catch (IOException e) {
                // If we can't get at the package, then we'll just
                // have to set the class to be not found.
                c.setDefinition(null, CS_NOTFOUND);

                error(0, "io.exception", c);
                if (tracing)
                    dtExit("loadDefinition: IO EXCEPTION (package)");
                return;
            }
            ClassFile binfile = pkg.getBinaryFile(nm.getName());
            if (binfile == null) {
                // must be source, there is no binary
                c.setDefinition(null, CS_SOURCE);
                if (tracing)
                    dtExit("loadDefinition: MUST BE SOURCE (no binary) " +
                           c.getName());
                return;
            }

            ClassFile srcfile = pkg.getSourceFile(nm.getName());
            if (srcfile == null) {
                if (tracing)
                    dtEvent("loadDefinition: NO SOURCE " + c.getName());
                BinaryClass bc = null;
                try {
                    bc = loadFile(binfile);
                } catch (IOException e) {
                    // If we can't access the binary, set the class to
                    // be not found.  (bug id 4030497)
                    c.setDefinition(null, CS_NOTFOUND);

                    error(0, "io.exception", binfile);
                    if (tracing)
                        dtExit("loadDefinition: IO EXCEPTION (binary)");
                    return;
                }
                if ((bc != null) && !bc.getName().equals(nm)) {
                    error(0, "wrong.class", binfile.getPath(), c, bc);
                    bc = null;
                    if (tracing)
                        dtEvent("loadDefinition: WRONG CLASS (binary)");
                }
                if (bc == null) {
                    // no source nor binary found
                    c.setDefinition(null, CS_NOTFOUND);
                    if (tracing)
                        dtExit("loadDefinition: NOT FOUND (source or binary)");
                    return;
                }

                // Couldn't find the source, try the one mentioned in the binary
                if (bc.getSource() != null) {
                    srcfile = new ClassFile(new File((String)bc.getSource()));
                    // Look for the source file
                    srcfile = pkg.getSourceFile(srcfile.getName());
                    if ((srcfile != null) && srcfile.exists()) {
                        if (tracing)
                            dtEvent("loadDefinition: FILENAME IN BINARY " +
                                    srcfile);
                        if (srcfile.lastModified() > binfile.lastModified()) {
                            // must be source, it is newer than the binary
                            c.setDefinition(bc, CS_SOURCE);
                            if (tracing)
                                dtEvent("loadDefinition: SOURCE IS NEWER " +
                                        srcfile);
                            bc.loadNested(this);
                            if (tracing)
                                dtExit("loadDefinition: MUST BE SOURCE " +
                                       c.getName());
                            return;
                        }
                        if (dependencies()) {
                            c.setDefinition(bc, CS_UNDECIDED);
                            if (tracing)
                                dtEvent("loadDefinition: UNDECIDED " +
                                        c.getName());
                        } else {
                            c.setDefinition(bc, CS_BINARY);
                            if (tracing)
                                dtEvent("loadDefinition: MUST BE BINARY " +
                                        c.getName());
                        }
                        bc.loadNested(this);
                        if (tracing)
                            dtExit("loadDefinition: EXIT " +
                                   c.getName() + ", status " + c.getStatus());
                        return;
                    }
                }

                // It must be binary, there is no source
                c.setDefinition(bc, CS_BINARY);
                if (tracing)
                    dtEvent("loadDefinition: MUST BE BINARY (no source) " +
                                     c.getName());
                bc.loadNested(this);
                if (tracing)
                    dtExit("loadDefinition: EXIT " +
                           c.getName() + ", status " + c.getStatus());
                return;
            }
            BinaryClass bc = null;
            try {
                if (srcfile.lastModified() > binfile.lastModified()) {
                    // must be source, it is newer than the binary
                    c.setDefinition(null, CS_SOURCE);
                    if (tracing)
                        dtEvent("loadDefinition: MUST BE SOURCE (younger than binary) " +
                                c.getName());
                    return;
                }
                bc = loadFile(binfile);
            } catch (IOException e) {
                error(0, "io.exception", binfile);
                if (tracing)
                    dtEvent("loadDefinition: IO EXCEPTION (binary)");
            }
            if ((bc != null) && !bc.getName().equals(nm)) {
                error(0, "wrong.class", binfile.getPath(), c, bc);
                bc = null;
                if (tracing)
                    dtEvent("loadDefinition: WRONG CLASS (binary)");
            }
            if (bc != null) {
                Identifier name = bc.getName();
                if (name.equals(c.getName())) {
                    if (dependencies()) {
                        c.setDefinition(bc, CS_UNDECIDED);
                        if (tracing)
                            dtEvent("loadDefinition: UNDECIDED " + name);
                    } else {
                        c.setDefinition(bc, CS_BINARY);
                        if (tracing)
                            dtEvent("loadDefinition: MUST BE BINARY " + name);
                    }
                } else {
                    c.setDefinition(null, CS_NOTFOUND);
                    if (tracing)
                        dtEvent("loadDefinition: NOT FOUND (source or binary)");
                    if (dependencies()) {
                        getClassDeclaration(name).setDefinition(bc, CS_UNDECIDED);
                        if (tracing)
                            dtEvent("loadDefinition: UNDECIDED " + name);
                    } else {
                        getClassDeclaration(name).setDefinition(bc, CS_BINARY);
                        if (tracing)
                            dtEvent("loadDefinition: MUST BE BINARY " + name);
                    }
                }
            } else {
                c.setDefinition(null, CS_NOTFOUND);
                if (tracing)
                    dtEvent("loadDefinition: NOT FOUND (source or binary)");
            }
            if (bc != null && bc == c.getClassDefinition())
                bc.loadNested(this);
            if (tracing) dtExit("loadDefinition: EXIT " +
                                c.getName() + ", status " + c.getStatus());
            return;
          }

          case CS_UNDECIDED: {
            if (tracing) dtEvent("loadDefinition: STATUS IS UNDECIDED");
            Hashtable tab = new Hashtable();
            if (!needsCompilation(tab, c)) {
                // All undecided classes that this class depends on must be binary
                for (Enumeration e = tab.keys() ; e.hasMoreElements() ; ) {
                    ClassDeclaration dep = (ClassDeclaration)e.nextElement();
                    if (dep.getStatus() == CS_UNDECIDED) {
                        // must be binary, dependencies need compilation
                        dep.setDefinition(dep.getClassDefinition(), CS_BINARY);
                        if (tracing)
                            dtEvent("loadDefinition: MUST BE BINARY " + dep);
                    }
                }
            }
            if (tracing) dtExit("loadDefinition: EXIT " +
                                c.getName() + ", status " + c.getStatus());
            return;
          }

          case CS_SOURCE: {
            if (tracing) dtEvent("loadDefinition: STATUS IS SOURCE");
            ClassFile srcfile = null;
            Package pkg = null;
            if (c.getClassDefinition() != null) {
                // Use the source file name from the binary class file
                try {
                    pkg = getPackage(c.getName().getQualifier());
                    srcfile = pkg.getSourceFile((String)c.getClassDefinition().getSource());
                } catch (IOException e) {
                    error(0, "io.exception", c);
                    if (tracing)
                        dtEvent("loadDefinition: IO EXCEPTION (package)");
                }
                if (srcfile == null) {
                    String fn = (String)c.getClassDefinition().getSource();
                    srcfile = new ClassFile(new File(fn));
                }
            } else {
                // Get a source file name from the package
                Identifier nm = c.getName();
                try {
                    pkg = getPackage(nm.getQualifier());
                    srcfile = pkg.getSourceFile(nm.getName());
                } catch (IOException e)  {
                    error(0, "io.exception", c);
                    if (tracing)
                        dtEvent("loadDefinition: IO EXCEPTION (package)");
                }
View Full Code Here

TOP

Related Classes of sun.tools.java.Package

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.