home *** CD-ROM | disk | FTP | other *** search
- package sun.tools.java;
-
- import java.io.File;
- import java.io.IOException;
-
- public class Environment implements Constants {
- Environment env;
- String encoding;
- Object source;
- private static boolean debugging = System.getProperty("debug") != null;
-
- public Environment(Environment var1, Object var2) {
- if (var1 != null && var1.env != null && var1.getClass() == this.getClass()) {
- var1 = var1.env;
- }
-
- this.env = var1;
- this.source = var2;
- }
-
- public Environment() {
- this((Environment)null, (Object)null);
- }
-
- public ClassDeclaration getClassDeclaration(Identifier var1) {
- return this.env.getClassDeclaration(var1);
- }
-
- public final ClassDefinition getClassDefinition(Identifier var1) throws ClassNotFound {
- if (!var1.isInner()) {
- return this.getClassDeclaration(var1).getClassDefinition(this);
- } else {
- ClassDefinition var2 = this.getClassDefinition(var1.getTopName());
-
- FieldDefinition var5;
- label27:
- for(Identifier var3 = var1.getFlatName(); var3.isQualified(); var2 = var5.getInnerClass()) {
- var3 = var3.getTail();
- Identifier var4 = var3.getHead();
-
- for(var5 = var2.getFirstMatch(var4); var5 != null; var5 = var5.getNextMatch()) {
- if (var5.isInnerClass()) {
- continue label27;
- }
- }
-
- throw new ClassNotFound(Identifier.lookupInner(var2.getName(), var4));
- }
-
- return var2;
- }
- }
-
- public ClassDeclaration getClassDeclaration(Type var1) {
- return this.getClassDeclaration(var1.getClassName());
- }
-
- public final ClassDefinition getClassDefinition(Type var1) throws ClassNotFound {
- return this.getClassDefinition(var1.getClassName());
- }
-
- public boolean classExists(Identifier var1) {
- return this.env.classExists(var1);
- }
-
- public final boolean classExists(Type var1) {
- return !var1.isType(10) || this.classExists(var1.getClassName());
- }
-
- public Package getPackage(Identifier var1) throws IOException {
- return this.env.getPackage(var1);
- }
-
- public void loadDefinition(ClassDeclaration var1) {
- this.env.loadDefinition(var1);
- }
-
- public final Object getSource() {
- return this.source;
- }
-
- public boolean resolve(int var1, ClassDefinition var2, Type var3) {
- switch (var3.getTypeCode()) {
- case 9:
- return this.resolve(var1, var2, var3.getElementType());
- case 10:
- try {
- Identifier var12 = var3.getClassName();
- if (!var12.isQualified() && !var12.isInner() && !this.classExists(var12)) {
- this.resolve(var12);
- }
-
- ClassDefinition var10 = this.getClassDefinition(var3);
- if (!var2.canAccess(this, var10.getClassDeclaration())) {
- this.error(var1, "cant.access.class", var10);
- return true;
- }
-
- var10.noteUsedBy(var2, var1, this.env);
- return true;
- } catch (AmbiguousClass var8) {
- this.error(var1, "ambig.class", var8.name1, var8.name2);
- return false;
- } catch (ClassNotFound var9) {
- ClassNotFound var11 = var9;
-
- try {
- if (var11.name.isInner() && this.getPackage(var11.name.getTopName()).exists()) {
- this.env.error(var1, "class.and.package", var11.name.getTopName());
- }
- } catch (IOException var7) {
- this.env.error(var1, "io.exception", "package check");
- }
-
- this.error(var1, "class.not.found", var9.name, "type declaration");
- return false;
- }
- case 11:
- default:
- return true;
- case 12:
- boolean var4 = this.resolve(var1, var2, var3.getReturnType());
- Type[] var5 = var3.getArgumentTypes();
-
- for(int var6 = var5.length; var6-- > 0; var4 &= this.resolve(var1, var2, var5[var6])) {
- }
-
- return var4;
- }
- }
-
- public Type resolveNames(ClassDefinition var1, Type var2) {
- switch (var2.getTypeCode()) {
- case 9:
- var2 = Type.tArray(this.resolveNames(var1, var2.getElementType()));
- break;
- case 10:
- Identifier var11 = var2.getClassName();
- Identifier var12 = var1.resolveName(this, var11);
- if (var11 != var12) {
- var2 = Type.tClass(var12);
- }
- case 11:
- default:
- break;
- case 12:
- Type var3 = var2.getReturnType();
- Type var4 = this.resolveNames(var1, var3);
- Type[] var5 = var2.getArgumentTypes();
- Type[] var6 = new Type[var5.length];
- boolean var7 = var3 != var4;
- int var8 = var5.length;
-
- while(var8-- > 0) {
- Type var9 = var5[var8];
- Type var10 = this.resolveNames(var1, var9);
- var6[var8] = var10;
- if (var9 != var10) {
- var7 = true;
- }
- }
-
- if (var7) {
- var2 = Type.tMethod(var4, var6);
- }
- }
-
- return var2;
- }
-
- public Identifier resolveName(Identifier var1) {
- if (this.innerClasses() && var1.isQualified()) {
- Identifier var5 = this.resolveName(var1.getHead());
- if (!this.classExists(var5)) {
- return this.resolvePackageQualifiedName(var1);
- } else {
- try {
- return this.getClassDefinition(var5).resolveInnerClass(this, var1.getTail());
- } catch (ClassNotFound var3) {
- return Identifier.lookupInner(var5, var1.getTail());
- }
- }
- } else {
- try {
- return this.resolve(var1);
- } catch (ClassNotFound var4) {
- Imports var2 = this.getImports();
- return var2 != null ? var2.forceResolve(this, var1) : var1;
- }
- }
- }
-
- public final Identifier resolvePackageQualifiedName(Identifier var1) {
- if (!this.innerClasses()) {
- return var1;
- } else {
- Identifier var2;
- for(var2 = null; !this.classExists(var1); var1 = var1.getQualifier()) {
- if (!var1.isQualified()) {
- var1 = var2 == null ? var1 : Identifier.lookup(var1, var2);
- var2 = null;
- break;
- }
-
- Identifier var3 = var1.getName();
- var2 = var2 == null ? var3 : Identifier.lookup(var3, var2);
- }
-
- if (var2 != null) {
- var1 = Identifier.lookupInner(var1, var2);
- }
-
- return var1;
- }
- }
-
- public Identifier resolve(Identifier var1) throws ClassNotFound {
- return this.env == null ? var1 : this.env.resolve(var1);
- }
-
- public Imports getImports() {
- return this.env == null ? null : this.env.getImports();
- }
-
- public ClassDefinition makeClassDefinition(Environment var1, int var2, IdentifierToken var3, String var4, int var5, IdentifierToken var6, IdentifierToken[] var7, ClassDefinition var8) {
- return this.env == null ? null : this.env.makeClassDefinition(var1, var2, var3, var4, var5, var6, var7, var8);
- }
-
- public FieldDefinition makeFieldDefinition(Environment var1, int var2, ClassDefinition var3, String var4, int var5, Type var6, Identifier var7, IdentifierToken[] var8, IdentifierToken[] var9, Object var10) {
- return this.env == null ? null : this.env.makeFieldDefinition(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10);
- }
-
- public boolean isApplicable(FieldDefinition var1, Type[] var2) throws ClassNotFound {
- Type var3 = var1.getType();
- if (!var3.isType(12)) {
- return false;
- } else {
- Type[] var4 = var3.getArgumentTypes();
- if (var2.length != var4.length) {
- return false;
- } else {
- int var5 = var2.length;
-
- do {
- --var5;
- if (var5 < 0) {
- return true;
- }
- } while(this.isMoreSpecific(var2[var5], var4[var5]));
-
- return false;
- }
- }
- }
-
- public boolean isMoreSpecific(FieldDefinition var1, FieldDefinition var2) throws ClassNotFound {
- Type var3 = var1.getClassDeclaration().getType();
- Type var4 = var2.getClassDeclaration().getType();
- boolean var5 = this.isMoreSpecific(var3, var4) && this.isApplicable(var2, var1.getType().getArgumentTypes());
- return var5;
- }
-
- public boolean isMoreSpecific(Type var1, Type var2) throws ClassNotFound {
- return this.implicitCast(var1, var2);
- }
-
- public boolean implicitCast(Type var1, Type var2) throws ClassNotFound {
- if (var1 == var2) {
- return true;
- } else {
- int var3 = var2.getTypeCode();
- switch (var1.getTypeCode()) {
- case 1:
- if (var3 == 3) {
- return true;
- }
- case 2:
- case 3:
- if (var3 == 4) {
- return true;
- }
- case 4:
- if (var3 == 5) {
- return true;
- }
- case 5:
- if (var3 == 6) {
- return true;
- }
- case 6:
- if (var3 == 7) {
- return true;
- }
- case 7:
- default:
- return false;
- case 8:
- return var2.inMask(1792);
- case 9:
- if (!var2.isType(9)) {
- if (var2 != Type.tObject && var2 != Type.tCloneable && var2 != Type.tSerializable) {
- return false;
- }
-
- return true;
- } else {
- do {
- var1 = var1.getElementType();
- var2 = var2.getElementType();
- } while(var1.isType(9) && var2.isType(9));
-
- if (var1.inMask(1536) && var2.inMask(1536)) {
- return this.isMoreSpecific(var1, var2);
- } else {
- return var1.getTypeCode() == var2.getTypeCode();
- }
- }
- case 10:
- if (var3 == 10) {
- ClassDefinition var4 = this.getClassDefinition(var1);
- ClassDefinition var5 = this.getClassDefinition(var2);
- return var5.implementedBy(this, var4.getClassDeclaration());
- } else {
- return false;
- }
- }
- }
- }
-
- public boolean explicitCast(Type var1, Type var2) throws ClassNotFound {
- if (this.implicitCast(var1, var2)) {
- return true;
- } else if (var1.inMask(254)) {
- return var2.inMask(254);
- } else if (var1.isType(10) && var2.isType(10)) {
- ClassDefinition var5 = this.getClassDefinition(var1);
- ClassDefinition var6 = this.getClassDefinition(var2);
- if (var6.isFinal()) {
- return var5.implementedBy(this, var6.getClassDeclaration());
- } else if (var5.isFinal()) {
- return var6.implementedBy(this, var5.getClassDeclaration());
- } else {
- return var6.isInterface() || var5.isInterface() || var5.superClassOf(this, var6.getClassDeclaration());
- }
- } else {
- if (var2.isType(9)) {
- if (var1.isType(9)) {
- Type var3 = var1.getElementType();
-
- Type var4;
- for(var4 = var2.getElementType(); var3.getTypeCode() == 9 && var4.getTypeCode() == 9; var4 = var4.getElementType()) {
- var3 = var3.getElementType();
- }
-
- if (var3.inMask(1536) && var4.inMask(1536)) {
- return this.explicitCast(var3, var4);
- }
- } else if (var1 == Type.tObject || var1 == Type.tCloneable || var1 == Type.tSerializable) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public int getFlags() {
- return this.env.getFlags();
- }
-
- public final boolean debug() {
- return (this.getFlags() & 8) != 0;
- }
-
- public final boolean optimize() {
- return (this.getFlags() & 16) != 0;
- }
-
- public final boolean verbose() {
- return (this.getFlags() & 1) != 0;
- }
-
- public final boolean dump() {
- return (this.getFlags() & 2) != 0;
- }
-
- public final boolean warnings() {
- return (this.getFlags() & 4) != 0;
- }
-
- public final boolean dependencies() {
- return (this.getFlags() & 32) != 0;
- }
-
- public final boolean print_dependencies() {
- return (this.getFlags() & 1024) != 0;
- }
-
- public final boolean innerClasses() {
- return (this.getFlags() & 256) != 0;
- }
-
- public final boolean deprecation() {
- return (this.getFlags() & 512) != 0;
- }
-
- public void innerClassesUsed(int var1) {
- if (!this.innerClasses()) {
- this.error(var1, "no.inner.classes");
- }
- }
-
- public void shutdown() {
- if (this.env != null) {
- this.env.shutdown();
- }
-
- }
-
- public void error(Object var1, int var2, String var3, Object var4, Object var5, Object var6) {
- this.env.error(var1, var2, var3, var4, var5, var6);
- }
-
- public final void error(int var1, String var2, Object var3, Object var4, Object var5) {
- this.error(this.source, var1, var2, var3, var4, var5);
- }
-
- public final void error(int var1, String var2, Object var3, Object var4) {
- this.error(this.source, var1, var2, var3, var4, (Object)null);
- }
-
- public final void error(int var1, String var2, Object var3) {
- this.error(this.source, var1, var2, var3, (Object)null, (Object)null);
- }
-
- public final void error(int var1, String var2) {
- this.error(this.source, var1, var2, (Object)null, (Object)null, (Object)null);
- }
-
- public void output(String var1) {
- this.env.output(var1);
- }
-
- public static void debugOutput(Object var0) {
- if (debugging) {
- System.out.println(var0.toString());
- }
-
- }
-
- public void setCharacterEncoding(String var1) {
- this.encoding = var1;
- }
-
- public String getCharacterEncoding() {
- return this.encoding;
- }
-
- public final boolean coverage() {
- return (this.getFlags() & 64) != 0;
- }
-
- public final boolean covdata() {
- return (this.getFlags() & 128) != 0;
- }
-
- public File getcovFile() {
- return this.env.getcovFile();
- }
- }
-