]> source.dussan.org Git - aspectj.git/commitdiff
passing the correct compressors around (for small class file sizes enhancement)
authoraclement <aclement>
Tue, 18 May 2010 19:46:36 +0000 (19:46 +0000)
committeraclement <aclement>
Tue, 18 May 2010 19:46:36 +0000 (19:46 +0000)
org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java
org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java

index 07149a5183d8dcfd8a939374944b26b89e6972ab..982a5ab8c2aa27db0addb81c63876417a4c413ac 100644 (file)
@@ -52,10 +52,10 @@ public abstract class AjAttribute {
        /**
         * Just writes the contents
         */
-       public byte[] getBytes() {
+       public byte[] getBytes(ConstantPoolWriter compressor) {
                try {
                        ByteArrayOutputStream b0 = new ByteArrayOutputStream();
-                       CompressingDataOutputStream s0 = new CompressingDataOutputStream(b0);
+                       CompressingDataOutputStream s0 = new CompressingDataOutputStream(b0, compressor);
                        write(s0);
                        s0.close();
                        return b0.toByteArray();
@@ -67,10 +67,12 @@ public abstract class AjAttribute {
 
        /**
         * Writes the full attribute, i.e. name_index, length, and contents
+        * 
+        * @param constantPool
         */
-       public byte[] getAllBytes(short nameIndex) {
+       public byte[] getAllBytes(short nameIndex, ConstantPoolWriter dataCompressor) {
                try {
-                       byte[] bytes = getBytes();
+                       byte[] bytes = getBytes(dataCompressor);
 
                        ByteArrayOutputStream b0 = new ByteArrayOutputStream();
                        DataOutputStream s0 = new DataOutputStream(b0);
@@ -86,12 +88,13 @@ public abstract class AjAttribute {
                }
        }
 
-       public static AjAttribute read(AjAttribute.WeaverVersionInfo v, String name, byte[] bytes, ISourceContext context, World w) {
+       public static AjAttribute read(AjAttribute.WeaverVersionInfo v, String name, byte[] bytes, ISourceContext context, World w,
+                       ConstantPoolReader dataDecompressor) {
                try {
                        if (bytes == null) {
                                bytes = new byte[0];
                        }
-                       VersionedDataInputStream s = new VersionedDataInputStream(new ByteArrayInputStream(bytes));
+                       VersionedDataInputStream s = new VersionedDataInputStream(new ByteArrayInputStream(bytes), dataDecompressor);
                        s.setVersion(v);
                        if (name.equals(Aspect.AttributeName)) {
                                return new Aspect(PerClause.readPerClause(s, context));
index 160d7018b975c90c000717cf703364204d5635e6..8e4d297d3f578adca04cf1c149db6a3f1951769e 100644 (file)
@@ -1,5 +1,5 @@
 /* *******************************************************************
- * Copyright (c) 2005 IBM
+ * Copyright (c) 2005-2010 Contributors
  * All rights reserved. 
  * This program and the accompanying materials are made available 
  * under the terms of the Eclipse Public License v1.0 
@@ -7,26 +7,38 @@
  * http://www.eclipse.org/legal/epl-v10.html 
  *  
  * Contributors: 
- *     Andy Clement           initial implementation
+ * Andy Clement (IBM, SpringSource)
  * ******************************************************************/
 
 package org.aspectj.weaver;
 
 import java.io.DataInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
 
 /**
- * Lightweight subclass of DataInputStream that knows what version of the weaver was used to construct the data in it.
+ * Lightweight subclass of DataInputStream that knows what version of the weaver was used to construct the data in it. The input
+ * stream has a constant pool reader attached which enables it to decode constant pool references found within the data being read.
+ * 
+ * @author Andy Clement
  */
 public class VersionedDataInputStream extends DataInputStream {
+
        private WeaverVersionInfo version = new WeaverVersionInfo();// assume we are the latest unless something tells us otherwise...
 
+       private ConstantPoolReader constantPoolReader;
+
        public VersionedDataInputStream(InputStream is) {
                super(is);
        }
 
+       public VersionedDataInputStream(InputStream is, ConstantPoolReader constantPoolReader) {
+               super(is);
+               this.constantPoolReader = constantPoolReader;
+       }
+
        public int getMajorVersion() {
                return version.getMajorVersion();
        }
@@ -42,4 +54,30 @@ public class VersionedDataInputStream extends DataInputStream {
        public void setVersion(WeaverVersionInfo version) {
                this.version = version;
        }
+
+       public String accessUtf8(int cpIndex) {
+               if (constantPoolReader == null) {
+                       throw new IllegalStateException();
+               }
+               if (cpIndex < 0) {
+                       throw new IllegalStateException(cpIndex + "");
+               }
+               return constantPoolReader.readUtf8(cpIndex);
+       }
+
+       public boolean canDecompress() {
+               return constantPoolReader != null;
+       }
+
+       public boolean isAtLeast169() {
+               return getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_AJ169;
+       }
+
+       public String readPath() throws IOException {
+               return accessUtf8(readShort());
+       }
+       
+       public String readSignature() throws IOException {
+               return accessUtf8(readShort());
+       }
 }
\ No newline at end of file