harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r727042 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: ClassBands.java MetadataBandGroup.java Segment.java
Date Tue, 16 Dec 2008 13:01:41 GMT
Author: sjanuary
Date: Tue Dec 16 05:01:40 2008
New Revision: 727042

URL: http://svn.apache.org/viewvc?rev=727042&view=rev
Log:
Pack200 - initial support for annotation bands

Added:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=727042&r1=727041&r2=727042&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
Tue Dec 16 05:01:40 2008
@@ -45,6 +45,7 @@
     private final int[] major_versions;
 
     private final long[] class_flags;
+    private int[] class_attr_calls;
     private final List classSourceFile = new ArrayList();
     private final List classEnclosingMethodClass = new ArrayList();
     private final List classEnclosingMethodDesc = new ArrayList();
@@ -56,12 +57,14 @@
     private final int[] class_field_count;
     private final CPNameAndType[][] field_descr;
     private final long[][] field_flags;
+    private int[] field_attr_calls;
     private final List fieldConstantValueKQ = new ArrayList();
     private final List fieldSignature = new ArrayList();
 
     private final int[] class_method_count;
     private final CPNameAndType[][] method_descr;
     private final long[][] method_flags;
+    private int[] method_attr_calls;
     private final List methodSignature = new ArrayList();
     private final List methodExceptionNumber = new ArrayList();
     private final List methodExceptionClasses = new ArrayList();
@@ -91,6 +94,16 @@
     private final List codeLocalVariableTypeTableTypeRS = new ArrayList();
     private final List codeLocalVariableTypeTableSlot = new ArrayList();
 
+    private final MetadataBandGroup class_RVA_bands;
+    private final MetadataBandGroup class_RIA_bands;
+    private final MetadataBandGroup field_RVA_bands;
+    private final MetadataBandGroup field_RIA_bands;
+    private final MetadataBandGroup method_RVA_bands;
+    private final MetadataBandGroup method_RIA_bands;
+    private final MetadataBandGroup method_RVPA_bands;
+    private final MetadataBandGroup method_RIPA_bands;
+    private final MetadataBandGroup method_AD_bands;
+
     private final List tempFieldFlags = new ArrayList();
     private final List tempFieldDesc = new ArrayList();
     private final List tempMethodFlags = new ArrayList();
@@ -121,6 +134,16 @@
         // minor_versions = new int[numClasses];
         major_versions = new int[numClasses];
         class_flags = new long[numClasses];
