You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2006/11/24 17:29:00 UTC
svn commit: r478907 [2/2] - in
/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200:
./ bytecode/
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFile.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFile.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFile.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+//NOTE: Do not extract strings as messages; this code is still a work-in-progress
+//NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+
+public class ClassFile {
+ public int major;
+ public int minor;
+ private int magic = 0xCAFEBABE;
+ public ClassConstantPool pool = new ClassConstantPool();
+ public int accessFlags;
+ public int thisClass;
+ public int superClass;
+ public int[] interfaces;
+ public ClassFileEntry[] fields;
+ public ClassFileEntry[] methods;
+ public Attribute[] attributes;
+ public void write(DataOutputStream dos) throws IOException {
+ dos.writeInt(magic);
+ dos.writeShort(minor);
+ dos.writeShort(major);
+ dos.writeShort(pool.size()+1);
+ for(int i=1;i<=pool.size();i++) {
+ ConstantPoolEntry entry;
+ (entry = (ConstantPoolEntry)pool.get(i)).doWrite(dos);
+ // Doubles and longs take up two spaces in the pool, but only one gets written
+ if (entry.getTag() == ConstantPoolEntry.CP_Double || entry.getTag() == ConstantPoolEntry.CP_Long)
+ i++;
+ };
+ dos.writeShort(accessFlags);
+ dos.writeShort(thisClass);
+ dos.writeShort(superClass);
+ dos.writeShort(interfaces.length);
+ for(int i=0;i<interfaces.length;i++) {
+ dos.writeShort(interfaces[i]);
+ }
+ dos.writeShort(fields.length);
+ for(int i=0;i<fields.length;i++) {
+ fields[i].write(dos);
+ }
+ dos.writeShort(methods.length);
+ for(int i=0;i<methods.length;i++) {
+ methods[i].write(dos);
+ }
+ dos.writeShort(attributes.length);
+ for(int i=0;i<attributes.length;i++) {
+ attributes[i].write(dos);
+ }
+ }
+}
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFileEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFileEntry.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFileEntry.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ClassFileEntry.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+
+// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+// NOTE: Do not extract strings as messages; this code is still a
+// work-in-progress
+// NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public abstract class ClassFileEntry {
+ private static final ClassFileEntry[] NONE = new ClassFileEntry[0];
+ private boolean resolved;
+
+ public abstract boolean equals(Object arg0);
+
+ protected ClassFileEntry[] getNestedClassFileEntries() {
+ return NONE;
+ }
+
+ public abstract int hashCode();
+
+ /**
+ * Allows the constant pool entries to resolve their nested entries
+ *
+ * @param pool
+ */
+ protected void resolve(ClassConstantPool pool) {
+ resolved = true;
+ }
+
+ public abstract String toString();
+
+ public final void write(DataOutputStream dos) throws IOException {
+ if(!resolved)
+ throw new IllegalStateException("Entry has not been resolved");
+ doWrite(dos);
+ }
+
+ protected abstract void doWrite(DataOutputStream dos) throws IOException;
+
+}
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantPoolEntry.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantPoolEntry.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantPoolEntry.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+
+// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5
+// NOTE: Do not extract strings as messages; this code is still a
+// work-in-progress
+// NOTE: Also, don't get rid of 'else' statements for the hell of it ...
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+
+/**
+ * @author alex
+ *
+ */
+public abstract class ConstantPoolEntry extends ClassFileEntry {
+ public static final byte CP_Class = 7;
+
+ public static final byte CP_Double = 6;
+
+ public static final byte CP_Fieldref = 9;
+
+ public static final byte CP_Float = 4;
+
+ public static final byte CP_Integer = 3;
+
+ /*
+ * class MemberRef extends ConstantPoolEntry { private int index;
+ *
+ * Class(String name) { super(CP_Class); index = pool.indexOf(name); }
+ *
+ * void writeBody(DataOutputStream dos) throws IOException {
+ * dos.writeShort(index); } }
+ */
+
+ public static final byte CP_InterfaceMethodref = 11;
+
+ public static final byte CP_Long = 5;
+
+ public static final byte CP_Methodref = 10;
+
+ public static final byte CP_NameAndType = 12;
+
+ public static final byte CP_String = 8;
+
+ public static final byte CP_UTF8 = 1;
+
+ byte tag;
+
+ ConstantPoolEntry(byte tag) {
+ this.tag = tag;
+ }
+
+ public abstract boolean equals(Object obj);
+
+ public byte getTag() {
+ return tag;
+ }
+
+ public abstract int hashCode();
+
+ public void doWrite(DataOutputStream dos) throws IOException {
+ dos.writeByte(tag);
+ writeBody(dos);
+ }
+
+ protected abstract void writeBody(DataOutputStream dos) throws IOException;
+}
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantValueAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantValueAttribute.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantValueAttribute.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ConstantValueAttribute.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class ConstantValueAttribute extends Attribute {
+ private int constantIndex;
+
+ private ClassFileEntry entry;
+
+ public ConstantValueAttribute(Object value) {
+ super("ConstantValue"); //$NON-NLS-1$
+ if (value instanceof java.lang.Integer) {
+ this.entry = new CPInteger((Integer) value);
+ } else if (value instanceof java.lang.Long) {
+ this.entry = new CPLong((Long) value);
+ } else if (value instanceof java.lang.Float) {
+ this.entry = new CPFloat((Float) value);
+ } else if (value instanceof java.lang.Double) {
+ this.entry = new CPDouble((Double) value);
+ } else if (value instanceof java.lang.String) {
+ this.entry = new CPString((String) value);
+ } else {
+ throw new Error("Oops, I've not done it again");
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (this.getClass() != obj.getClass())
+ return false;
+ final ConstantValueAttribute other = (ConstantValueAttribute) obj;
+ if (entry == null) {
+ if (other.entry != null)
+ return false;
+ } else if (!entry.equals(other.entry))
+ return false;
+ return true;
+ }
+
+ @Override
+ protected int getLength() {
+ return 2;
+ }
+
+ protected ClassFileEntry[] getNestedClassFileEntries() {
+ return new ClassFileEntry[] { getAttributeName(), entry };
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + ((entry == null) ? 0 : entry.hashCode());
+ return result;
+ }
+
+ protected void resolve(ClassConstantPool pool) {
+ super.resolve(pool);
+ entry.resolve(pool);
+ this.constantIndex = pool.indexOf(entry);
+ }
+
+ public String toString() {
+ return "Constant:" + entry;
+ }
+
+ @Override
+ protected void writeBody(DataOutputStream dos) throws IOException {
+ dos.writeShort(constantIndex);
+ }
+
+}
\ No newline at end of file
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ExceptionsAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ExceptionsAttribute.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ExceptionsAttribute.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/ExceptionsAttribute.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class ExceptionsAttribute extends Attribute {
+
+ private transient int[] exceptionIndexes;
+
+ private CPClass[] exceptions;
+
+ public ExceptionsAttribute(CPClass[] exceptions) {
+ super("Exceptions"); //$NON-NLS-1$
+ this.exceptions = exceptions;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final ExceptionsAttribute other = (ExceptionsAttribute) obj;
+ if (!Arrays.equals(exceptions, other.exceptions))
+ return false;
+ return true;
+ }
+
+ @Override
+ protected int getLength() {
+ return 2 + 2 * exceptions.length;
+ }
+
+ protected ClassFileEntry[] getNestedClassFileEntries() {
+ ClassFileEntry[] result = new ClassFileEntry[exceptions.length+1];
+ for (int i = 0; i < exceptions.length; i++) {
+ result[i] = exceptions[i];
+ }
+ result[exceptions.length] = getAttributeName();
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + Arrays.hashCode(exceptions);
+ return result;
+ }
+
+ protected void resolve(ClassConstantPool pool) {
+ super.resolve(pool);
+ exceptionIndexes = new int[exceptions.length];
+ for (int i = 0; i < exceptions.length; i++) {
+ exceptions[i].resolve(pool);
+ exceptionIndexes[i] = pool.indexOf(exceptions[i]);
+ }
+ }
+
+ public String toString() {
+ return "Exceptions:" + exceptions;
+ }
+
+ @Override
+ protected void writeBody(DataOutputStream dos) throws IOException {
+ dos.writeShort(exceptionIndexes.length);
+ for (int i = 0; i < exceptionIndexes.length; i++) {
+ dos.writeShort(exceptionIndexes[i]);
+ }
+ }
+
+}
\ No newline at end of file
Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/SourceFileAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/SourceFileAttribute.java?view=auto&rev=478907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/SourceFileAttribute.java (added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/pack200/bytecode/SourceFileAttribute.java Fri Nov 24 08:28:57 2006
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.archive.internal.pack200.bytecode;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+
+public class SourceFileAttribute extends Attribute {
+ private CPUTF8 name;
+
+ private int nameIndex;
+
+ public SourceFileAttribute(String name) {
+ super("SourceFile"); //$NON-NLS-1$
+ this.name = new CPUTF8(name);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (this.getClass() != obj.getClass())
+ return false;
+ final SourceFileAttribute other = (SourceFileAttribute) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ @Override
+ protected int getLength() {
+ return 2;
+ }
+
+ protected ClassFileEntry[] getNestedClassFileEntries() {
+ return new ClassFileEntry[] { getAttributeName(), name };
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = super.hashCode();
+ result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ protected void resolve(ClassConstantPool pool) {
+ super.resolve(pool);
+ nameIndex = pool.indexOf(name);
+ }
+
+ public String toString() {
+ return "SourceFile: " + name;
+ }
+
+ protected void writeBody(DataOutputStream dos) throws IOException {
+ dos.writeShort(nameIndex);
+ }
+}
\ No newline at end of file