+
+        class_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
+        class_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
+        field_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
+        field_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
+        method_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_METHOD,
cpBands);
+        method_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_METHOD,
cpBands);
+        method_RVPA_bands = new MetadataBandGroup("RVPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands);
+        method_RIPA_bands = new MetadataBandGroup("RIPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands);
+        method_AD_bands = new MetadataBandGroup("AD", MetadataBandGroup.CONTEXT_METHOD, cpBands);
     }
 
     private int index = 0;
@@ -156,7 +179,7 @@
     public void currentClassReferencesInnerClass(CPClass inner) {
         if(!(index >= class_this.length)) {
             CPClass currentClass = class_this[index];
-            if(currentClass != null && !currentClass.equals(inner)) {
+            if(currentClass != null && !currentClass.equals(inner) && !isInnerClassOf(currentClass,
inner)) {
                 Set referencedInnerClasses = (Set)classReferencesInnerClass.get(currentClass);
                 if(referencedInnerClasses == null) {
                     referencedInnerClasses = new HashSet();
@@ -167,8 +190,18 @@
         }
     }
 
+    private boolean isInnerClassOf(CPClass possibleInner, CPClass possibleOuter) {
+        String currentClassName = possibleInner.toString();
+        if(possibleInner.isInnerClass()) {
+            String superClassName = currentClassName.substring(0, currentClassName.lastIndexOf('$'));
+            return superClassName.equals(possibleOuter.toString());
+        }
+        return false;
+    }
+
     public void addField(int flags, String name, String desc, String signature,
             Object value) {
+        flags = flags & 0xFFFF;
         CPMethodOrField field = cpBands.addCPField(class_this[index], name,
                 desc);
         tempFieldDesc.add(field.getDesc());
@@ -284,6 +317,40 @@
                 classInnerClassesNameRUN.add(icTuple.N);
             }
         }
+        // Calculate any backwards calls from metadata bands
+        List classAttrCalls = new ArrayList();
+        List fieldAttrCalls = new ArrayList();
+        List methodAttrCalls = new ArrayList();
+        if(class_RVA_bands.hasContent()) {
+            classAttrCalls.add(new Integer(class_RVA_bands.numBackwardsCalls()));
+        }
+        if(class_RIA_bands.hasContent()) {
+            classAttrCalls.add(new Integer(class_RIA_bands.numBackwardsCalls()));
+        }
+        if(field_RVA_bands.hasContent()) {
+            fieldAttrCalls.add(new Integer(field_RVA_bands.numBackwardsCalls()));
+        }
+        if(field_RIA_bands.hasContent()) {
+            fieldAttrCalls.add(new Integer(field_RIA_bands.numBackwardsCalls()));
+        }
+        if(method_RVA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RVA_bands.numBackwardsCalls()));
+        }
+        if(method_RIA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RIA_bands.numBackwardsCalls()));
+        }
+        if(method_RVPA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RVPA_bands.numBackwardsCalls()));
+        }
+        if(method_RIPA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RIPA_bands.numBackwardsCalls()));
+        }
+        if(method_AD_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_AD_bands.numBackwardsCalls()));
+        }
+        class_attr_calls = listToArray(classAttrCalls);
+        field_attr_calls = listToArray(fieldAttrCalls);
+        method_attr_calls = listToArray(methodAttrCalls);
     }
 
     public void pack(OutputStream out) throws IOException, Pack200Exception {
@@ -353,28 +420,44 @@
             Pack200Exception {
         out.write(encodeFlags("field_flags", field_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_field_flags_hi()));
+//        *field_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *field_attr_indexes :UNSIGNED5 [SUM(*field_attr_count)]
+        out.write(encodeBandInt("field_attr_calls", field_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("fieldConstantValueKQ",
                 cpEntryListToArray(fieldConstantValueKQ), Codec.UNSIGNED5));
         out.write(encodeBandInt("fieldSignature",
                 cpEntryListToArray(fieldSignature), Codec.UNSIGNED5));
+        field_RVA_bands.pack(out);
+        field_RIA_bands.pack(out);
     }
 
     private void writeMethodAttributeBands(OutputStream out)
             throws IOException, Pack200Exception {
         out.write(encodeFlags("method_flags", method_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_method_flags_hi()));
+//        *method_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *method_attr_indexes :UNSIGNED5 [SUM(*method_attr_count)]
+        out.write(encodeBandInt("method_attr_calls", method_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionNumber",
                 listToArray(methodExceptionNumber), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionClasses",
                 cpEntryListToArray(methodExceptionClasses), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodSignature",
                 cpEntryListToArray(methodSignature), Codec.UNSIGNED5));
+        method_RVA_bands.pack(out);
+        method_RIA_bands.pack(out);
+        method_RVPA_bands.pack(out);
+        method_RIPA_bands.pack(out);
+        method_AD_bands.pack(out);
     }
 
     private void writeClassAttributeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeFlags("class_flags", class_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_class_flags_hi()));
+//        *class_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *class_attr_indexes :UNSIGNED5 [SUM(*class_attr_count)]
+        out.write(encodeBandInt("class_attr_calls", class_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("classSourceFile",
                 cpEntryOrNullListToArray(classSourceFile), Codec.UNSIGNED5));
         out.write(encodeBandInt("class_enclosing_method_RC",
@@ -385,6 +468,8 @@
                 Codec.UNSIGNED5));
         out.write(encodeBandInt("class_Signature_RS",
                 cpEntryListToArray(classSignature), Codec.UNSIGNED5));
+        class_RVA_bands.pack(out);
+        class_RIA_bands.pack(out);
         out.write(encodeBandInt("class_InnerClasses_N", class_InnerClasses_N, Codec.UNSIGNED5));
         out.write(encodeBandInt("class_InnerClasses_RC", getInts(class_InnerClasses_RC),
Codec.UNSIGNED5));
         out.write(encodeBandInt("class_InnerClasses_F", class_InnerClasses_F, Codec.UNSIGNED5));
@@ -443,8 +528,7 @@
         out.write(encodeBandInt("code_LocalVariableTable_bci_P",
                 listToArray(codeLocalVariableTableBciP), Codec.BCI5));
         out.write(encodeBandInt("code_LocalVariableTable_span_O",
-                listToArray(codeLocalVariableTableSpanO), Codec.BRANCH5)); // TODO:
-                                                                            // Difference
+                listToArray(codeLocalVariableTableSpanO), Codec.BRANCH5));
         out.write(encodeBandInt("code_LocalVariableTable_name_RU",
                 cpEntryListToArray(codeLocalVariableTableNameRU),
                 Codec.UNSIGNED5));
@@ -743,4 +827,99 @@
     public boolean isAnySyntheticMethods() {
         return anySyntheticMethods;
     }
+
+    public void addParameterAnnotation(int parameter, String desc,
+            boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS,
List nestNameRU, List nestPairN) {
+        if(visible) {
+            method_RVPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            if((flag.intValue() & (1<<23)) != 0) {
+                method_RVPA_bands.incrementAnnoN();
+            } else {
+                method_RVPA_bands.newEntryInAnnoN();
+            }
+            tempMethodFlags.add(new Integer(flag.intValue() | (1<<23)));
+        } else {
+            method_RIPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            if((flag.intValue() & (1<<24)) != 0) {
+                method_RIPA_bands.incrementAnnoN();
+            } else {
+                method_RIPA_bands.newEntryInAnnoN();
+            }
+            tempMethodFlags.add(new Integer(flag.intValue() | (1<<24)));
+        }
+    }
+
+    public void addAnnotation(int context, String desc, boolean visible, List nameRU, List
t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
+        switch (context) {
+        case MetadataBandGroup.CONTEXT_CLASS:
+            if(visible) {
+                class_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                if((class_flags[index] & (1<<21)) != 0) {
+                    class_RVA_bands.incrementAnnoN();
+                } else {
+                    class_RVA_bands.newEntryInAnnoN();
+                    class_flags[index] = class_flags[index] | (1<<21);
+                }
+            } else {
+                class_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                if((class_flags[index] & (1<<22)) != 0) {
+                    class_RIA_bands.incrementAnnoN();
+                } else {
+                    class_RIA_bands.newEntryInAnnoN();
+                    class_flags[index] = class_flags[index] | (1<<22);
+                }
+            }
+            break;
+        case MetadataBandGroup.CONTEXT_FIELD:
+            if(visible) {
+                field_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                Long flag = (Long) tempFieldFlags.remove(tempFieldFlags.size() - 1);
+                if((flag.intValue() & (1<<21)) != 0) {
+                    field_RVA_bands.incrementAnnoN();
+                } else {
+                    field_RVA_bands.newEntryInAnnoN();
+                }
+                tempFieldFlags.add(new Long(flag.intValue() | (1<<21)));
+            } else {
+                field_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                Long flag = (Long) tempFieldFlags.remove(tempFieldFlags.size() - 1);
+                if((flag.intValue() & (1<<22)) != 0) {
+                    field_RIA_bands.incrementAnnoN();
+                } else {
+                    field_RIA_bands.newEntryInAnnoN();
+                }
+                tempFieldFlags.add(new Long(flag.intValue() | (1<<22)));
+            }
+            break;
+        case MetadataBandGroup.CONTEXT_METHOD:
+            if(visible) {
+                method_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+                if((flag.intValue() & (1<<21)) != 0) {
+                    method_RVA_bands.incrementAnnoN();
+                } else {
+                    method_RVA_bands.newEntryInAnnoN();
+                }
+                tempMethodFlags.add(new Long(flag.intValue() | (1<<21)));
+            } else {
+                method_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS,
nestNameRU, nestPairN);
+                Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+                if((flag.intValue() & (1<<22)) != 0) {
+                    method_RIA_bands.incrementAnnoN();
+                } else {
+                    method_RIA_bands.newEntryInAnnoN();
+                }
+                tempMethodFlags.add(new Long(flag.intValue() | (1<<22)));
+            }
+            break;
+        }
+    }
+
+    public void addAnnotationDefault(List nameRU, List t, List values, List caseArrayN, List
nestTypeRS, List nestNameRU, List nestPairN) {
+        method_AD_bands.addAnnotation(null, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU,
nestPairN);
+        Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+        tempMethodFlags.add(new Integer(flag.intValue() | (1<<25)));
+    }
 }

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java?rev=727042&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
Tue Dec 16 05:01:40 2008
@@ -0,0 +1,190 @@
+/*
+ * 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.pack200;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A group of metadata (annotation) bands, such as class_RVA_bands,
+ * method_AD_bands etc.
+ */
+public class MetadataBandGroup extends BandSet {
+
+    public static final int CONTEXT_CLASS = 0;
+    public static final int CONTEXT_FIELD = 1;
+    public static final int CONTEXT_METHOD = 2;
+
+    private final String type;
+    private int numBackwardsCalls = 0;
+
+    public List param_NB = new ArrayList(); // TODO: Lazy instantiation?
+    public List anno_N = new ArrayList();
+    public List type_RS = new ArrayList();
+    public List pair_N = new ArrayList();
+    public List name_RU = new ArrayList();
+    public List T = new ArrayList();
+    public List caseI_KI = new ArrayList();
+    public List caseD_KD = new ArrayList();
+    public List caseF_KF = new ArrayList();
+    public List caseJ_KJ = new ArrayList();
+    public List casec_RS = new ArrayList();
+    public List caseet_RS = new ArrayList();
+    public List caseec_RU = new ArrayList();
+    public List cases_RU = new ArrayList();
+    public List casearray_N = new ArrayList();
+    public List nesttype_RS = new ArrayList();
+    public List nestpair_N = new ArrayList();
+    public List nestname_RU = new ArrayList();
+
+    private final CpBands cpBands;
+    private final int context;
+
+    /**
+     * Constructs a new MetadataBandGroup
+     * @param type - must be either AD, RVA, RIA, RVPA or RIPA.
+     */
+    public MetadataBandGroup(String type, int context, CpBands cpBands) {
+        this.type = type;
+        this.cpBands = cpBands;
+        this.context = context;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.BandSet#pack(java.io.OutputStream)
+     */
+    public void pack(OutputStream out) throws IOException, Pack200Exception {
+        if(hasContent()) {
+            String contextStr;
+            if(context == CONTEXT_CLASS) {
+                contextStr = "Class";
+            } else if (context == CONTEXT_FIELD) {
+                contextStr = "Field";
+            } else {
+                contextStr = "Method";
+            }
+            if(!type.equals("AD")) {
+                out.write(encodeBandInt(contextStr + "_" + type + " anno_N",  listToArray(anno_N),
Codec.UNSIGNED5));
+                out.write(encodeBandInt(contextStr + "_" + type + " type_RS",  cpEntryListToArray(type_RS),
Codec.UNSIGNED5));
+                out.write(encodeBandInt(contextStr + "_" + type + " pair_N",  listToArray(pair_N),
Codec.UNSIGNED5));
+                out.write(encodeBandInt(contextStr + "_" + type + " name_RU",  cpEntryListToArray(name_RU),
Codec.UNSIGNED5));
+            }
+            out.write(encodeBandInt(contextStr + "_" + type + " T",  tagListToArray(T), Codec.BYTE1));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseI_KI",  cpEntryListToArray(caseI_KI),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseD_KD",  cpEntryListToArray(caseD_KD),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseF_KF",  cpEntryListToArray(caseF_KF),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseJ_KJ",  cpEntryListToArray(caseJ_KJ),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " casec_RS",  cpEntryListToArray(casec_RS),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseet_RS",  cpEntryListToArray(caseet_RS),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " caseec_RU",  cpEntryListToArray(caseec_RU),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " cases_RU",  cpEntryListToArray(cases_RU),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " casearray_N",  listToArray(casearray_N),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " nesttype_RS",  cpEntryListToArray(nesttype_RS),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " nestpair_N",  listToArray(nestpair_N),
Codec.UNSIGNED5));
+            out.write(encodeBandInt(contextStr + "_" + type + " nestname_RU",  cpEntryListToArray(nestname_RU),
Codec.UNSIGNED5));
+        }
+    }
+
+    private int[] tagListToArray(List t2) {
+        int[] ints = new int[t2.size()];
+        for (int i = 0; i < ints.length; i++) {
+            ints[i] = ((String)t2.get(i)).charAt(0);
+        }
+        return ints;
+    }
+
+    public void addAnnotation(String desc, List nameRU, List t, List values, List caseArrayN,
List nestTypeRS, List nestNameRU, List nestPairN) {
+        type_RS.add(cpBands.getCPSignature(desc));
+        pair_N.add(new Integer(t.size()));
+
+        for (Iterator iterator = nameRU.iterator(); iterator.hasNext();) {
+            String name = (String) iterator.next();
+            name_RU.add(cpBands.getCPUtf8(name));
+        }
+
+        Iterator valuesIterator = values.iterator();
+        for (Iterator iterator = t.iterator(); iterator.hasNext();) {
+            String tag = (String) iterator.next();
+            T.add(tag);
+            if (tag.equals("B") || tag.equals("C") || tag.equals("I")
+                    || tag.equals("S") || tag.equals("Z")) {
+                Integer value = (Integer)valuesIterator.next();
+                caseI_KI.add(cpBands.getConstant(value));
+            } else if (tag.equals("D")) {
+                Double value = (Double)valuesIterator.next();
+                caseD_KD.add(cpBands.getConstant(value));
+            } else if (tag.equals("F")) {
+                Float value = (Float)valuesIterator.next();
+                caseF_KF.add(cpBands.getConstant(value));
+            } else if (tag.equals("J")) {
+                Long value = (Long)valuesIterator.next();
+                caseJ_KJ.add(cpBands.getConstant(value));
+            } else if (tag.equals("C")) {
+                String value = (String)valuesIterator.next();
+                casec_RS.add(cpBands.getCPSignature(value));
+            } else if (tag.equals("e")) {
+                String value = (String)valuesIterator.next();
+                String value2 = (String)valuesIterator.next();
+                caseet_RS.add(cpBands.getCPSignature(value));
+                caseec_RU.add(cpBands.getCPUtf8(value2));
+            } else if (tag.equals("s")) {
+                String value = (String)valuesIterator.next();
+                cases_RU.add(cpBands.getCPUtf8(value));
+            }
+            // do nothing here for [ or @ (handled below)
+        }
+        for (Iterator iterator = caseArrayN.iterator(); iterator.hasNext();) {
+            Integer arraySize = (Integer) iterator.next();
+            casearray_N.add(arraySize);
+            numBackwardsCalls += arraySize.intValue();
+        }
+        for (Iterator iterator = nesttype_RS.iterator(); iterator.hasNext();) {
+            String type = (String) iterator.next();
+            nesttype_RS.add(cpBands.getCPSignature(type));
+        }
+        for (Iterator iterator = nestname_RU.iterator(); iterator.hasNext();) {
+            String name = (String) iterator.next();
+            nestname_RU.add(cpBands.getCPUtf8(name));
+        }
+        for (Iterator iterator = nestPairN.iterator(); iterator.hasNext();) {
+            Integer numPairs = (Integer) iterator.next();
+            nestPairN.add(numPairs);
+            numBackwardsCalls += numPairs.intValue();
+        }
+    }
+
+    public boolean hasContent() {
+        return T.size() > 0;
+    }
+
+    public int numBackwardsCalls() {
+        return numBackwardsCalls;
+    }
+
+    public void incrementAnnoN() {
+        Integer latest = (Integer)anno_N.remove(anno_N.size() -1);
+        anno_N.add(new Integer(latest.intValue() + 1));
+    }
+
+    public void newEntryInAnnoN() {
+        anno_N.add(new Integer(1));
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=727042&r1=727041&r2=727042&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Tue Dec 16 05:01:40 2008
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -27,6 +28,7 @@
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
 
 public class Segment implements ClassVisitor {
 
@@ -40,7 +42,6 @@
 
     private final SegmentFieldVisitor fieldVisitor = new SegmentFieldVisitor();
     private final SegmentMethodVisitor methodVisitor = new SegmentMethodVisitor();
-    private final SegmentAnnotationVisitor annotationVisitor = new SegmentAnnotationVisitor();
     private Pack200ClassReader currentClassReader;
 
     public void pack(List classes, List files, OutputStream out)
@@ -87,7 +88,8 @@
         bcBands.setCurrentClass(name);
         bcBands.setSuperClass(superName);
         segmentHeader.addMajorVersion(version);
-        classBands.addClass(version, access, name, signature, superName, interfaces);
+        classBands.addClass(version, access, name, signature, superName,
+                interfaces);
     }
 
     public void visitSource(String source, String debug) {
@@ -99,8 +101,9 @@
 
     }
 
-    public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-        return annotationVisitor;
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+        return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_CLASS,
+                desc, visible);
     }
 
     public void visitAttribute(Attribute arg0) {
@@ -133,12 +136,13 @@
      */
     public class SegmentMethodVisitor implements MethodVisitor {
 
-        public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-            return annotationVisitor;
+        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(
+                    MetadataBandGroup.CONTEXT_METHOD, desc, visible);
         }
 
         public AnnotationVisitor visitAnnotationDefault() {
-            return annotationVisitor;
+            return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_METHOD);
         }
 
         public void visitAttribute(Attribute arg0) {
@@ -173,9 +177,10 @@
             classBands.addMaxStack(maxStack, maxLocals);
         }
 
-        public AnnotationVisitor visitParameterAnnotation(int arg0,
-                String arg1, boolean arg2) {
-            return annotationVisitor;
+        public AnnotationVisitor visitParameterAnnotation(int parameter,
+                String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(
+                    MetadataBandGroup.CONTEXT_METHOD, parameter, desc, visible);
         }
 
         public void visitTryCatchBlock(Label start, Label end, Label handler,
@@ -246,36 +251,170 @@
 
     public class SegmentAnnotationVisitor implements AnnotationVisitor {
 
-        public void visit(String arg0, Object arg1) {
-            // TODO Auto-generated method stub
-
-        }
-
-        public AnnotationVisitor visitAnnotation(String arg0, String arg1) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        public AnnotationVisitor visitArray(String arg0) {
-            // TODO Auto-generated method stub
-            return null;
+        private int context = -1;
+        private int parameter = -1;
+        private String desc;
+        private boolean visible;
+
+        private final List nameRU = new ArrayList();
+        private final List T = new ArrayList(); // tags
+        private final List values = new ArrayList();
+        private final List caseArrayN = new ArrayList();
+        private final List nestTypeRS = new ArrayList();
+        private final List nestNameRU = new ArrayList();
+        private final List nestPairN = new ArrayList();
+
+
+        public SegmentAnnotationVisitor(int context, String desc,
+                boolean visible) {
+            this.context = context;
+            this.desc = desc;
+            this.visible = visible;
+        }
+
+        public SegmentAnnotationVisitor(int context) {
+            this.context = context;
+        }
+
+        public SegmentAnnotationVisitor(int context, int parameter,
+                String desc, boolean visible) {
+            this.context = context;
+            this.parameter = parameter;
+            this.desc = desc;
+            this.visible = visible;
+        }
+
+        public void visit(String name, Object value) {
+            nameRU.add(name);
+            values.add(value);
+            addTag(value);
+        }
+
+        private void addTag(Object value) {
+            if(value instanceof Integer) {
+                T.add("I");
+            } else if (value instanceof Double) {
+                T.add("D");
+            } else if (value instanceof Float) {
+                T.add("F");
+            } else if (value instanceof Long) {
+                T.add("J");
+            } else if (value instanceof Byte) {
+                T.add("B");
+            } else if (value instanceof Character) {
+                T.add("C");
+            } else if (value instanceof Short) {
+                T.add("S");
+            } else if (value instanceof Boolean) {
+                T.add("Z");
+            } else if (value instanceof String) {
+                T.add("s");
+            } else if (value instanceof Type) {
+                T.add("c");
+            }
+        }
+
+        public AnnotationVisitor visitAnnotation(String name, String desc) {
+            T.add("@");
+            nameRU.add(name);
+            nestTypeRS.add(desc);
+            nestPairN.add(new Integer(0));
+            return new AnnotationVisitor() {
+                public void visit(String name, Object value) {
+                    Integer numPairs = (Integer) nestPairN.remove(nestPairN.size() - 1);
+                    nestPairN.add(new Integer(numPairs.intValue() + 1));
+                    nestNameRU.add(name);
+                    values.add(value);
+                    addTag(value);
+                }
+
+                public AnnotationVisitor visitAnnotation(String arg0,
+                        String arg1) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public AnnotationVisitor visitArray(String arg0) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public void visitEnd() {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public void visitEnum(String name, String desc, String value) {
+                    Integer numPairs = (Integer) nestPairN.remove(nestPairN.size() - 1);
+                    nestPairN.add(new Integer(numPairs.intValue() + 1));
+                    T.add("e");
+                    nestNameRU.add(name);
+                    values.add(desc);
+                    values.add(value);
+                }
+            };
+        }
+
+        public AnnotationVisitor visitArray(String name) {
+            T.add("[");
+            nameRU.add(name);
+            caseArrayN.add(new Integer(0));
+            return new AnnotationVisitor() {
+                public void visit(String name, Object value) {
+                    Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
+                    caseArrayN.add(new Integer(numCases.intValue() + 1));
+                    nameRU.add(name);
+                    values.add(value);
+                    addTag(value);
+                }
+
+                public AnnotationVisitor visitAnnotation(String arg0,
+                        String arg1) {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public AnnotationVisitor visitArray(String arg0) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public void visitEnd() {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public void visitEnum(String name, String desc, String value) {
+                    Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
+                    caseArrayN.add(new Integer(numCases.intValue() + 1));
+                    T.add("e");
+                    nameRU.add(name);
+                    values.add(desc);
+                    values.add(value);
+                }
+            };
         }
 
         public void visitEnd() {
-            // TODO Auto-generated method stub
-
+            if (desc == null) {
+                Segment.this.classBands.addAnnotationDefault(nameRU, T, values, caseArrayN,
nestTypeRS, nestNameRU, nestPairN);
+            } else if(parameter != -1) {
+                Segment.this.classBands.addParameterAnnotation(parameter, desc, visible,
nameRU, T, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            } else {
+                Segment.this.classBands.addAnnotation(context, desc, visible, nameRU, T,
values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            }
         }
 
-        public void visitEnum(String arg0, String arg1, String arg2) {
-            // TODO Auto-generated method stub
-
+        public void visitEnum(String name, String desc, String value) {
+            T.add("e");
+            nameRU.add(name);
+            values.add(desc);
+            values.add(value);
         }
     }
 
     public class SegmentFieldVisitor implements FieldVisitor {
 
-        public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-            return annotationVisitor;
+        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_FIELD,
+                    desc, visible);
         }
 
         public void visitAttribute(Attribute arg0) {



Mime
View raw message