[MAJOR: removed Java API. barista@x9c.fr**20110307050012 Ignore-this: 92ef0bc7f9276d95b9b6b310d17065d3 ] { rmdir ./api/classes hunk ./api/src/fr/x9c/barista/api/API.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -import fr.x9c.cadmium.kernel.AbstractNativeRunner; -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.CadmiumException; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.kernel.Fail; -import fr.x9c.cadmium.kernel.FalseExit; -import fr.x9c.cadmium.kernel.Fatal; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * Entry point of the Barista Java API. - * - * @author Xavier Clerc - * @version 1.1 - * @since 1.0 - */ -public final class API { - - /** The actual Barista program (that registered callbacks to be used). */ - private static fr.x9c.barista.cafesterolMain main; - - /** - * No instance of this class. - */ - private API() { - } // end empty constructor - - /** - * Initializes the Barista API. - */ - public static synchronized void init() { - if (main == null) { - main = fr.x9c.barista.cafesterolMain.mainWithReturn(new String[] { "-api" }); - } // end if - } // end method 'init()' - - /** - * Runs a callback, wrapping any exception as a Barista one. - * @param name callback name - should not be null - * @param args callback parameters - should not be null - * @return the result of the callback execution - * @throws BaristaException if any error occurs during callback - */ - static Value callback(final String name, final Value... args) - throws BaristaException { - assert name != null : "null name"; - assert args != null : "null args"; - init(); - final AbstractNativeRunner runner = main.copy(); - try { - return runner.callback(name, args); - } catch (final Fail.Exception fe) { - final Value v = fe.asValue(runner); - throw new BaristaException(v.asBlock().get(1).asBlock().asString()); - } catch (final Fatal.Exception fe) { - throw new BaristaException(fe.getMessage()); - } catch (final FalseExit fe) { - return null; - } catch (final CadmiumException ce) { - throw new BaristaException(ce.toString()); - } // end try/catch - } // end method 'callback(String, Value...)' - - /** - * Creates an UTF8 instance from a string. - * @param s string to create from - should not be null - * @return the corresponding UTF8 instance - */ - static Value createUTF8(final String s) { - assert s != null : "null s"; - try { - final Block b = Block.createString(s.getBytes("UTF-8")); - return Value.createFromBlock(b); - } catch (java.io.UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } // and try/catch - } // end method 'createUTF8(String)' - - /** - * Converts an UTF8 value into a string. - * @param v value to convert - should not be null - * @return the corresponding string - */ - static String stringOfUTF8(final Value v) { - assert v != null : "null v"; - try { - return new String(v.asBlock().getBytes(), "UTF-8"); - } catch (java.io.UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } // and try/catch - } // end method 'stringOfUTF8(Value)' - - /** - * Creates a class name from a string. - * @param s string to create name from - should not be null - * @return the corresponding class name - * @throws BaristaException if passed string is not a valid class name - */ - static Value createClassName(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Name.make_class", - createUTF8(s)); - } // end method 'createClassName(String)' - - /** - * Creates a field name from a string. - * @param s string to create name from - should not be null - * @return the corresponding field name - * @throws BaristaException if passed string is not a valid field name - */ - static Value createFieldName(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Name.make_field", - createUTF8(s)); - } // end method 'createFieldName(String)' - - /** - * Creates a method name from a string. - * @param s string to create name from - should not be null - * @return the corresponding method name - * @throws BaristaException if passed string is not a valid method name - */ - static Value createMethodName(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Name.make_method", - createUTF8(s)); - } // end method 'createMethodName(String)' - - /** - * Converts a class name value into a string. - * @param v classname value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfClassName(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Name.utf8_of_class", v)); - } // end method 'stringOfClassName(Value)' - - /** - * Converts a field name value into a string. - * @param v field name value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfFieldName(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Name.utf8_of_field", v)); - } // end method 'stringOfFieldName(Value)' - - /** - * Converts a method name value into a string. - * @param v method name value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfMethodName(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Name.utf8_of_method", v)); - } // end method 'stringOfMethodName(Value)' - - /** - * Creates a field signature from a string. - * @param s string to create signature from - should not be null - * @return the corresponding signature - * @throws BaristaException if passed string is not a valid field signature - */ - static Value createFieldSignature(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Signature.make_field", - createUTF8(s)); - } // end method 'createFieldSignature(String)' - - /** - * Converts a field signature value into a string. - * @param v field signature value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfFieldSignature(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Signature.utf8_of_field_signature", v)); - } // end method 'stringOfFieldSignature(Value)' - - /** - * Creates a method signature from a string. - * @param s string to create signature from - should not be null - * @return the corresponding signature - * @throws BaristaException if passed string is not a valid method signature - */ - static Value createMethodSignature(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Signature.make_method", - createUTF8(s)); - } // end method 'createMethodSignature(String)' - - /** - * Converts a method signature value into a string. - * @param v method signature value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfMethodSignature(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Signature.utf8_of_method_signature", v)); - } // end method 'stringOfMethodSignature(Value)' - - /** - * Creates a class signature from a string. - * @param s string to create signature from - should not be null - * @return the corresponding signature - * @throws BaristaException if passed string is not a valid class signature - */ - static Value createClassSignature(final String s) throws BaristaException { - assert s != null : "null s"; - return callback("fr.x9c.barista.api.Signature.make_class", - createUTF8(s)); - } // end method 'createClassSignature(String)' - - /** - * Converts a class signature value into a string. - * @param v class signature value to convert - should not be null - * @return the corresponding string - * @throws BaristaEception if an error occurs during conversion - */ - static String stringOfClassSignature(final Value v) throws BaristaException { - assert v != null : "null v"; - return stringOfUTF8(callback("fr.x9c.barista.api.Signature.utf8_of_class_signature", v)); - } // end method 'stringOfClassSignature(Value)' - - /** - * Decodes a list of value from a value. - * @param v value to decode - should not be null - * @return the corresponding list - */ - static List decodeList(final Value v) { - assert v != null : "null v"; - final List res = new LinkedList(); - Value list = v; - while (list != Value.EMPTY_LIST) { - final Block b = list.asBlock(); - res.add(b.get(0)); - list = b.get(1); - } // end while - return res; - } // end method 'decodeList(Value)' - - /** - * Encodes a list into a value. - * @param l list to encode - should not be null - * @return the passed list as a value - */ - static Value encodeList(final List l) { - assert l != null : "null l"; - Value res = Value.EMPTY_LIST; - final ListIterator it = l.listIterator(l.size()); - while (it.hasPrevious()) { - final Block cons = Block.createBlock(Block.TAG_CONS, - it.previous().toValue(), - res); - res = Value.createFromBlock(cons); - } // end while - return res; - } // end method 'encodeList(List)' - - /** - * Encodes a list into a value. - * @param l list to encode - should not be null - * @return the passed list as a value - */ - static Value encodeValueList(final List l) { - assert l != null : "null l"; - Value res = Value.EMPTY_LIST; - final ListIterator it = l.listIterator(l.size()); - while (it.hasPrevious()) { - final Block cons = Block.createBlock(Block.TAG_CONS, - it.previous(), - res); - res = Value.createFromBlock(cons); - } // end while - return res; - } // end method 'encodeValueList(List)' - - /** - * Encodes a list into a value. - * @param ll list to encode - should not be null - * @return the passed list as a value - */ - static Value encodeListList(final List< List > ll) { - assert ll != null : "null ll"; - final List l = new LinkedList(); - for (List i : ll) { - l.add(encodeList(i)); - } // end for - return encodeValueList(l); - } // end method 'encodeListList(List< List >)' - - /** - * Tests whether two objects are either equal or both null. - * @param obj1 first object to test - * @param obj2 second object to test - * @return true if passed objects are either equal or both null, - * false otherwise - */ - static boolean nullOrEquals(final Object obj1, final Object obj2) { - if (obj1 != null) { - return obj2 != null ? obj1.equals(obj2) : false; - } else { - return obj2 == null; - } // end if/else - } // end method 'nullOrEquals(Object, Object)' - -} // end class 'API' rmfile ./api/src/fr/x9c/barista/api/API.java hunk ./api/src/fr/x9c/barista/api/AccessFlag.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.primitives.stdlib.Hash; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java access flag for a Java element. - * - * @author Xavier Clerc - * @version 2.0 - * @since 1.0 - */ -public enum AccessFlag implements ToValue, Comparator { - - Public, - Private, - Protected, - Static, - Final, - Super, - Synchronized, - Bridge, - Volatile, - Transient, - Varargs, - Native, - Interface, - Abstract, - Strict, - Synthetic, - Annotation, - Enum, - Module; - - /** Map from tag values to flags. */ - private static final Map MAP = - new HashMap(); - - /** Map initilization. */ - static { - for (AccessFlag a : AccessFlag.values()) { - MAP.put(a.toValue().asLong(), a); - } // end for - } // end static block - - /** - * Tests whether the flag is a valid class flag. - * @return true if the flag is a valid class flag, - * false otherwise - */ - public boolean isClassFlag() { - switch (this) { - case Public: - case Final: - case Super: - case Interface: - case Abstract: - case Synthetic: - case Annotation: - case Enum: - case Module: - return true; - default: - return false; - } // end switch - } // end method 'isClassFlag()' - - /** - * Tests whether the flag is a valid inner-class flag. - * @return true if the flag is a valid inner-class flag, - * false otherwise - */ - public boolean isInnerClassFlag() { - switch (this) { - case Public: - case Private: - case Protected: - case Static: - case Final: - case Super: - case Interface: - case Abstract: - case Synthetic: - case Annotation: - case Enum: - case Module: - return true; - default: - return false; - } // end switch - } // end method 'isInnerClassFlag()' - - /** - * Tests whether the flag is a valid field flag. - * @return true if the flag is a valid field flag, - * false otherwise - */ - public boolean isFieldFlag() { - switch (this) { - case Public: - case Private: - case Protected: - case Static: - case Final: - case Volatile: - case Transient: - case Synthetic: - case Enum: - case Module: - return true; - default: - return false; - } // end switch - } // end method 'isFieldFlag()' - - /** - * Tests whether the flag is a valid method flag. - * @return true if the flag is a valid method flag, - * false otherwise - */ - public boolean isMethodFlag() { - switch (this) { - case Public: - case Private: - case Protected: - case Static: - case Final: - case Synchronized: - case Bridge: - case Varargs: - case Native: - case Abstract: - case Strict: - case Synthetic: - case Module: - return true; - default: - return false; - } // end switch - } // end method 'isMethodFlag()' - - /** - * Tests whether the flag is a valid constructor flag. - * @return true if the flag is a valid constructor flag, - * false otherwise - */ - public boolean isConstructorFlag() { - switch (this) { - case Public: - case Private: - case Protected: - case Strict: - case Varargs: - case Synthetic: - case Module: - return true; - default: - return false; - } // end switch - } // end method 'isConstructorFlag()' - - /** - * Returns the rank of a flag, used for comparison. - * @return the rank of a flag, used for comparison - */ - int getRank() { - switch (this) { - case Public: - case Private: - case Protected: - case Module: - return 1; - case Abstract: - case Static: - return 2; - case Final: - return 3; - case Synchronized: - case Volatile: - case Transient: - case Native: - case Strict: - return 4; - case Super: - case Bridge: - case Varargs: - case Interface: - case Synthetic: - case Annotation: - case Enum: - return 5; - default: - assert false : "invalid flag"; - return 0; - } // end switch - } // end method 'getRank()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Hash.hashVariant(name()); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - public int compare(final AccessFlag af1, final AccessFlag af2) { - assert af1 != null : "null af1"; - assert af2 != null : "null af2"; - final int cmp = af1.getRank() - af2.getRank(); - if (cmp != 0) { - return cmp; - } else { - return af1.name().compareTo(af2.name()); - } // end if/else - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static AccessFlag fromValue(final Value v) { - assert v != null : "null v"; - return MAP.get(v.asLong()); - } // end method 'fromValue(Value)' - - /** - * Tests whether a list contains only class flags. - * @param l list to test - should not be null - * @return true if the list contains only class flags, - * false otherwise - */ - public static boolean areClassFlags(final List l) { - for (AccessFlag a : l) { - if (!a.isClassFlag()) { - return false; - } // end if - } // end for - return true; - } // end method 'areClassFlags(List)' - - /** - * Tests whether a list contains only inner-class flags. - * @param l list to test - should not be null - * @return true if the list contains only inner-class flags, - * false otherwise - */ - public static boolean areInnerClassFlags(final List l) { - for (AccessFlag a : l) { - if (!a.isInnerClassFlag()) { - return false; - } // end if - } // end for - return true; - } // end method 'areInnerClassFlags(List)' - - /** - * Tests whether a list contains only field flags. - * @param l list to test - should not be null - * @return true if the list contains only field flags, - * false otherwise - */ - public static boolean areFieldFlags(final List l) { - for (AccessFlag a : l) { - if (!a.isFieldFlag()) { - return false; - } // end if - } // end for - return true; - } // end method 'areFieldFlags(List)' - - /** - * Tests whether a list contains only method flags. - * @param l list to test - should not be null - * @return true if the list contains only method flags, - * false otherwise - */ - public static boolean areMethodFlags(final List l) { - for (AccessFlag a : l) { - if (!a.isMethodFlag()) { - return false; - } // end if - } // end for - return true; - } // end method 'areMethodFlags(List)' - - /** - * Tests whether a list contains only constructor flags. - * @param l list to test - should not be null - * @return true if the list contains only constructor flags, - * false otherwise - */ - public static boolean areConstructorFlags(final List l) { - for (AccessFlag a : l) { - if (!a.isConstructorFlag()) { - return false; - } // end if - } // end for - return true; - } // end method 'areConstructorFlags(List)' - - /** - * Converts a flag list into a string. - * @param l list to convert - should not be null - * @return the concatenation of all list elements - */ - public static String listToString(final List l) { - assert l != null : "null l"; - final StringBuilder sb = new StringBuilder(); - final List l2 = new LinkedList(l); - Collections.sort(l2); - boolean first = true; - for (AccessFlag a : l2) { - if (first) { - first = false; - } else { - sb.append(" "); - } // end if/else - sb.append(a.toString()); - } // end for - return sb.toString(); - } // end method 'listToString(List)' - -} // end class 'AccessFlag' rmfile ./api/src/fr/x9c/barista/api/AccessFlag.java hunk ./api/src/fr/x9c/barista/api/Annotation.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.Helper; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java annotation. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class Annotation implements ToValue { - - /** - * Parent class of all element value embedded inside annotations. - */ - public static abstract class ElementValue implements ToValue { - - /** - * Ensures that no element value could be defined outside this file. - */ - private ElementValue() { - } // end empty constructor - - } // end inner-class 'ElementValue' - - /** - * Represents a boolean value embedded inside an annotation. - */ - public static final class BooleanValue extends ElementValue { - - /** The underlying value. */ - private final boolean value; - - /** - * Constructs a boolean value. - * @param v value - */ - public BooleanValue(final boolean v) { - this.value = v; - } // end constructor(boolean) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public boolean getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, this.value ? Value.TRUE : Value.FALSE); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "BooleanValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value ? 1 : 0; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof BooleanValue) { - final BooleanValue that = (BooleanValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'BooleanValue' - - /** - * Represents a byte value embedded inside an annotation. - */ - public static final class ByteValue extends ElementValue { - - /** The underlying value. */ - private final byte value; - - /** - * Constructs a byte value. - * @param v value - */ - public ByteValue(final byte v) { - this.value = v; - } // end constructor(byte) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public byte getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ByteValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ByteValue) { - final ByteValue that = (ByteValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ByteValue' - - /** - * Represents a char value embedded inside an annotation. - */ - public static final class CharValue extends ElementValue { - - /** The underlying value. */ - private final char value; - - /** - * Constructs a char value. - * @param v value - */ - public CharValue(final char v) { - this.value = v; - } // end constructor(char) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public char getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "CharValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof CharValue) { - final CharValue that = (CharValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'CharValue' - - /** - * Represents a double value embedded inside an annotation. - */ - public static final class DoubleValue extends ElementValue { - - /** The underlying value. */ - private final double value; - - /** - * Constructs a double value. - * @param v value - */ - public DoubleValue(final double v) { - this.value = v; - } // end constructor(double) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public double getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(3, Helper.createFloat(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "DoubleValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof DoubleValue) { - final DoubleValue that = (DoubleValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'DoubleValue' - - /** - * Represents a float value embedded inside an annotation. - */ - public static final class FloatValue extends ElementValue { - - /** The underlying value. */ - private final float value; - - /** - * Constructs a float value. - * @param v value - */ - public FloatValue(final float v) { - this.value = v; - } // end constructor(float) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public float getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(4, Helper.createFloat(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "FloatValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof FloatValue) { - final FloatValue that = (FloatValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'FloatValue' - - /** - * Represents an int value embedded inside an annotation. - */ - public static final class IntValue extends ElementValue { - - /** The underlying value. */ - private final int value; - - /** - * Constructs a int value. - * @param v value - */ - public IntValue(final int v) { - this.value = v; - } // end constructor(int) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public int getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(5, Helper.createInt32(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IntValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IntValue) { - final IntValue that = (IntValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IntValue' - - /** - * Represents a long value embedded inside an annotation. - */ - public static final class LongValue extends ElementValue { - - /** The underlying value. */ - private final long value; - - /** - * Constructs a long value. - * @param v value - */ - public LongValue(final long v) { - this.value = v; - } // end constructor(long) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public long getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(6, Helper.createInt64(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LongValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LongValue) { - final LongValue that = (LongValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LongValue' - - /** - * Represents a short value embedded inside an annotation. - */ - public static final class ShortValue extends ElementValue { - - /** The underlying value. */ - private final short value; - - /** - * Constructs a short value. - * @param v value - */ - public ShortValue(final short v) { - this.value = v; - } // end constructor(short) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public short getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(7, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ShortValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ShortValue) { - final ShortValue that = (ShortValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ShortValue' - - /** - * Represents a string value embedded inside an annotation. - */ - public static final class StringValue extends ElementValue { - - /** The underlying value. */ - private final String value; - - /** - * Constructs a string value. - * @param v value - should not be null - */ - public StringValue(final String v) { - assert v != null : "null v"; - this.value = v; - } // end constructor(String) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public String getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(8, API.createUTF8(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "StringValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof StringValue) { - final StringValue that = (StringValue) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'StringValue' - - /** - * Represents an enum value embedded inside an annotation. - */ - public static final class EnumValue extends ElementValue { - - /** The underlying class name. */ - private final String className; - - /** The underlying enum name. */ - private final String enumName; - - /** - * Constructs an enum value. - * @param cn class name - should not be null - * @param en enum name - should not be null - */ - public EnumValue(final String cn, final String en) { - assert cn != null : "null cn"; - assert en != null : "null en"; - this.className = cn; - this.enumName = en; - } // end constructor(String, String) - - /** - * Returns the class name. - * @return the class name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * Returns the enum name. - * @return the enum name - */ - public String getEnumName() { - return this.enumName; - } // end method 'getEnumName()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(9, - API.createClassName(this.className), - API.createFieldName(this.enumName)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "EnumValue(" + this.className + ", " + this.enumName + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.className.hashCode() + this.enumName.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof EnumValue) { - final EnumValue that = (EnumValue) obj; - return this.className.equals(that.className) - && this.enumName.equals(that.enumName); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'EnumValue' - - /** - * Represents a class value embedded inside an annotation. - */ - public static final class ClassValue extends ElementValue { - - /** The underlying class name. */ - private final String className; - - /** - * Constructs a class value. - * @param cn class name - should not be null - */ - public ClassValue(final String cn) { - assert cn != null : "null cn"; - this.className = cn; - } // end constructor(String) - - /** - * Returns the class name. - * @return the class name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(10, API.createClassName(this.className)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassValue(" + this.className + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.className.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassValue) { - final ClassValue that = (ClassValue) obj; - return this.className.equals(that.className); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassValue' - - /** - * Represents an annotation value embedded inside an annotation. - */ - public static final class AnnotationValue extends ElementValue { - - /** The underlying value. */ - private final Annotation value; - - /** - * Constructs an annotation value. - * @param v value - should not be null - */ - public AnnotationValue(final Annotation v) { - assert v != null : "null v"; - this.value = v; - } // end constructor(Annotation) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public Annotation getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(11, this.value.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "AnnotationValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.value.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof AnnotationValue) { - final AnnotationValue that = (AnnotationValue) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'AnnotationValue' - - /** - * Represents an Array value embedded inside an annotation. - */ - public static final class ArrayValue extends ElementValue { - - /** The underlying value. */ - private final ElementValue[] value; - - /** - * Constructs an array value. - * @param v value - should not be null - */ - public ArrayValue(final ElementValue[] v) { - assert v != null : "null v"; - final int len = v.length; - this.value = new ElementValue[len]; - System.arraycopy(v, 0, this.value, 0, len); - } // end constructor(ElementValue[]) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public ElementValue[] getValue() { - final int len = this.value.length; - final ElementValue[] res = new ElementValue[len]; - System.arraycopy(this.value, 0, res, 0, len); - return res; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - Value res = Value.EMPTY_LIST; - for (int i = this.value.length - 1; i >= 0; i--) { - final Block cons = Block.createBlock(Block.TAG_CONS, - this.value[i].toValue(), - res); - res = Value.createFromBlock(cons); - } // end for - final Block b = Block.createBlock(12, res); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ArrayValue(" + Arrays.toString(this.value) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Arrays.hashCode(this.value); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ArrayValue) { - final ArrayValue that = (ArrayValue) obj; - return Arrays.equals(this.value, that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ArrayValue' - - /** Annotation name. */ - private final String name; - - /** Annotation element names. */ - private final List names; - - /** Annotation element values. */ - private final List values; - - /** - * Constructs an annotation. - * @param nm annotation name - should not be null - * @param n element names - should not be null, - * should also have the same size as v - * @param v element values - should not be null, - * should also have the same size as n - */ - public Annotation(final String nm, - final List n, - final List v) { - assert nm != null : "null nm"; - assert n != null : "null n"; - assert v != null : "null v"; - assert n.size() == v.size() : "n and v have different sizes"; - this.name = nm; - this.names = new LinkedList(n); - this.values = new LinkedList(v); - } // end constructor(String, List, List) - - /** - * Returns the name of the annotation. - * @return the name of the annotation - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the names of the annotations elements. - * @return the names of the annotations elements - */ - public List getNames() { - return new LinkedList(this.names); - } // end method 'getNames()' - - /** - * Returns the values of the annotations elements. - * @return the values of the annotations elements - */ - public List getValues() { - return new LinkedList(this.values); - } // end method 'getValues()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - Value list = Value.EMPTY_LIST; - final ListIterator itNames = this.names.listIterator(this.names.size()); - final ListIterator itValues = this.values.listIterator(this.values.size()); - while (itNames.hasPrevious() && itValues.hasPrevious()) { - final Block b = Block.createBlock(0, - API.createUTF8(itNames.previous()), - itValues.previous().toValue()); - final Block cons = Block.createBlock(Block.TAG_CONS, - Value.createFromBlock(b), - list); - list = Value.createFromBlock(cons); - } // end while - final Block res = Block.createBlock(0, - API.createClassName(this.name), - list); - return Value.createFromBlock(res); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static ElementValue elementFromValue(final Value v) { - assert v != null : "null v"; - final Block val = v.asBlock(); - final ElementValue elem; - switch (val.getTag()) { - case 0: - return new BooleanValue(val.get(0) == Value.TRUE); - case 1: - return new ByteValue((byte) val.get(0).asLong()); - case 2: - return new CharValue((char) val.get(0).asLong()); - case 3: - return new DoubleValue(val.get(0).asBlock().asDouble()); - case 4: - return new FloatValue((float) val.get(0).asBlock().asDouble()); - case 5: - return new IntValue(val.get(0).asBlock().asInt32()); - case 6: - return new LongValue(val.get(0).asBlock().asInt64()); - case 7: - return new ShortValue((short) val.get(0).asLong()); - case 8: - return new StringValue(API.stringOfUTF8(val.get(0))); - case 9: - return new EnumValue(API.stringOfClassName(val.get(0)), - API.stringOfFieldName(val.get(1))); - case 10: - return new ClassValue(API.stringOfClassName(val.get(0))); - case 11: - return new AnnotationValue(fromValue(val.get(0))); - case 12: - final List elements = API.decodeList(val.get(0)); - final int sz = elements.size(); - final ElementValue[] elementValues = new ElementValue[sz]; - elements.toArray(elementValues); - return new ArrayValue(elementValues); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end method 'elementFromValue(Value)' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Annotation fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final String name = API.stringOfClassName(b.get(0)); - final List list = API.decodeList(b.get(1)); - final List names = new LinkedList(); - final List values = new LinkedList(); - for (Value e : list) { - final Block bl = e.asBlock(); - names.add(API.stringOfUTF8(bl.get(0))); - values.add(elementFromValue(bl.get(1))); - } // end for - return new Annotation(name, names, values); - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("@"); - sb.append(this.name); - sb.append("("); - final Iterator itNames = this.names.iterator(); - final Iterator itValues = this.values.iterator(); - boolean first = true; - while (itNames.hasNext() && itValues.hasNext()) { - if (first) { - first = false; - } else { - sb.append(", "); - } // end if/else - sb.append(itNames.next()); - sb.append("="); - sb.append(itValues.next().toString()); - } // end while - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.name.hashCode() - + this.names.hashCode() - + this.values.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Annotation) { - final Annotation that = (Annotation) obj; - return this.name.equals(that.name) - && this.names.equals(that.names) - && this.values.equals(that.values); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - -} // end class 'Annotation' rmfile ./api/src/fr/x9c/barista/api/Annotation.java hunk ./api/src/fr/x9c/barista/api/AntAssembleTask.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; - -/** - * This class implements an Ant task - * assembling a class.
- * The task supports the following attributes: - *
    - *
  • file: file to assemble
    - * file - no default value, should be set - *
  • path: output path for assembled file
    - * directory - no default value, should be set - *
  • target: version used for class encoding
    - * string - default value is 1.6 - *
- * - * @author Xavier Clerc - * @version 1.3 - * @since 1.0 - */ -public final class AntAssembleTask extends Task { - - /** File to assemble. */ - private File file; - - /** Output path for assembled file. */ - private File path; - - /** Version used for class encoding. */ - private String target; - - /** - * Creates a new task with default parameters. - */ - public AntAssembleTask() { - this.file = null; - this.path = null; - this.target = "1.6"; - } // end empty constructor - - /** - * Sets the file to assemble. - * @param f file to assemble - */ - public void setFile(final File f) { - this.file = f; - } // end method 'setFile(File)' - - /** - * Sets the output path for assembled file. - * @param f output path for assembled file - */ - public void setPath(final File f) { - this.path = f; - } // end method 'setPath(File)' - - /** - * Sets the version used for class encoding. - * @param s version used for class encoding - */ - public void setTarget(final String s) { - this.target = s; - } // end method 'setTarger(String)' - - /** - * Actually executes the task. - */ - public void execute() throws BuildException { - if (this.file == null) { - throw new BuildException("'file' attribute is not set.", - getLocation()); - } // end if - if (this.path == null) { - throw new BuildException("'path' attribute is not set.", - getLocation()); - } // end if - final Version version = Version.fromString(this.target); - if (version == null) { - throw new BuildException("'target' attribute is invalid.", - getLocation()); - } // end if - - try { - Assembler.assemble(version, - new FileInputStream(this.file), - this.path.getAbsolutePath()); - } catch (final IOException ioe) { - throw new BuildException(ioe.getMessage(), ioe, getLocation()); - } catch (final BaristaException be) { - throw new BuildException(be.getMessage(), be, getLocation()); - } // end try/catch - } // end method 'execute()' - -} // end class 'AntAssembleTask' rmfile ./api/src/fr/x9c/barista/api/AntAssembleTask.java hunk ./api/src/fr/x9c/barista/api/AntDisassembleTask.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.LinkedList; -import java.util.List; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; - -/** - * This class implements an Ant task - * diassembling a class.
- * The task supports the following attributes: - *
    - *
  • classname: fully-qualified name of the class to disassemble
    - * string - no default value, should be set - *
  • output: where to disassemble the class
    - file defaults to null (which means standard output) - *

- * The task should also be supplied a nested <classpath> element - * to know where to look for class files. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class AntDisassembleTask extends Task { - - /** Fully-qualified name of the class to be disassembled. */ - private String classname; - - /** Where to disassemble the class (null means standard output). */ - private File output; - - /** Nested classpath elements. */ - private List classpaths; - - /** - * Creates a new task with default parameters. - */ - public AntDisassembleTask() { - this.classname = null; - this.output = null; - this.classpaths = new LinkedList(); - } // end empty constructor - - /** - * Sets the fully-qualified name of the class to disassemble. - * @param cn fully-qualified name of the class to disassemble - */ - public void setClassname(final String cn) { - this.classname = cn; - } // end method 'setClassname(String)' - - /** - * Sets the output for the task. - * @param f output for the task - */ - public void setOutput(final File f) { - this.output = f; - } // end method 'setOutput(File)' - - /** - * Adds a nested classpath element to the task. - * @param p classpath element to add - */ - public void addClasspath(final Path p) { - if (p != null) { - this.classpaths.add(p); - } // end if - } // end method 'addClasspath(Path)' - - /** - * Actually executes the task. - */ - public void execute() throws BuildException { - if (this.classname == null) { - throw new BuildException("'classname' attribute is not set.", - getLocation()); - } // end if - - final List classpath = new LinkedList(); - for (Path p : this.classpaths) { - for (String s : p.list()) { - classpath.add(new File(s).getAbsolutePath()); - } // end for - } // end for - - try { - final OutputStream out = - this.output == null ? System.out : new FileOutputStream(this.output); - Disassembler.disassemble(this.classname, new ClassPath(classpath), out); - } catch (final IOException ioe) { - throw new BuildException(ioe.getMessage(), ioe, getLocation()); - } catch (final BaristaException be) { - throw new BuildException(be.getMessage(), be, getLocation()); - } // end try/catch - } // end method 'execute()' - -} // end class 'AntDisassembleTask' rmfile ./api/src/fr/x9c/barista/api/AntDisassembleTask.java hunk ./api/src/fr/x9c/barista/api/AntPrintTask.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.LinkedList; -import java.util.List; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; - -/** - * This class implements an Ant task - * printing a class.
- * The task supports the following attributes: - *
    - *
  • classname: fully-qualified name of the class to print
    - * string - no default value, should be set - *
  • output: where to print the class
    - file defaults to null (which means standard output) - *

- * The task should also be supplied a nested <classpath> element - * to know where to look for class files. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class AntPrintTask extends Task { - - /** Fully-qualified name of the class to be printed. */ - private String classname; - - /** Where to print the class (null means standard output). */ - private File output; - - /** Nested classpath elements. */ - private List classpaths; - - /** - * Creates a new task with default parameters. - */ - public AntPrintTask() { - this.classname = null; - this.output = null; - this.classpaths = new LinkedList(); - } // end empty constructor - - /** - * Sets the fully-qualified name of the class to print. - * @param cn fully-qualified name of the class to print - */ - public void setClassname(final String cn) { - this.classname = cn; - } // end method 'setClassname(String)' - - /** - * Sets the output for the task. - * @param f output for the task - */ - public void setOutput(final File f) { - this.output = f; - } // end method 'setOutput(File)' - - /** - * Adds a nested classpath element to the task. - * @param p classpath element to add - */ - public void addClasspath(final Path p) { - if (p != null) { - this.classpaths.add(p); - } // end if - } // end method 'addClasspath(Path)' - - /** - * Actually executes the task. - */ - public void execute() throws BuildException { - if (this.classname == null) { - throw new BuildException("'classname' attribute is not set.", - getLocation()); - } // end if - - final List classpath = new LinkedList(); - for (Path p : this.classpaths) { - for (String s : p.list()) { - classpath.add(new File(s).getAbsolutePath()); - } // end for - } // end for - - try { - final OutputStream out = - this.output == null ? System.out : new FileOutputStream(this.output); - Printer.print(this.classname, new ClassPath(classpath), out); - } catch (final IOException ioe) { - throw new BuildException(ioe.getMessage(), ioe, getLocation()); - } catch (final BaristaException be) { - throw new BuildException(be.getMessage(), be, getLocation()); - } // end try/catch - } // end method 'execute()' - -} // end class 'AntPrintTask' rmfile ./api/src/fr/x9c/barista/api/AntPrintTask.java hunk ./api/src/fr/x9c/barista/api/Assembler.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.InputStream; -import java.io.OutputStream; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Channel; -import fr.x9c.cadmium.kernel.Custom; -import fr.x9c.cadmium.kernel.Value; - -/** - * This class provides methods for class assembling from textual source. - * - * @author Xavier Clerc - * @version 2.0 - * @since 1.0 - */ -public final class Assembler { - - /** - * No instance of this class. - */ - private Assembler() { - } // end empty constructor - - /** - * Calls the callback to assemble a class. - * @param v version usef for encoding - should not be null - * @param computeStacks whether stack elements should be computed - * @param optimize whether optimizations should be enabled - * @param classPath class path (used for stack computations) - should not be null - * @param in where to read source - should not be null - * @param dest where to output bytecode - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - private static String callAssemble(final Version v, - final boolean computeStacks, - final boolean optimize, - final String classPath, - final InputStream in, - final Value dest) - throws BaristaException { - assert v != null : "null v"; - assert classPath != null : "null classPath"; - assert in != null : "null in"; - assert dest != null : "null dest"; - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(in)); - final Value i = Value.createFromBlock(b); - final Value res = - API.callback("fr.x9c.barista.api.Assembler.assemble", - v.toValue(), - computeStacks ? Value.TRUE : Value.FALSE, - optimize ? Value.TRUE : Value.FALSE, - Value.createFromBlock(Block.createString(classPath)), - i, - dest); - return API.stringOfUTF8(res); - } // end method 'callAssemble(Version, boolean, boolean, String, InputStream, Value)' - - /** - * Assembles from a textual source. - * @param v version usef for encoding - should not be null - * @param computeStacks whether stack elements should be computed - * @param optimize whether optimizations should be enabled - * @param classPath class path (used for stack computations) - should not be null - * @param in where to read source - should not be null - * @param out where to output bytecode - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final Version v, - final boolean computeStacks, - final boolean optimize, - final String classPath, - final InputStream in, - final OutputStream out) - throws BaristaException { - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(out)); - final Block c = Block.createBlock(1, Value.createFromBlock(b)); - final Block d = Block.createBlock(0, Value.createFromBlock(c)); - return callAssemble(v, computeStacks, optimize, classPath, in, Value.createFromBlock(d)); - } // end method 'assemble(Version, boolean, boolean, String, InputStream, OutputStream)' - - /** - * Assembles from a textual source. - * @param v version usef for encoding - should not be null - * @param in where to read source - should not be null - * @param out where to output bytecode - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final Version v, - final InputStream in, - final OutputStream out) - throws BaristaException { - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(out)); - final Block c = Block.createBlock(1, Value.createFromBlock(b)); - final Block d = Block.createBlock(0, Value.createFromBlock(c)); - return callAssemble(v, false, false, ".", in, Value.createFromBlock(d)); - } // end method 'assemble(Version, InputStream, OutputStream)' - - /** - * Assembles from a textual source. - * @param in where to read source - should not be null - * @param out where to output bytecode - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final InputStream in, - final OutputStream out) - throws BaristaException { - return assemble(Version.Java_1_6, in, out); - } // end method 'assemble(InputStream, OutputStream)' - - /** - * Assembles from a textual source. - * @param v version usef for encoding - should not be null - * @param computeStacks whether stack elements should be computed - * @param optimize whether optimizations should be enabled - * @param classPath class path (used for stack computations) - should not be null - * @param in where to read source - should not be null - * @param path where to output bytecode (needed subdirectories will be created) - * - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final Version v, - final boolean computeStacks, - final boolean optimize, - final String classPath, - final InputStream in, - final String path) - throws BaristaException { - final Block b = Block.createString(path); - final Block d = Block.createBlock(1, Value.createFromBlock(b)); - return callAssemble(v, computeStacks, optimize, classPath, in, Value.createFromBlock(d)); - } // end method 'assemble(Version, boolean, boolean, String, InputStream, String)' - - /** - * Assembles from a textual source. - * @param v version usef for encoding - should not be null - * @param in where to read source - should not be null - * @param path where to output bytecode (needed subdirectories will be created) - * - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final Version v, - final InputStream in, - final String path) - throws BaristaException { - final Block b = Block.createString(path); - final Block d = Block.createBlock(1, Value.createFromBlock(b)); - return callAssemble(v, false, false, ".", in, Value.createFromBlock(d)); - } // end method 'assemble(Version, InputStream, String)' - - /** - * Assembles from a textual source. - * @param in where to read source - should not be null - * @param path where to output bytecode (needed subdirectories will be created) - * - should not be null - * @return the name of the assembled class - * @throws BaristaException if an errors occurs while assembling - */ - public static String assemble(final InputStream in, - final String path) - throws BaristaException { - return assemble(Version.Java_1_6, in, path); - } // end method 'assemble(InputStream, String)' - -} // end class 'Assembler' rmfile ./api/src/fr/x9c/barista/api/Assembler.java hunk ./api/src/fr/x9c/barista/api/Attribute.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.primitives.stdlib.Hash; -import fr.x9c.cadmium.support.Helper; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents an attribute of a Java element. - * - * @author Xavier Clerc - * @version 2.0 - * @since 1.0 - */ -public abstract class Attribute implements ToValue { - - /** Hash value for 'AnnotationDefault' attribute. */ - public static final Value HASH_ANNOTATION_DEFAULT = - Hash.hashVariant("AnnotationDefault"); - - /** Hash value for 'Code' attribute. */ - public static final Value HASH_CODE = - Hash.hashVariant("Code"); - - /** Hash value for 'ConstantValue' attribute. */ - public static final Value HASH_CONSTANT_VALUE = - Hash.hashVariant("ConstantValue"); - - /** Hash value for 'Deprecated' attribute. */ - public static final Value HASH_DEPRECATED = - Hash.hashVariant("Deprecated"); - - /** Hash value for 'EnclosingMethod' attribute. */ - public static final Value HASH_ENCLOSING_METHOD = - Hash.hashVariant("EnclosingMethod"); - - /** Hash value for 'Exceptions' attribute. */ - public static final Value HASH_EXCEPTIONS = - Hash.hashVariant("Exceptions"); - - /** Hash value for 'InnerClasses' attribute. */ - public static final Value HASH_INNER_CLASSES = - Hash.hashVariant("InnerClasses"); - - /** Hash value for 'LineNumberTable' attribute. */ - public static final Value HASH_LINE_NUMBER_TABLE = - Hash.hashVariant("LineNumberTable"); - - /** Hash value for 'LocalVariableTable' attribute. */ - public static final Value HASH_LOCAL_VARIABLE_TABLE = - Hash.hashVariant("LocalVariableTable"); - - /** Hash value for 'LocalVariableTypeTable' attribute. */ - public static final Value HASH_LOCAL_VARIABLE_TYPE_TABLE = - Hash.hashVariant("LocalVariableTypeTable"); - - /** Hash value for 'Module' attribute. */ - public static final Value HASH_MODULE = - Hash.hashVariant("Module"); - - /** Hash value for 'RuntimeInvisibleAnnotations' attribute. */ - public static final Value HASH_RUNTIME_INVISIBLE_ANNOTATIONS = - Hash.hashVariant("RuntimeInvisibleAnnotations"); - - /** Hash value for 'RuntimeInvisibleTypeAnnotations' attribute. */ - public static final Value HASH_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS = - Hash.hashVariant("RuntimeInvisibleTypeAnnotations"); - - /** Hash value for 'RuntimeInvisibleParameterAnnotations' attribute. */ - public static final Value HASH_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = - Hash.hashVariant("RuntimeInvisibleParameterAnnotations"); - - /** Hash value for 'RuntimeVisibleAnnotations' attribute. */ - public static final Value HASH_RUNTIME_VISIBLE_ANNOTATIONS = - Hash.hashVariant("RuntimeVisibleAnnotations"); - - /** Hash value for 'RuntimeVisibleParameterAnnotations' attribute. */ - public static final Value HASH_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = - Hash.hashVariant("RuntimeVisibleParameterAnnotations"); - - /** Hash value for 'RuntimeVisibleTypeAnnotations' attribute. */ - public static final Value HASH_RUNTIME_VISIBLE_TYPE_ANNOTATIONS = - Hash.hashVariant("RuntimeVisibleTypeAnnotations"); - - /** Hash value for 'Signature' attribute. */ - public static final Value HASH_SIGNATURE = - Hash.hashVariant("Signature"); - - /** Hash value for 'SourceDebugExtension' attribute. */ - public static final Value HASH_SOURCE_DEBUG_EXTENSION = - Hash.hashVariant("SourceDebugExtension"); - - /** Hash value for 'SourceFile' attribute. */ - public static final Value HASH_SOURCE_FILE = - Hash.hashVariant("SourceFile"); - - /** Hash value for 'Synthetic' attribute. */ - public static final Value HASH_SYNTHETIC = - Hash.hashVariant("Synthetic"); - - /** Hash value for 'Synthetic' attribute. */ - public static final Value HASH_STACK_MAP_TABLE = - Hash.hashVariant("StackMapTable"); - - /** Hash value for 'Unknown' attribute. */ - public static final Value HASH_UNKNOWN = - Hash.hashVariant("Unknown"); - - /** - * Parent class of all constant values embedded in attributes. - */ - public static abstract class ConstantVal implements ToValue { - - /** - * Ensures that no constant value could be defined outside this file. - */ - private ConstantVal() { - } // end empty constructor - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static ConstantVal fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - switch (b.getTag()) { - case 0: return new LongValue(b.get(0).asBlock().asInt64()); - case 1: return new FloatValue((float) b.get(0).asBlock().asDouble()); - case 2: return new DoubleValue(b.get(0).asBlock().asDouble()); - case 3: return new BooleanValue(b.get(0) == Value.TRUE); - case 4: return new ByteValue((byte) b.get(0).asLong()); - case 5: return new CharValue((char) b.get(0).asLong()); - case 6: return new ShortValue((short) b.get(0).asLong()); - case 7: return new IntegerValue(b.get(0).asBlock().asInt32()); - case 8: return new StringValue(API.stringOfUTF8(b.get(0))); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end method 'fromValue(Value)' - - } // end inner-class 'ConstantVal' - - /** - * Represents a long value embedded inside an attribute. - */ - public static final class LongValue extends ConstantVal { - - /** The underlying value. */ - private final long value; - - /** - * Constructs a long value. - * @param v value - */ - public LongValue(final long v) { - this.value = v; - } // end constructor(long) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public long getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, Helper.createInt64(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "LongValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof LongValue) { - final LongValue that = (LongValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LongValue' - - /** - * Represents a float value embedded inside an attribute. - */ - public static final class FloatValue extends ConstantVal { - - /** The underlying value. */ - private final float value; - - /** - * Constructs a float value. - * @param v value - */ - public FloatValue(final float v) { - this.value = v; - } // end constructor(float) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public float getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, Helper.createFloat(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "FloatValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof FloatValue) { - final FloatValue that = (FloatValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'FloatValue' - - /** - * Represents a double value embedded inside an attribute. - */ - public static final class DoubleValue extends ConstantVal { - - /** The underlying value. */ - private final double value; - - /** - * Constructs a double value. - * @param v value - */ - public DoubleValue(final double v) { - this.value = v; - } // end constructor(double) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public double getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, Helper.createFloat(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "DoubleValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return (int) this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof DoubleValue) { - final DoubleValue that = (DoubleValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'DoubleValue' - - /** - * Represents a boolean value embedded inside an attribute. - */ - public static final class BooleanValue extends ConstantVal { - - /** The underlying value. */ - private final boolean value; - - /** - * Constructs a boolean value. - * @param v value - */ - public BooleanValue(final boolean v) { - this.value = v; - } // end constructor(boolean) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public boolean getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(3, this.value ? Value.TRUE : Value.FALSE); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "BooleanValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value ? 1 : 0; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof BooleanValue) { - final BooleanValue that = (BooleanValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'BooleanValue' - - /** - * Represents a byte value embedded inside an attribute. - */ - public static final class ByteValue extends ConstantVal { - - /** The underlying value. */ - private final byte value; - - /** - * Constructs a byte value. - * @param v value - */ - public ByteValue(final byte v) { - this.value = v; - } // end constructor(byte) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public byte getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(4, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "ByteValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof ByteValue) { - final ByteValue that = (ByteValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ByteValue' - - /** - * Represents a char value embedded inside an attribute. - */ - public static final class CharValue extends ConstantVal { - - /** The underlying value. */ - private final char value; - - /** - * Constructs a char value. - * @param v value - */ - public CharValue(final char v) { - this.value = v; - } // end constructor(char) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public char getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(5, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "CharValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof CharValue) { - final CharValue that = (CharValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'CharValue' - - /** - * Represents a short value embedded inside an attribute. - */ - public static final class ShortValue extends ConstantVal { - - /** The underlying value. */ - private final short value; - - /** - * Constructs a short value. - * @param v value - */ - public ShortValue(final short v) { - this.value = v; - } // end constructor(short) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public short getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(6, Value.createFromLong(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "ShortValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof ShortValue) { - final ShortValue that = (ShortValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ShortValue' - - /** - * Represents a integer value embedded inside an attribute. - */ - public static final class IntegerValue extends ConstantVal { - - /** The underlying value. */ - private final int value; - - /** - * Constructs a integer value. - * @param v value - */ - public IntegerValue(final int v) { - this.value = v; - } // end constructor(integer) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public int getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(7, Helper.createInt32(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "IntegerValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof IntegerValue) { - final IntegerValue that = (IntegerValue) obj; - return this.value == that.value; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IntegerValue' - - /** - * Represents a string value embedded inside an attribute. - */ - public static final class StringValue extends ConstantVal { - - /** The underlying value. */ - private final String value; - - /** - * Constructs a string value. - * @param v value - should not be null - */ - public StringValue(final String v) { - assert v != null : "null v"; - this.value = v; - } // end constructor(String) - - /** - * Returns the underlying value. - * @return the underlying value - */ - public String getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(8, API.createUTF8(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "StringValue(" + this.value + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.value.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof StringValue) { - final StringValue that = (StringValue) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'StringValue' - - /** - * This class implements elements to be used in an exception table. - */ - public static final class ExceptionTableElement implements ToValue { - - /** The starting offset of protected code. */ - private final int start; - - /** The ending offset of protected code. */ - private final int end; - - /** The handler offset. */ - private final int handler; - - /** The exception to be caught (null means all). */ - private final String exception; - - /** - * Constructs an exception table element from offsets and name. - * @param s starting offset of protected code - should be in 0..65535 - * @param e ending offset of protected code - should be in 0..65535 - * @param h handler offset - should be in 0..65535 - * @param exn exception to be caught (null means all) - */ - public ExceptionTableElement(final int s, - final int e, - final int h, - final String exn) { - assert (s >= 0) && (s <= 65535) : "invalid s"; - assert (e >= 0) && (e <= 65535) : "invalid e"; - assert (h >= 0) && (h <= 65535) : "invalid h"; - this.start = s; - this.end = e; - this.handler = h; - this.exception = exn; - } // end constructor(int, int, int, String) - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Value exn; - if (this.exception == null) { - exn = Value.ZERO; - } else { - exn = Value.createFromBlock(Block.createBlock(0, API.createClassName(this.exception))); - } // end if/else - final Block b = Block.createBlock(0, - Value.createFromLong(this.start), - Value.createFromLong(this.end), - Value.createFromLong(this.handler), - exn); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static ExceptionTableElement fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - return new ExceptionTableElement(b.get(0).asLong(), - b.get(1).asLong(), - b.get(2).asLong(), - b.get(3) == Value.ZERO - ? null - : API.stringOfClassName(b.get(3).asBlock().get(0))); - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - return "ExceptionTableElement(" - + this.start + ", " - + this.end + ", " - + this.handler + ", " - + this.exception + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.start - + this.end - + this.handler - + (this.exception != null ? this.exception.hashCode() : 0); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof ExceptionTableElement) { - final ExceptionTableElement that = (ExceptionTableElement) obj; - return (this.start == that.start) - && (this.end == that.end) - && (this.handler == that.handler) - && API.nullOrEquals(this.exception, that.exception); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ExceptionTableElement' - - /** - * This class implements a code value. - */ - public static final class CodeValue implements ToValue { - - /** Maximum stack size. */ - private final int maxStack; - - /** Maximum locals size. */ - private final int maxLocals; - - /** Instructions. */ - private final List instructions; - - /** Exception table. */ - private final List exceptionTable; - - /** Attributes. */ - private final List attributes; - - /** - * Constructs a code value. - * @param ms maximum stack size - should be in 0..65535 - * @param ml maximum locals size - should be in 0..65535 - * @param c instructions - should not be null - * @param e exception table - should not be null - * @param a attribute - should not be null, - * should also be code attributes - */ - public CodeValue(final int ms, - final int ml, - final List c, - final List e, - final List a) { - assert (ms >= 0) && (ms <= 65535) : "invalid ms"; - assert (ml >= 0) && (ml <= 65535) : "invalid ml"; - assert c != null : "null c"; - assert e != null : "null e"; - assert a != null : "null a"; - assert areCodeAttributes(a) : "invalid attribute"; - this.maxStack = ms; - this.maxLocals = ml; - this.instructions = new LinkedList(c); - this.exceptionTable = new LinkedList(e); - this.attributes = new LinkedList(a); - } // end constructor(int, int, List, ...) - - /** - * Returns the maximum stack size. - * @return the maximum stack size - */ - public int getMaxStack() { - return this.maxStack; - } // end method 'getMaxStack()' - - /** - * Returns the maximum locals size. - * @return the maximum locals size - */ - public int getMaxLocals() { - return this.maxLocals; - } // end method 'getMaxLocals()' - - /** - * Returns the instruction list. - * @return the instruction list - */ - public List getInstructions() { - return new LinkedList(this.instructions); - } // end method 'getInstructions()' - - /** - * Returns the exception table. - * @return the exception table - */ - public List getExceptionTable() { - return new LinkedList(this.exceptionTable); - } // end method 'getExceptionTable()' - - /** - * Returns the attributes. - * @return the attributes - */ - public List getAttributes() { - return new LinkedList(this.attributes); - } // end method 'getAttributes()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("CodeValue(maxstack="); - sb.append(this.maxStack); - sb.append(",maxlocals="); - sb.append(this.maxLocals); - sb.append(",instructions="); - sb.append(this.instructions.toString()); - sb.append(",exceptiontable="); - sb.append(this.exceptionTable.toString()); - sb.append(",attributes="); - sb.append(this.attributes.toString()); - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof CodeValue) { - final CodeValue that = (CodeValue) obj; - return this.maxStack == that.maxStack - && this.maxLocals == that.maxLocals - && this.instructions.equals(that.instructions) - && this.exceptionTable.equals(that.exceptionTable) - && this.attributes.equals(that.attributes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.maxStack - + this.maxLocals - + this.instructions.hashCode() - + this.exceptionTable.hashCode() - + this.attributes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(5, 0); - b.set(0, Value.createFromLong(this.maxStack)); - b.set(1, Value.createFromLong(this.maxLocals)); - b.set(2, API.encodeList(this.instructions)); - b.set(3, API.encodeList(this.exceptionTable)); - b.set(4, API.encodeList(this.attributes)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static CodeValue fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final List instrs = new LinkedList(); - for (Value i : API.decodeList(b.get(2))) { - instrs.add(Instruction.fromValue(i)); - } // end for - final List exns = new LinkedList(); - for (Value e : API.decodeList(b.get(3))) { - exns.add(ExceptionTableElement.fromValue(e)); - } // end for - final List attrs = new LinkedList(); - for (Value a : API.decodeList(b.get(4))) { - attrs.add(Attribute.fromValue(a)); - } // end for - return new CodeValue(b.get(0).asLong(), - b.get(1).asLong(), - instrs, - exns, - attrs); - } // end method 'fromValue(Value)' - - } // end inner-class 'CodeValue' - - /** - * This class represents verification type infos used in stack frames. - */ - public static abstract class VerificationTypeInfo implements ToValue { - - /** The tag for 'type' elements. */ - private static final int TAG_TYPE = Hash.hashVariant("Class_or_interface").asLong(); - - /** The tag for 'array' elements. */ - private static final int TAG_ARRAY = Hash.hashVariant("Array_type").asLong(); - - /** - * This class represents verification type infos with no parameter. - */ - private static final class Simple extends VerificationTypeInfo { - - /** Type name. */ - private final String name; - - /** Type code. */ - private final int code; - - /** - * Constructs a verification type from name and code. - * @param n type name - should not be null - * @param c type code - */ - private Simple(final String n, final int c) { - assert n != null : "null n"; - this.name = n; - this.code = c; - } // end constructor(String, int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Value.createFromLong(this.code); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.name; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.code; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Simple) { - final Simple that = (Simple) obj; - return this.code == that.code; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Simple' - - /** Verification type info for "top". */ - public static final VerificationTypeInfo TopVariableInfo = new Simple("TopVariableInfo", 0); - - /** Verification type info for "integer". */ - public static final VerificationTypeInfo IntegerVariableInfo = new Simple("IntegerVariableInfo", 1); - - /** Verification type info for "float". */ - public static final VerificationTypeInfo FloatVariableInfo = new Simple("FloatVariableInfo", 2); - - /** Verification type info for "long". */ - public static final VerificationTypeInfo LongVariableInfo = new Simple("LongVariableInfo", 3); - - /** Verification type info for "double". */ - public static final VerificationTypeInfo DoubleVariableInfo = new Simple("DoubleVariableInfo", 4); - - /** Verification type info for "null". */ - public static final VerificationTypeInfo NullVariableInfo = new Simple("NullVariableInfo", 5); - - /** Verification type info for "uninitialized this". */ - public static final VerificationTypeInfo UninitializedThisVariableInfo = new Simple("UninitializedThisVariableInfo", 6); - - /** Verification type info for "object". */ - public static final class ObjectVariableInfo extends VerificationTypeInfo { - - /** Parameter. */ - private final Object param; - - /** - * Constructs an instance of the "object" variable info. - * @param t type name - should not be null - */ - public ObjectVariableInfo(final Instruction.TypeName t) { - assert t != null : "null t"; - this.param = t; - } // end constructor(Instruction.TypeName) - - /** - * Constructs an instance of the "object" variable info. - * @param d descriptor - should not be null - */ - public ObjectVariableInfo(final Descriptor.Array d) { - assert d != null : "null d"; - this.param = d; - } // end constructor(Descriptor.Array) - - /** - * Returns the underlying type name. - * @return the underlying type name if any, null otherwise - */ - public Instruction.TypeName getTypeName() { - return this.param instanceof Instruction.TypeName - ? (Instruction.TypeName) this.param - : null; - } // end method 'getTypeName()' - - /** - * Returns the underlying descriptor. - * @return the underlying descriptor if any, null otherwise - */ - public Descriptor.Array getDescriptor() { - return this.param instanceof Descriptor.Array - ? (Descriptor.Array) this.param - : null; - } // end method 'getDescriptor()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - if (this.param instanceof Instruction.TypeName) { - final Block b = Block.createBlock(1, 0); - b.set(0, Instruction.wrap("Class_or_interface", ((Instruction.TypeName) this.param).toValue())); - return Value.createFromBlock(b); - } else { - final Block b = Block.createBlock(1, 0); - b.set(0, Instruction.wrap("Array", ((Instruction.TypeName) this.param).toValue())); - return Value.createFromBlock(b); - } // end if/else - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ObjectVariableInfo(" + this.param.toString() + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.param.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ObjectVariableInfo) { - final ObjectVariableInfo that = (ObjectVariableInfo) obj; - return this.param.equals(that.param); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ObjectVariableInfo' - - /** Verification type info for "uninitialized". */ - public static final class UninitializedVariableInfo extends VerificationTypeInfo { - - /** Code offset of object creation. */ - private final int offset; - - /** - * Constructs an instance of the "uninitialized" variable info. - * @param o code offset of object creation - should be in 0..65535 - */ - public UninitializedVariableInfo(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid o"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the code offset of object creation. - * @return the code offset of object creation - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "UninitializedVariableInfo(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof UninitializedVariableInfo) { - final UninitializedVariableInfo that = (UninitializedVariableInfo) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'UninitializedVariableInfo' - - private VerificationTypeInfo() { - } // end empty constructor - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - @SuppressWarnings("fallthrough") - static VerificationTypeInfo fromValue(final Value v) { - assert v != null : "null v"; - if (v.isLong()) { - switch (v.asLong()) { - case 0: return TopVariableInfo; - case 1: return IntegerVariableInfo; - case 2: return FloatVariableInfo; - case 3: return LongVariableInfo; - case 4: return DoubleVariableInfo; - case 5: return NullVariableInfo; - case 6: return UninitializedThisVariableInfo; - default: - assert false : "invalid tag"; - return null; - } // end switch - } else { - final Block b = v.asBlock(); - switch (b.getTag()) { - case 0: if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new ObjectVariableInfo(Instruction.TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new ObjectVariableInfo((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 1: return new UninitializedVariableInfo((short) b.get(0).asBlock().get(1).asLong()); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end if/else - } // end method 'fromValue(Value)' - - } // end inner-class 'VerificationTypeInfo' - - /** - * This class represents stack map frames. - */ - public static abstract class StackMapFrame implements ToValue { - - /** Code offset. */ - protected final int offset; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - */ - private StackMapFrame(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid o"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the code offset. - * @return the code offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** Stack map frame for 'same'. */ - public static final class Same extends StackMapFrame { - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - */ - public Same(final int o) { - super(o); - } // end constructor(int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Same(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Same) { - final Same that = (Same) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Same' - - /** Stack map frame for 'same locals, 1 stack item'. */ - public static final class SameLocals1StackItem extends StackMapFrame { - - /** Type of stack item. */ - private final VerificationTypeInfo type; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - * @param t type of stack item - should not be null - */ - public SameLocals1StackItem(final int o, final VerificationTypeInfo t) { - super(o); - assert t != null : "null t"; - this.type = t; - } // end constructor(int, VerificationTypeInfo) - - /** - * Returns the type of the stack item. - * @return the type of the stack item - */ - public VerificationTypeInfo getType() { - return this.type; - } // end method 'getType()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, Value.createFromLong(this.offset), this.type.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "SameLocals1StackItem(" + this.offset + ", " + this.type + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.type.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof SameLocals1StackItem) { - final SameLocals1StackItem that = (SameLocals1StackItem) obj; - return (this.offset == that.offset) - && this.type.equals(that.type); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SameLocals1StackItem' - - /** Stack map frame for 'chop1'. */ - public static final class Chop1 extends StackMapFrame { - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - */ - public Chop1(final int o) { - super(o); - } // end constructor(int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Chop1(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Chop1) { - final Chop1 that = (Chop1) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Chop1' - - /** Stack map frame for 'chop2'. */ - public static final class Chop2 extends StackMapFrame { - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - */ - public Chop2(final int o) { - super(o); - } // end constructor(int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(3, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Chop2(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Chop2) { - final Chop2 that = (Chop2) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Chop2' - - /** Stack map frame for 'chop3'. */ - public static final class Chop3 extends StackMapFrame { - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - */ - public Chop3(final int o) { - super(o); - } // end constructor(int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(4, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Chop3(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Chop3) { - final Chop3 that = (Chop3) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Chop3' - - /** Stack map frame for 'append1'. */ - public static final class Append1 extends StackMapFrame { - - /** Type of stack item. */ - private final VerificationTypeInfo type; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - * @param t type of stack item - should not be null - */ - public Append1(final int o, final VerificationTypeInfo t) { - super(o); - assert t != null : "null t"; - this.type = t; - } // end constructor(int, VerificationTypeInfo) - - /** - * Returns the type of the stack item. - * @return the type of the stack item - */ - public VerificationTypeInfo getType() { - return this.type; - } // end method 'getType()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(5, Value.createFromLong(this.offset), this.type.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Append1(" + this.offset + ", " + this.type + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.type.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Append1) { - final Append1 that = (Append1) obj; - return (this.offset == that.offset) - && this.type.equals(that.type); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Append1' - - /** Stack map frame for 'append2'. */ - public static final class Append2 extends StackMapFrame { - - /** Type of first added stack item. */ - private final VerificationTypeInfo type1; - - /** Type of second added stack item. */ - private final VerificationTypeInfo type2; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - * @param t1 type of stack item - should not be null - * @param t2 type of stack item - should not be null - */ - public Append2(final int o, - final VerificationTypeInfo t1, - final VerificationTypeInfo t2) { - super(o); - assert t1 != null : "null t1"; - assert t2 != null : "null t2"; - this.type1 = t1; - this.type2 = t2; - } // end constructor(int, VerificationTypeInfo, VerificationTypeInfo) - - /** - * Returns the type of the first added stack item. - * @return the type of the first added stack item - */ - public VerificationTypeInfo getType1() { - return this.type1; - } // end method 'getType1()' - - /** - * Returns the type of the second added stack item. - * @return the type of the second added stack item - */ - public VerificationTypeInfo getType2() { - return this.type2; - } // end method 'getType2()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(6, Value.createFromLong(this.offset), this.type1.toValue(), this.type2.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Append2(" + this.offset + ", " + this.type1 + ", " + this.type2 + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.type1.hashCode() + this.type2.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Append2) { - final Append2 that = (Append2) obj; - return (this.offset == that.offset) - && this.type1.equals(that.type1) - && this.type2.equals(that.type2); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Append2' - - /** Stack map frame for 'append3'. */ - public static final class Append3 extends StackMapFrame { - - /** Type of first added stack item. */ - private final VerificationTypeInfo type1; - - /** Type of second added stack item. */ - private final VerificationTypeInfo type2; - - /** Type of third added stack item. */ - private final VerificationTypeInfo type3; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - * @param t1 type of stack item - should not be null - * @param t2 type of stack item - should not be null - * @param t3 type of stack item - should not be null - */ - public Append3(final int o, - final VerificationTypeInfo t1, - final VerificationTypeInfo t2, - final VerificationTypeInfo t3) { - super(o); - assert t1 != null : "null t1"; - assert t2 != null : "null t2"; - assert t3 != null : "null t3"; - this.type1 = t1; - this.type2 = t2; - this.type3 = t3; - } // end constructor(int, VerificationTypeInfo, VerificationTypeInfo, VerificationTypeInfo) - - /** - * Returns the type of the first added stack item. - * @return the type of the first added stack item - */ - public VerificationTypeInfo getType1() { - return this.type1; - } // end method 'getType1()' - - /** - * Returns the type of the second added stack item. - * @return the type of the second added stack item - */ - public VerificationTypeInfo getType2() { - return this.type2; - } // end method 'getType2()' - - /** - * Returns the type of the third added stack item. - * @return the type of the third added stack item - */ - public VerificationTypeInfo getType3() { - return this.type3; - } // end method 'getType3()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(7, Value.createFromLong(this.offset), this.type1.toValue(), this.type2.toValue(), this.type3.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Append3(" + this.offset + ", " + this.type1 + ", " + this.type2 + ", " + this.type3 + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.type1.hashCode() + this.type2.hashCode() + this.type3.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Append3) { - final Append3 that = (Append3) obj; - return (this.offset == that.offset) - && this.type1.equals(that.type1) - && this.type2.equals(that.type2) - && this.type3.equals(that.type3); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Append3' - - /** Stack map frame for 'full'. */ - public static final class Full extends StackMapFrame { - - /** Type of first added stack item. */ - private final List locals; - - /** Type of second added stack item. */ - private final List operands; - - /** - * Constructs an instance from a code offset. - * @param o code offset - should be in 0..65535 - * @param locs types of locals - should not be null - * @param ops types of stack operands - should not be null - */ - public Full(final int o, - final List locs, - final List ops) { - super(o); - assert locs != null : "null locs"; - assert ops != null : "null ops"; - this.locals = new LinkedList(locs); - this.operands = new LinkedList(ops); - } // end constructor(int, List, List) - - /** - * Returns the types of the locals. - * @return the types of the locals - */ - public List getLocals() { - return new LinkedList(this.locals); - } // end method 'getLocals()' - - /** - * Returns the types of the operands. - * @return the types of the operands - */ - public List getOperands() { - return new LinkedList(this.operands); - } // end method 'getOperands()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(8, Value.createFromLong(this.offset), API.encodeList(this.locals), API.encodeList(this.operands)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Full(" + this.offset + ", " + this.locals + ", " + this.operands + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.locals.hashCode() + this.operands.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Full) { - final Full that = (Full) obj; - return (this.offset == that.offset) - && this.locals.equals(that.locals) - && this.operands.equals(that.operands); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Full' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static StackMapFrame fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - switch (b.getTag()) { - case 0: return new Same(b.get(0).asLong()); - case 1: return new SameLocals1StackItem(b.get(0).asLong(), VerificationTypeInfo.fromValue(b.get(1))); - case 2: return new Chop1(b.get(0).asLong()); - case 3: return new Chop2(b.get(0).asLong()); - case 4: return new Chop3(b.get(0).asLong()); - case 5: return new Append1(b.get(0).asLong(), VerificationTypeInfo.fromValue(b.get(1))); - case 6: return new Append2(b.get(0).asLong(), VerificationTypeInfo.fromValue(b.get(1)), VerificationTypeInfo.fromValue(b.get(2))); - case 7: return new Append3(b.get(0).asLong(), VerificationTypeInfo.fromValue(b.get(1)), VerificationTypeInfo.fromValue(b.get(2)), VerificationTypeInfo.fromValue(b.get(3))); - case 8: - final List locals = new LinkedList(); - for (Value l : API.decodeList(b.get(1))) { - locals.add(VerificationTypeInfo.fromValue(l)); - } // end for - final List operands = new LinkedList(); - for (Value o : API.decodeList(b.get(2))) { - operands.add(VerificationTypeInfo.fromValue(o)); - } // end for - return new Full(b.get(0).asLong(), locals, operands); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end method 'fromValue(Value)' - - } // end inner-class 'StackMapFrame' - - /** Whether the attribute can be a field attribute. */ - private final boolean isField; - - /** Whether the attribute can be a method attribute. */ - private final boolean isMethod; - - /** Whether the attribute can be a class attribute. */ - private final boolean isClass; - - /** Whether the attribute can be a code attribute. */ - private final boolean isCode; - - /** - * Constructs an attribute. - * @param f whether the attribute can be a field attribute - * @param m whether the attribute can be a method attribute - * @param c whether the attribute can be a class attribute - * @param d whether the attribute can be a code attribute - */ - private Attribute(final boolean f, - final boolean m, - final boolean c, - final boolean d) { - this.isField = f; - this.isMethod = m; - this.isClass = c; - this.isCode = d; - } // end constructor(boolean, boolean, boolean, boolean) - - /** - * Tests whether the attribute can be a field attribute. - * @return true if the attribute can be a field attribute, - * false otherwise - */ - public final boolean isFieldAttribute() { - return this.isField; - } // end method 'isFieldAttribute()' - - /** - * Tests whether the attribute can be a method attribute. - * @return true if the attribute can be a method attribute, - * false otherwise - */ - public final boolean isMethodAttribute() { - return this.isMethod; - } // end method 'isMethodAttribute()' - - /** - * Tests whether the attribute can be a class attribute. - * @return true if the attribute can be a class attribute, - * false otherwise - */ - public final boolean isClassAttribute() { - return this.isClass; - } // end method 'isClassAttribute()' - - /** - * Tests whether the attribute can be a code attribute. - * @return true if the attribute can be a code attribute, - * false otherwise - */ - public final boolean isCodeAttribute() { - return this.isCode; - } // end method 'isCodeAttribute()' - - /** - * {@inheritDoc} - */ - @Override - public final String toString() { - final Class c = this.getClass(); - if (c.equals(Deprecated.class)) { - return "Deprecated"; - } else if (c.equals(Synthetic.class)) { - return "Synthetic"; - } else { - return c.getSimpleName() + "(-)"; - } // end if/elsif/else - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public final int hashCode() { - return this.getClass().hashCode(); - } // end method 'toString()' - - /** - * Tests whether a list contains only field attributes. - * @param l list to test - should not be null - * @return true if the list contains only field attributes, - * false otherwise - */ - public static boolean areFieldAttributes(final List l) { - assert l != null : "null l"; - for (Attribute a : l) { - if (!a.isFieldAttribute()) { - return false; - } // end if - } // end for - return true; - } // end method 'areFieldAttributes(List)' - - /** - * Tests whether a list contains only method attributes. - * @param l list to test - should not be null - * @return true if the list contains only method attributes, - * false otherwise - */ - public static boolean areMethodAttributes(final List l) { - assert l != null : "null l"; - for (Attribute a : l) { - if (!a.isMethodAttribute()) { - return false; - } // end if - } // end for - return true; - } // end method 'areMethodAttributes(List)' - - /** - * Tests whether a list contains only class attributes. - * @param l list to test - should not be null - * @return true if the list contains only class attributes, - * false otherwise - */ - public static boolean areClassAttributes(final List l) { - assert l != null : "null l"; - for (Attribute a : l) { - if (!a.isClassAttribute()) { - return false; - } // end if - } // end for - return true; - } // end method 'areClassAttributes(List)' - - /** - * Tests whether a list contains only code attributes. - * @param l list to test - should not be null - * @return true if the list contains only code attributes, - * false otherwise - */ - public static boolean areCodeAttributes(final List l) { - assert l != null : "null l"; - for (Attribute a : l) { - if (!a.isCodeAttribute()) { - return false; - } // end if - } // end for - return true; - } // end method 'areCodeAttributes(List)' - - /** - * This class implements an 'AnnotationDefault' attribute. - */ - public static final class AnnotationDefault extends Attribute { - - /** Attribute value. */ - private final Annotation.ElementValue value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public AnnotationDefault(final Annotation.ElementValue v) { - super(false, true, false, false); - assert v != null : "null v"; - this.value = v; - } // end constructor(Annotation.ElementValue) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public Annotation.ElementValue getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_ANNOTATION_DEFAULT, - this.value.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof AnnotationDefault) { - final AnnotationDefault that = (AnnotationDefault) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'AnnotationDefault' - - /** - * This class implements a 'Code' attribute. - */ - public static final class Code extends Attribute { - - /** Attribute value. */ - private final CodeValue value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public Code(final CodeValue v) { - super(false, true, false, false); - assert v != null : "null v"; - this.value = v; - } // end constructor(CodeValue) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public CodeValue getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_CODE, - this.value.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Code) { - final Code that = (Code) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Code' - - /** - * This class implements a 'ConstantValue' attribute. - */ - public static final class ConstantValue extends Attribute { - - /** Attribute value. */ - private final ConstantVal value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public ConstantValue(final ConstantVal v) { - super(true, false, false, false); - assert v != null : "null v"; - this.value = v; - } // end constructor(ConstantVal) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public ConstantVal getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_CONSTANT_VALUE, - this.value.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof ConstantValue) { - final ConstantValue that = (ConstantValue) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ConstantValue' - - /** - * This class implements a 'Deprecated' attribute. - */ - public static final class Deprecated extends Attribute { - - /** - * Constructs an attribute. - */ - public Deprecated() { - super(true, true, true, false); - } // end empty constructor - - /** - * {@inheritDoc} - */ - public Value toValue() { - return HASH_DEPRECATED; - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Deprecated) { - return true; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Deprecated' - - /** - * This class implements an 'EnclosingMethod' attribute. - */ - public static final class EnclosingMethod extends Attribute { - - /** Class name. */ - private final String className; - - /** Method name. */ - private final String methodName; - - /** Method return type descriptor. */ - private final Descriptor returnType; - - /** Method parameter type descriptors. */ - private final List parameterTypes; - - /** - * Constructs an attribute. - * @param cn class name - should not be null - * @param mn method name - should not be null - * @param mr method return type descriptor - should not be null - * @param mp method parameter type descriptors - should not be null, - * should also be non-void descriptors - * @throws BaristaException if one of the descriptors is not a valid descriptor - * @throws BaristaException if one of the attributes is not a valid attribute - */ - public EnclosingMethod(final String cn, - final String mn, - final Descriptor mr, - final List mp) - throws BaristaException { - super(false, false, true, false); - assert cn != null : "null cn"; - assert mn != null : "null mn"; - assert mr != null : "null mr"; - assert mp != null : "null mp"; - if (!mr.isFieldDescriptor()) { - throw new BaristaException("invalid descriptor for return type"); - } // end if - if (!Descriptor.areFieldDescriptors(mp)) { - throw new BaristaException("invalid descriptor for parameter type"); - } // end fi - this.className = cn; - this.methodName = mn; - this.returnType = mr; - this.parameterTypes = new LinkedList(mp); - } // end constructor(String, String, Descriptor, List) - - /** - * Constructs an attribute. - * @param cn class name - should not be null - */ - public EnclosingMethod(final String cn) { - super(false, false, true, false); - assert cn != null : "null cn"; - this.className = cn; - this.methodName = null; - this.returnType = null; - this.parameterTypes = null; - } // end constructor(String) - - /** - * Returns the class name. - * @return the class name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * Returns the method name. - * @return the method name - */ - public String getMethodName() { - return this.methodName; - } // end method 'getMethodName()' - - /** - * Returns the method return type. - * @return the method return type - */ - public Descriptor getReturnType() { - return this.returnType; - } // end method 'getReturnType()' - - /** - * Returns the method parameter types. - * @return the method parameter types - */ - public List getParameterTypes() { - return new LinkedList(this.parameterTypes); - } // end method 'getParameterTypes()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Value o; - if (this.methodName == null) { - o = Value.ZERO; - } else { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block m = Block.createBlock(0, - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - o = Value.createFromBlock(m); - } // end if/else - final Block c = Block.createBlock(0, - API.createClassName(this.className), - o); - final Block b = Block.createBlock(0, - HASH_ENCLOSING_METHOD, - Value.createFromBlock(c)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof EnclosingMethod) { - final EnclosingMethod that = (EnclosingMethod) obj; - return this.className.equals(that.className) - && API.nullOrEquals(this.methodName, that.methodName) - && API.nullOrEquals(this.returnType, that.returnType) - && API.nullOrEquals(this.parameterTypes, that.parameterTypes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'EnclosingMethod' - - /** - * This class implements an 'Exceptions' attribute. - */ - public static final class Exceptions extends Attribute { - - /** Attribute value. */ - private final List value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public Exceptions(final List v) { - super(false, true, false, false); - assert v != null : "null v"; - this.value = new LinkedList(v); - } // end constructor(List) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List getValue() { - return new LinkedList(this.value); - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final List l = new LinkedList(); - for (String s : this.value) { - l.add(API.createClassName(s)); - } // end value - final Block b = Block.createBlock(0, - HASH_EXCEPTIONS, - API.encodeValueList(l)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Exceptions) { - final Exceptions that = (Exceptions) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Exceptions' - - /** - * This class implements an 'InnerClasses' attribute. - */ - public static final class InnerClasses extends Attribute { - - /** Inner-class names. */ - private final List inners; - - /** Outer-class names. */ - private final List outers; - - /** Class names. */ - private final List names; - - /** Class flags. */ - private final List< List > flags; - - /** - * Constructs an attribute.
- * all passed lists should have the same size. - * @param i inner-class names - should not be null - * @param o outer-class names - should not be null - * @param n names - should not be null - * @param f class flags - should not be null, - * should also be inner-class flags - * @throws BaristaException if one of the flags is not a valid flag - */ - public InnerClasses(final List i, - final List o, - final List n, - final List< List > f) - throws BaristaException { - super(false, false, true, false); - assert i != null : "null i"; - assert o != null : "null o"; - assert n != null : "null n"; - assert f != null : "null f"; - for (List l : f) { - if (!AccessFlag.areInnerClassFlags(l)) { - throw new BaristaException("invalid flag"); - } // endif - } // end for - assert i.size() == o.size() - && o.size() == n.size() - && n.size() == f.size() : "parameters have different sizes"; - this.inners = new LinkedList(i); - this.outers = new LinkedList(o); - this.names = new LinkedList(n); - this.flags = new LinkedList< List >(); - for (List l : f) { - this.flags.add(new LinkedList(l)); - } // end for - } // end constructor(List, List, ...) - - /** - * Returns the inner class names. - * @return the inner class names - */ - public List getInners() { - return new LinkedList(this.inners); - } // end method 'getInners()' - - /** - * Returns the outer class names. - * @return the outer class names - */ - public List getOuters() { - return new LinkedList(this.outers); - } // end method 'getOuters()' - - /** - * Returns the class names. - * @return the class names - */ - public List getNames() { - return new LinkedList(this.names); - } // end method 'getNames()' - - /** - * Returns the class flags. - * @return the class flags - */ - public List< List > getFlags() { - final List< List > res = new LinkedList< List >(); - for (List l : this.flags) { - res.add(new LinkedList(l)); - } // end for - return res; - } // end method 'getFlags()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final List l = new LinkedList(); - final Iterator itInn = this.inners.iterator(); - final Iterator itOut = this.outers.iterator(); - final Iterator itNames = this.names.iterator(); - final Iterator< List > itFlags = this.flags.iterator(); - while (itInn.hasNext() && itOut.hasNext() - && itNames.hasNext() && itFlags.hasNext()) { - final String i = itInn.next(); - final String o = itOut.next(); - final String n = itNames.next(); - final List f = itFlags.next(); - final Value bi; - if (i == null) { - bi = Value.ZERO; - } else { - bi = Value.createFromBlock(Block.createBlock(0, API.createClassName(i))); - } // end if/else - final Value bo; - if (o == null) { - bo = Value.ZERO; - } else { - bo = Value.createFromBlock(Block.createBlock(0, API.createClassName(o))); - } // end if/else - final Value bn; - if (n == null) { - bn = Value.ZERO; - } else { - bn = Value.createFromBlock(Block.createBlock(0, API.createUTF8(n))); - } // end if/else - l.add(Value.createFromBlock(Block.createBlock(0, bi, bo, bn, API.encodeList(f)))); - } // end while - final Block b = Block.createBlock(0, - HASH_INNER_CLASSES, - API.encodeValueList(l)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof InnerClasses) { - final InnerClasses that = (InnerClasses) obj; - return this.inners.equals(that.inners) - && this.outers.equals(that.outers) - && this.names.equals(that.names) - && this.flags.equals(that.flags); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'InnerClasses' - - /** - * This class implements a 'LineNumberTable' attribute. - */ - public static final class LineNumberTable extends Attribute { - - /** Offets. */ - private final List offsets; - - /** Lines. */ - private final List lines; - - /** - * Constructs an attribute. - * @param ofs offets - should not be null, - * each value should be in 0..65535 - * @param ln lines - should not be null, - * each value should be in 0..65535 - */ - public LineNumberTable(final List ofs, - final List ln) { - super(false, false, false, true); - assert ofs != null : "null ofs"; - assert ln != null : "null ln"; - assert ofs.size() == ln.size() : "ofs and ln have different sizes"; - for (int o : ofs) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - } // end for - for (int l : ln) { - assert (l >= 0) && (l <= 65535) : "invalid line value"; - } // end for - this.offsets = new LinkedList(ofs); - this.lines = new LinkedList(ln); - } // end constructor(List, List) - - /** - * Returns the offsets. - * @return the offsets - */ - public List getOffsets() { - return new LinkedList(this.offsets); - } // end method 'getOffsets()' - - /** - * Returns the lines. - * @return the lines - */ - public List getLines() { - return new LinkedList(this.lines); - } // end method 'getLines()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final List l = new LinkedList(); - final Iterator itOffsets = this.offsets.iterator(); - final Iterator itLines = this.lines.iterator(); - while (itOffsets.hasNext() && itLines.hasNext()) { - final Block e = Block.createBlock(0, - Value.createFromLong(itOffsets.next()), - Value.createFromLong(itLines.next())); - l.add(Value.createFromBlock(e)); - } // end while - final Block b = Block.createBlock(0, - HASH_LINE_NUMBER_TABLE, - API.encodeValueList(l)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof LineNumberTable) { - final LineNumberTable that = (LineNumberTable) obj; - return this.offsets.equals(that.offsets) - && this.lines.equals(that.lines); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LineNumberTable' - - /** - * This class implements a 'LocalVariableTable' attribute. - */ - public static final class LocalVariableTable extends Attribute { - - /** Starting offets. */ - private final List starts; - - /** Ending offets. */ - private final List ends; - - /** Variable names. */ - private final List names; - - /** Variable descriptors. */ - private final List descriptors; - - /** Variable indexes. */ - private final List indexes; - - /** - * Constructs an attribute.
- * all passed lists should have the same size. - * @param s starting offsets - should not be null
, - * each value should be in 0..65535 - * @param e ending offsets - should not be null
, - * each value should be in 0..65535 - * @param n variable names - should not be null
- * @param d descriptors - should not be null
, - * should also be a non-void descriptor - * @param i indexes - should not be null
, - * each value should be in 0..65535 - * @throws BaristaException if one of the descriptors is not a valid descriptor - */ - public LocalVariableTable(final List s, - final List e, - final List n, - final List d, - final List i) - throws BaristaException { - super(false, false, false, true); - assert s != null : "null s"; - assert e != null : "null e"; - assert n != null : "null n"; - assert d != null : "null d"; - assert i != null : "null i"; - if (!Descriptor.areFieldDescriptors(d)) { - throw new BaristaException("invalid descriptor"); - } // end if - assert s.size() == e.size() - && e.size() == n.size() - && n.size() == d.size() - && d.size() == i.size() : "parameters have different sizes"; - for (int x : s) { - assert (x >= 0) && (x <= 65535) : "invalid offset value"; - } // end for - for (int x : e) { - assert (x >= 0) && (x <= 65535) : "invalid offset value"; - } // end for - for (int x : i) { - assert (x >= 0) && (x <= 65535) : "invalid index value"; - } // end for - this.starts = new LinkedList(s); - this.ends = new LinkedList(e); - this.names = new LinkedList(n); - this.descriptors = new LinkedList(d); - this.indexes = new LinkedList(i); - } // end constructor(List, List, ...) - - /** - * Returns the list of starting offsets. - * @return the list of starting offsets - */ - public List getStartingOffsets() { - return new LinkedList(this.starts); - } // end method 'getStartingOffsets()' - - /** - * Returns the list of ending offsets. - * @return the list of ending offsets - */ - public List getEndingOffsets() { - return new LinkedList(this.ends); - } // end method 'getEndingOffsets()' - - /** - * Returns the list of names. - * @return the list of names - */ - public List getNames() { - return new LinkedList(this.names); - } // end method 'getNames()' - - /** - * Returns the list of descriptors. - * @return the list of descriptors - */ - public List getDescriptors() { - return new LinkedList(this.descriptors); - } // end method 'getDescriptors()' - - /** - * Returns the list of indexes. - * @return the list of indexes - */ - public List getIndexes() { - return new LinkedList(this.indexes); - } // end method 'getIndexes()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final List l = new LinkedList(); - final Iterator itStarts = this.starts.iterator(); - final Iterator itEnds = this.ends.iterator(); - final Iterator itNames = this.names.iterator(); - final Iterator itDescs = this.descriptors.iterator(); - final Iterator itInd = this.indexes.iterator(); - while (itStarts.hasNext() && itEnds.hasNext() && itNames.hasNext() - && itDescs.hasNext() && itInd.hasNext()) { - final Block e = Block.createBlock(5, 0); - e.set(0, Value.createFromLong(itStarts.next())); - e.set(1, Value.createFromLong(itEnds.next())); - e.set(2, API.createUTF8(itNames.next())); - e.set(3, itDescs.next().toValue()); - e.set(4, Value.createFromLong(itInd.next())); - l.add(Value.createFromBlock(e)); - } // end while - final Block b = Block.createBlock(0, - HASH_LOCAL_VARIABLE_TABLE, - API.encodeValueList(l)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof LocalVariableTable) { - final LocalVariableTable that = (LocalVariableTable) obj; - return this.starts.equals(that.starts) - && this.ends.equals(that.ends) - && this.names.equals(that.names) - && this.descriptors.equals(that.descriptors) - && this.indexes.equals(that.indexes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LocalVariableTable' - - /** - * This class implements a 'LocalVariableTypeTable' attribute. - */ - public static final class LocalVariableTypeTable extends Attribute { - - /** Starting offets. */ - private final List starts; - - /** Ending offets. */ - private final List ends; - - /** Variable names. */ - private final List names; - - /** Variable type signatures. */ - private final List signatures; - - /** Variable indexes. */ - private final List indexes; - - /** - * Constructs an attribute.
- * all passed lists should have the same size. - * @param s starting offsets - should not be null
, - * each value should be in 0..65535 - * @param e ending offsets - should not be null
, - * each value should be in 0..65535 - * @param n variable names - should not be null
- * @param t type signatures - should not be null - * @param i indexes - should not be null, - * each value should be in 0..65535 - */ - public LocalVariableTypeTable(final List s, - final List e, - final List n, - final List t, - final List i) { - super(false, false, false, true); - assert s != null : "null s"; - assert e != null : "null e"; - assert n != null : "null n"; - assert t != null : "null t"; - assert i != null : "null i"; - assert s.size() == e.size() - && e.size() == n.size() - && n.size() == t.size() - && t.size() == i.size() : "parameters have different sizes"; - for (int x : s) { - assert (x >= 0) && (x <= 65535) : "invalid offset value"; - } // end for - for (int x : e) { - assert (x >= 0) && (x <= 65535) : "invalid offset value"; - } // end for - for (int x : i) { - assert (x >= 0) && (x <= 65535) : "invalid index value"; - } // end for - this.starts = new LinkedList(s); - this.ends = new LinkedList(e); - this.names = new LinkedList(n); - this.signatures = new LinkedList(t); - this.indexes = new LinkedList(i); - } // end constructor(List, List, ...) - - /** - * Returns the list of starting offsets. - * @return the list of starting offsets - */ - public List getStartingOffsets() { - return new LinkedList(this.starts); - } // end method 'getStartingOffsets()' - - /** - * Returns the list of ending offsets. - * @return the list of ending offsets - */ - public List getEndingOffsets() { - return new LinkedList(this.ends); - } // end method 'getEndingOffsets()' - - /** - * Returns the list of names. - * @return the list of names - */ - public List getNames() { - return new LinkedList(this.names); - } // end method 'getNames()' - - /** - * Returns the list of type signatures. - * @return the list of type signatures - */ - public List getSignatures() { - return new LinkedList(this.signatures); - } // end method 'getSignatures()' - - /** - * Returns the list of indexes. - * @return the list of indexes - */ - public List getIndexes() { - return new LinkedList(this.indexes); - } // end method 'getIndexes()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final List l = new LinkedList(); - final Iterator itStarts = this.starts.iterator(); - final Iterator itEnds = this.ends.iterator(); - final Iterator itNames = this.names.iterator(); - final Iterator itSigns = this.signatures.iterator(); - final Iterator itInd = this.indexes.iterator(); - while (itStarts.hasNext() && itEnds.hasNext() && itNames.hasNext() - && itSigns.hasNext() && itInd.hasNext()) { - final Block e = Block.createBlock(5, 0); - e.set(0, Value.createFromLong(itStarts.next())); - e.set(1, Value.createFromLong(itEnds.next())); - e.set(2, API.createUTF8(itNames.next())); - e.set(3, API.createFieldSignature(itSigns.next())); - e.set(4, Value.createFromLong(itInd.next())); - l.add(Value.createFromBlock(e)); - } // end while - final Block b = Block.createBlock(0, - HASH_LOCAL_VARIABLE_TYPE_TABLE, - API.encodeValueList(l)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof LocalVariableTypeTable) { - final LocalVariableTypeTable that = (LocalVariableTypeTable) obj; - return this.starts.equals(that.starts) - && this.ends.equals(that.ends) - && this.names.equals(that.names) - && this.signatures.equals(that.signatures) - && this.indexes.equals(that.indexes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LocalVariableTypeTable' - - /** - * This class implements a 'Module' attribute. - */ - public static final class Module extends Attribute { - - /** Attribute name. */ - private final String name; - - /** Attribute version. */ - private final String version; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public Module(final String n, final String v) { - super(false, false, true, false); - assert n != null : "null n"; - assert v != null : "null v"; - this.name = n; - this.version = v; - } // end constructor(String, String) - - /** - * Returns the attribute name. - * @return the attribute name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the attribute version. - * @return the attribute version - */ - public String getVersion() { - return this.version; - } // end method 'getVersion()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block c = Block.createBlock(0, - API.createUTF8(this.name), - API.createUTF8(this.version)); - final Block b = Block.createBlock(0, - HASH_MODULE, - Value.createFromBlock(c)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Module) { - final Module that = (Module) obj; - return this.name.equals(that.name) - && this.version.equals(that.version); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Module' - - /** - * This class implements a 'RuntimeInvisibleAnnotations' attribute. - */ - public static final class RuntimeInvisibleAnnotations extends Attribute { - - /** Attribute value. */ - private final List value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeInvisibleAnnotations(final List v) { - super(true, true, true, false); - assert v != null : "null v"; - this.value = new LinkedList(v); - } // end constructor(List) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List getValue() { - return new LinkedList(this.value); - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_INVISIBLE_ANNOTATIONS, - API.encodeList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeInvisibleAnnotations) { - final RuntimeInvisibleAnnotations that = (RuntimeInvisibleAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeInvisibleAnnotations' - - /** - * This class implements a 'RuntimeInvisibleAnnotations' attribute. - */ - public static final class RuntimeInvisibleTypeAnnotations extends Attribute { - - /** Attribute value. */ - private final List value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeInvisibleTypeAnnotations(final List v) { - super(true, true, true, false); - assert v != null : "null v"; - this.value = new LinkedList(v); - } // end constructor(List) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List getValue() { - return new LinkedList(this.value); - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, - API.encodeList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeInvisibleTypeAnnotations) { - final RuntimeInvisibleTypeAnnotations that = (RuntimeInvisibleTypeAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeInvisibleTypeAnnotations' - - /** - * This class implements a 'RuntimeInvisibleParameterAnnotations' attribute. - */ - public static final class RuntimeInvisibleParameterAnnotations extends Attribute { - - /** Attribute value. */ - private final List< List > value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeInvisibleParameterAnnotations(final List< List > v) { - super(false, true, false, false); - assert v != null : "null v"; - this.value = new LinkedList< List >(); - for (List a : v) { - this.value.add(new LinkedList(a)); - } // end for - } // end constructor(List< List >) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List< List > getValue() { - final List< List > res = new LinkedList< List >(); - for (List l : this.value) { - res.add(new LinkedList(l)); - } // end for - return res; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, - API.encodeListList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeInvisibleParameterAnnotations) { - final RuntimeInvisibleParameterAnnotations that = (RuntimeInvisibleParameterAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeInvisibleParameterAnnotations' - - /** - * This class implements a 'RuntimeVisibleAnnotations' attribute. - */ - public static final class RuntimeVisibleAnnotations extends Attribute { - - /** Attribute value. */ - private final List value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeVisibleAnnotations(final List v) { - super(true, true, true, false); - assert v != null : "null v"; - this.value = new LinkedList(v); - } // end constructor(List) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List getValue() { - return new LinkedList(this.value); - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_VISIBLE_ANNOTATIONS, - API.encodeList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeVisibleAnnotations) { - final RuntimeVisibleAnnotations that = (RuntimeVisibleAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeVisibleAnnotations' - - /** - * This class implements a 'RuntimeVisibleAnnotations' attribute. - */ - public static final class RuntimeVisibleTypeAnnotations extends Attribute { - - /** Attribute value. */ - private final List value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeVisibleTypeAnnotations(final List v) { - super(true, true, true, false); - assert v != null : "null v"; - this.value = new LinkedList(v); - } // end constructor(List) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List getValue() { - return new LinkedList(this.value); - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, - API.encodeList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeVisibleTypeAnnotations) { - final RuntimeVisibleTypeAnnotations that = (RuntimeVisibleTypeAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeVisibleTypeAnnotations' - - /** - * This class implements a 'RuntimeVisibleParameterAnnotations' attribute. - */ - public static final class RuntimeVisibleParameterAnnotations extends Attribute { - - /** Attribute value. */ - private final List< List > value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public RuntimeVisibleParameterAnnotations(final List< List > v) { - super(false, true, false, false); - assert v != null : "null v"; - this.value = new LinkedList< List >(); - for (List a : v) { - this.value.add(new LinkedList(a)); - } // end for - } // end constructor(List< List >) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public List< List > getValue() { - final List< List > res = new LinkedList< List >(); - for (List l : this.value) { - res.add(new LinkedList(l)); - } // end for - return res; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, - API.encodeListList(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof RuntimeVisibleParameterAnnotations) { - final RuntimeVisibleParameterAnnotations that = (RuntimeVisibleParameterAnnotations) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RuntimeVisibleParameterAnnotations' - - /** - * This class implements a 'Signature' attribute. - */ - public static final class Signature extends Attribute { - - /** Hash value for 'Class' attribute. */ - private static final Value HASH_CLASS = - Hash.hashVariant("Class"); - - /** Hash value for 'Method' attribute. */ - private static final Value HASH_METHOD = - Hash.hashVariant("Method"); - - /** Hash value for 'Field' attribute. */ - private static final Value HASH_FIELD = - Hash.hashVariant("Field"); - - /** Kinds of signatures. */ - public static enum Kind { CLASS, METHOD, FIELD }; - - /** Attribute kind. */ - private final Kind kind; - - /** Attribute value. */ - private final String value; - - /** - * Constructs an attribute. - * @param k kind of signature - should not be null - * @param v attribute value - should not be null - */ - public Signature(final Kind k, final String v) { - super(k.equals(Kind.FIELD), k.equals(Kind.METHOD), k.equals(Kind.CLASS), false); - assert k != null : "null k"; - assert v != null : "null v"; - this.kind = k; - this.value = v; - } // end constructor(String) - - /** - * Returns the attribute kind. - * @return the attribute kind - */ - public Kind getKind() { - return this.kind; - } // end method 'getKind()' - - /** - * Returns the attribute value. - * @return the attribute value - */ - public String getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block v; - switch (this.kind) { - case CLASS: - v = Block.createBlock(0, - HASH_CLASS, - API.createClassSignature(this.value)); - break; - case METHOD: - v = Block.createBlock(0, - HASH_METHOD, - API.createMethodSignature(this.value)); - break; - case FIELD: - v = Block.createBlock(0, - HASH_FIELD, - API.createFieldSignature(this.value)); - break; - default: - // should not be reached - v = Block.createBlock(0, Value.ZERO, Value.ZERO); - break; - } // end switch - final Block b = Block.createBlock(0, - HASH_SIGNATURE, - Value.createFromBlock(v)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Signature) { - final Signature that = (Signature) obj; - return this.kind.equals(that.kind) - && this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Signature' - - /** - * This class implements a 'SourceDebugExtension' attribute. - */ - public static final class SourceDebugExtension extends Attribute { - - /** Attribute value. */ - private final String value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public SourceDebugExtension(final String v) { - super(false, false, true, false); - assert v != null : "null v"; - this.value = v; - } // end constructor(String) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public String getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_SOURCE_DEBUG_EXTENSION, - API.createUTF8(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof SourceDebugExtension) { - final SourceDebugExtension that = (SourceDebugExtension) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SourceDebugExtension' - - /** - * This class implements a 'SourceFile' attribute. - */ - public static final class SourceFile extends Attribute { - - /** Attribute value. */ - private final String value; - - /** - * Constructs an attribute. - * @param v attribute value - should not be null - */ - public SourceFile(final String v) { - super(false, false, true, false); - assert v != null : "null v"; - this.value = v; - } // end constructor(String) - - /** - * Returns the attribute value. - * @return the attribute value - */ - public String getValue() { - return this.value; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - HASH_SOURCE_FILE, - API.createUTF8(this.value)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof SourceFile) { - final SourceFile that = (SourceFile) obj; - return this.value.equals(that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SourceFile' - - /** - * This class implements a 'Synthetic' attribute. - */ - public static final class Synthetic extends Attribute { - - /** - * Constructs an attribute. - */ - public Synthetic() { - super(true, true, true, false); - } // end empty constructor - - /** - * {@inheritDoc} - */ - public Value toValue() { - return HASH_SYNTHETIC; - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Synthetic) { - return true; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Synthetic' - - /** - * This class implements a 'StackMapTable' attribute. - */ - public static final class StackMapTable extends Attribute { - - /** Embedded frames. */ - private final List frames; - - /** - * Constructs an attribute. - * @param f stack frames - should not be null - */ - public StackMapTable(final List f) { - super(false, false, false, true); - assert f != null : "null f"; - this.frames = new LinkedList(f); - } // end constructor(List) - - /** - * Returns the list of embedded frames. - * @return the list of embedded frames - */ - public List getFrames() { - return new LinkedList(this.frames); - } // end method 'getFrames()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block c = Block.createBlock(0, API.encodeList(this.frames)); - final Block b = Block.createBlock(0, - HASH_STACK_MAP_TABLE, - Value.createFromBlock(c)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof StackMapTable) { - final StackMapTable that = (StackMapTable) obj; - return this.frames.equals(that.frames); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'StackMapTable' - - /** - * This class implements an 'Unknown' attribute. - */ - public static final class Unknown extends Attribute { - - /** Attribute name. */ - private final String name; - - /** Attribute value. */ - private final byte[] value; - - /** - * Constructs an attribute. - * @param n attribute name - should not be null - * @param v attribute value - should not be null - */ - public Unknown(final String n, final byte[] v) { - super(true, true, true, true); - assert n != null : "null n"; - assert v != null : "null v"; - this.name = n; - final int len = v.length; - this.value = new byte[len]; - System.arraycopy(v, 0, this.value, 0, len); - } // end constructor(String, byte[]) - - /** - * Returns the attribute name. - * @return the attribute name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the attribute value. - * @return the attribute value - */ - public byte[] getValue() { - final int len = this.value.length; - final byte[] res = new byte[len]; - System.arraycopy(this.value, 0, res, 0, len); - return res; - } // end method 'getValue()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block c = Block.createBlock(0, - API.createUTF8(this.name), - Value.createFromBlock(Block.createString(this.value))); - final Block b = Block.createBlock(0, - HASH_UNKNOWN, - Value.createFromBlock(c)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public final boolean equals(final Object obj) { - if (obj instanceof Unknown) { - final Unknown that = (Unknown) obj; - return this.name.equals(that.name) - && Arrays.equals(this.value, that.value); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Unknown' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Attribute fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final int hash = b.get(0).asLong(); - if (hash == HASH_ANNOTATION_DEFAULT.asLong()) { - return new AnnotationDefault(Annotation.elementFromValue(b.get(1))); - } else if (hash == HASH_CODE.asLong()) { - return new Code(CodeValue.fromValue(b.get(1))); - } else if (hash == HASH_CONSTANT_VALUE.asLong()) { - return new ConstantValue(ConstantVal.fromValue(b.get(1))); - } else if (hash == HASH_DEPRECATED.asLong()) { - return new Deprecated(); - } else if (hash == HASH_ENCLOSING_METHOD.asLong()) { - final Block bb = b.get(1).asBlock(); - if (bb.get(1) == Value.ZERO) { - return new EnclosingMethod(API.stringOfClassName(bb.get(0))); - } else { - final Block bbb = bb.get(1).asBlock(); - final Block desc = bbb.get(1).asBlock(); - final List params = new LinkedList(); - for (Value p : API.decodeList(desc.get(0))) { - params.add(Descriptor.fromValue(v)); - } // end for - return new EnclosingMethod(API.stringOfClassName(bb.get(0)), - API.stringOfMethodName(bbb.get(0)), - Descriptor.fromValue(desc.get(1)), - params); - } // end if/else - } else if (hash == HASH_EXCEPTIONS.asLong()) { - final List exns = new LinkedList(); - for (Value e : API.decodeList(b.get(1))) { - exns.add(API.stringOfClassName(e)); - } // end for - return new Exceptions(exns); - } else if (hash == HASH_INNER_CLASSES.asLong()) { - final List inners = new LinkedList(); - final List outers = new LinkedList(); - final List names = new LinkedList(); - final List< List > flags = new LinkedList< List >(); - for (Value i : API.decodeList(b.get(1))) { - final Block ii = i.asBlock(); - if (ii.get(0) == Value.ZERO) { - inners.add(null); - } else { - inners.add(API.stringOfClassName(ii.get(0).asBlock().get(0))); - } // end if/else - if (ii.get(1) == Value.ZERO) { - outers.add(null); - } else { - outers.add(API.stringOfClassName(ii.get(1).asBlock().get(0))); - } // end if/else - if (ii.get(2) == Value.ZERO) { - outers.add(null); - } else { - outers.add(API.stringOfUTF8(ii.get(2).asBlock().get(0))); - } // end if/else - final List l = new LinkedList(); - for (Value f : API.decodeList(ii.get(3))) { - l.add(AccessFlag.fromValue(f)); - } // end for - flags.add(l); - } // end for - return new InnerClasses(inners, outers, names, flags); - } else if (hash == HASH_LINE_NUMBER_TABLE.asLong()) { - final List offsets = new LinkedList(); - final List lines = new LinkedList(); - for (Value c : API.decodeList(b.get(1))) { - final Block cb = c.asBlock(); - offsets.add(cb.get(0).asLong()); - lines.add(cb.get(1).asLong()); - } // end for - return new LineNumberTable(offsets, lines); - } else if (hash == HASH_LOCAL_VARIABLE_TABLE.asLong()) { - final List starts = new LinkedList(); - final List ends = new LinkedList(); - final List names = new LinkedList(); - final List descriptors = new LinkedList(); - final List indexes = new LinkedList(); - for (Value t : API.decodeList(b.get(1))) { - final Block bb = t.asBlock(); - starts.add(bb.get(0).asLong()); - ends.add(bb.get(1).asLong()); - names.add(API.stringOfUTF8(bb.get(2))); - descriptors.add(Descriptor.fromValue(bb.get(3))); - indexes.add(bb.get(4).asLong()); - } // end for - return new LocalVariableTable(starts, ends, names, descriptors, indexes); - } else if (hash == HASH_LOCAL_VARIABLE_TYPE_TABLE.asLong()) { - final List starts = new LinkedList(); - final List ends = new LinkedList(); - final List names = new LinkedList(); - final List signatures = new LinkedList(); - final List indexes = new LinkedList(); - for (Value t : API.decodeList(b.get(1))) { - final Block bb = t.asBlock(); - starts.add(bb.get(0).asLong()); - ends.add(bb.get(1).asLong()); - names.add(API.stringOfUTF8(bb.get(2))); - signatures.add(API.stringOfFieldSignature(bb.get(3))); - indexes.add(bb.get(4).asLong()); - } // end for - return new LocalVariableTypeTable(starts, ends, names, signatures, indexes); - } else if (hash == HASH_MODULE.asLong()) { - return new Module(API.stringOfUTF8(b.get(1).asBlock().get(0)), - API.stringOfUTF8(b.get(1).asBlock().get(1))); - } else if (hash == HASH_RUNTIME_INVISIBLE_ANNOTATIONS.asLong()) { - final List annots = new LinkedList(); - for (Value a : API.decodeList(b.get(1))) { - annots.add(Annotation.fromValue(a)); - } // end for - return new RuntimeInvisibleAnnotations(annots); - } else if (hash == HASH_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.asLong()) { - final List annots = new LinkedList(); - for (Value a : API.decodeList(b.get(1))) { - annots.add(ExtendedAnnotation.fromValue(a)); - } // end for - return new RuntimeInvisibleTypeAnnotations(annots); - } else if (hash == HASH_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS.asLong()) { - final List< List > annotLists = new LinkedList< List >(); - for (Value al : API.decodeList(b.get(1))) { - final List l = new LinkedList(); - for (Value a : API.decodeList(al)) { - l.add(Annotation.fromValue(a)); - } // end for - annotLists.add(l); - } // end for - return new RuntimeInvisibleParameterAnnotations(annotLists); - } else if (hash == HASH_RUNTIME_VISIBLE_ANNOTATIONS.asLong()) { - final List annots = new LinkedList(); - for (Value a : API.decodeList(b.get(1))) { - annots.add(Annotation.fromValue(a)); - } // end for - return new RuntimeVisibleAnnotations(annots); - } else if (hash == HASH_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.asLong()) { - final List annots = new LinkedList(); - for (Value a : API.decodeList(b.get(1))) { - annots.add(ExtendedAnnotation.fromValue(a)); - } // end for - return new RuntimeVisibleTypeAnnotations(annots); - } else if (hash == HASH_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS.asLong()) { - final List< List > annotLists = new LinkedList< List >(); - for (Value al : API.decodeList(b.get(1))) { - final List l = new LinkedList(); - for (Value a : API.decodeList(al)) { - l.add(Annotation.fromValue(a)); - } // end for - annotLists.add(l); - } // end for - return new RuntimeVisibleParameterAnnotations(annotLists); - } else if (hash == HASH_SIGNATURE.asLong()) { - final Block s = b.get(1).asBlock(); - final int h = s.get(0).asLong(); - if (h == Signature.HASH_CLASS.asLong()) { - return new Signature(Signature.Kind.CLASS, - API.stringOfClassSignature(s.get(1))); - } else if (h == Signature.HASH_METHOD.asLong()) { - return new Signature(Signature.Kind.METHOD, - API.stringOfMethodSignature(s.get(1))); - } else if (h == Signature.HASH_FIELD.asLong()) { - return new Signature(Signature.Kind.FIELD, - API.stringOfFieldSignature(s.get(1))); - } else { - assert false : "invalid tag"; - return null; - } // end if/elsif/else - } else if (hash == HASH_SOURCE_DEBUG_EXTENSION.asLong()) { - return new SourceDebugExtension(API.stringOfUTF8(b.get(1))); - } else if (hash == HASH_SOURCE_FILE.asLong()) { - return new SourceFile(API.stringOfUTF8(b.get(1))); - } else if (hash == HASH_SYNTHETIC.asLong()) { - return new Synthetic(); - } else if (hash == HASH_STACK_MAP_TABLE.asLong()) { - final List frames = new LinkedList(); - for (Value f : API.decodeList(b.get(1))) { - frames.add(StackMapFrame.fromValue(f)); - } // end for - return new StackMapTable(frames); - } else if (hash == HASH_UNKNOWN.asLong()) { - return new Unknown(API.stringOfUTF8(b.get(1).asBlock().get(0)), - b.get(1).asBlock().get(1).asBlock().getBytes()); - } else { - assert false : "invalid tag"; - return null; - } // end if/elsif/else - } // end method 'fromValue(Value)' - -} // end class 'Attribute' rmfile ./api/src/fr/x9c/barista/api/Attribute.java hunk ./api/src/fr/x9c/barista/api/BaristaException.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -/** - * This class defines the exception to be thrown when a Barista call fails. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class BaristaException extends RuntimeException { - - /** Serialization UID. */ - static final long serialVersionUID = 8049594418997160639L; - - /** - * Constructs an exception from message. - * @param msg exception message - */ - public BaristaException(final String msg) { - super(msg); - } // end constructor (String) - - /** - * Constructs an exception from message and cause. - * @param msg exception message - * @param cause exception cause - */ - public BaristaException(final String msg, final Throwable cause) { - super(msg, cause); - } // end constructor (String, Throwable) - -} // end class 'BaristaException' rmfile ./api/src/fr/x9c/barista/api/BaristaException.java hunk ./api/src/fr/x9c/barista/api/ByteCode.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.InputStream; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Channel; -import fr.x9c.cadmium.kernel.Custom; -import fr.x9c.cadmium.kernel.Value; - -/** - * This class represents a Java class definition. - * - * @author Xavier Clerc - * @version 1.3 - * @since 1.0 - */ -public final class ByteCode { - - /** - * No instance of this class. - */ - private ByteCode() { - } // end empty constructor - - /** - * Generates bytecode for a class definition. - * @param v version usef for encoding - should not be null - * @param cd class definition to encode - should not be null - * @return the bytecode for the passed definition - * @throws BaristaException if an error occurs - */ - public static byte[] encode(final Version v, - final ClassDefinition cd) - throws BaristaException { - assert v != null : "null v"; - assert cd != null : "null cd"; - final Value res = - API.callback("fr.x9c.barista.api.ClassDefinition.encode", - v.toValue(), - cd.toValue()); - return res.asBlock().getBytes(); - } // end method 'encode(Version, ClassDefinition)' - - /** - * Generates bytecode for a class definition. - * @param cd class definition to encode - should not be null - * @return the bytecode for the passed definition - * @throws BaristaException if an error occurs - */ - public static byte[] encode(final ClassDefinition cd) - throws BaristaException { - assert cd != null : "null cd"; - return encode(Version.Java_1_6, cd); - } // end method 'encode(ClassDefinition)' - - /** - * Constructs a class definition from an input stream. - * @param in source for class bytecode - should not be null - * @return the class definition of the passed bytecode - * @throws BaristaException if an error occurs - */ - public static ClassDefinition decode(final InputStream in) - throws BaristaException { - assert in != null : "null in"; - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(in)); - final Value res = - API.callback("fr.x9c.barista.api.ClassDefinition.decode", - Value.createFromBlock(b)); - return ClassDefinition.fromValue(res); - } // end method 'decode(InputStream)' - -} // end class 'ByteCode' rmfile ./api/src/fr/x9c/barista/api/ByteCode.java hunk ./api/src/fr/x9c/barista/api/ClassDefinition.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.LinkedList; -import java.util.List; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java class definition. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class ClassDefinition implements ToValue { - - /** Class flags. */ - private final List flags; - - /** Class name. */ - private final String name; - - /** - * Class parent - * (should be nullonly for java.lang.Object). - */ - private final String parent; - - /** Class interfaces. */ - private final List interfaces; - - /** Class fields. */ - private final List fields; - - /** Class methods. */ - private final List methods; - - /** Class attributes. */ - private final List attributes; - - /** - * Constructs a class definition. - * @param af class flags - should not be null, - * should also be class flags - * @param n class name - should not be null - * @param p class parent (should be nullonly for java.lang.Object) - * @param i class interfaces - should not be null - * @param f class fields - should not be null - * @param m class methods - should not be null - * @param a class attributes - should not be null, - * should also be class attributes - * @throws BaristaException if one of the flags is not a valid flag - * @throws BaristaException if one of the attributes is not a valid attribute - */ - public ClassDefinition(final List af, - final String n, - final String p, - final List i, - final List f, - final List m, - final List a) - throws BaristaException { - assert af != null : "null af"; - assert n != null : "null n"; - assert i != null : "null i"; - assert f != null : "null f"; - assert m != null : "null m"; - assert a != null : "null a"; - if (!AccessFlag.areClassFlags(af)) { - throw new BaristaException("invalid flag"); - } // end if - if (!Attribute.areClassAttributes(a)) { - throw new BaristaException("invalid attribute"); - } // end if - this.flags = new LinkedList(af); - this.name = n; - this.parent = p; - this.interfaces = new LinkedList(i); - this.fields = new LinkedList(f); - this.methods = new LinkedList(m); - this.attributes = new LinkedList(a); - } // end constructor(List, String, String, ...) - - /** - * Returns the class flags. - * @return the class flags - */ - public List getFlags() { - return new LinkedList(this.flags); - } // end method 'getFlags()' - - /** - * Returns the class name. - * @return the class name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the class parent. - * @return the class parent - */ - public String getParent() { - return this.parent; - } // end method 'getParent()' - - /** - * Returns the class interfaces. - * @return the class interfaces - */ - public List getInterfaces() { - return new LinkedList(this.interfaces); - } // end method 'getInterfaces()' - - /** - * Returns the class fields. - * @return the class fields - */ - public List getFields() { - return new LinkedList(this.fields); - } // end method 'getFields()' - - /** - * Returns the class methods. - * @return the class methods - */ - public List getMethods() { - return new LinkedList(this.methods); - } // end method 'getMethods()' - - /** - * Returns the class attributes. - * @return the class attributes - */ - public List getAttributes() { - return new LinkedList(this.attributes); - } // end method 'getAttributes()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(7, 0); - b.set(0, API.encodeList(this.flags)); - b.set(1, API.createClassName(this.name)); - if (this.parent == null) { - b.set(2, Value.ZERO); - } else { - final Block p = Block.createBlock(0, API.createClassName(this.parent)); - b.set(2, Value.createFromBlock(p)); - } // end if/else - final List l = new LinkedList(); - for (String s : this.interfaces) { - l.add(API.createClassName(s)); - } // end for - b.set(3, API.encodeValueList(l)); - b.set(4, API.encodeList(this.fields)); - b.set(5, API.encodeList(this.methods)); - b.set(6, API.encodeList(this.attributes)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs a class definition from a value. - * @param v value to constructs class definition from - should not be null - * @return the class definition corresponding to the passed value - */ - public static ClassDefinition fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final List flags = new LinkedList(); - for (Value a : API.decodeList(b.get(0))) { - flags.add(AccessFlag.fromValue(a)); - } // end for - final List itf = new LinkedList(); - for (Value i : API.decodeList(b.get(3))) { - itf.add(API.stringOfClassName(i)); - } // end for - final List fld = new LinkedList(); - for (Value f : API.decodeList(b.get(4))) { - fld.add(Field.fromValue(f)); - } // end for - final List mth = new LinkedList(); - for (Value m : API.decodeList(b.get(5))) { - mth.add(Method.fromValue(m)); - } // end for - final List att = new LinkedList(); - for (Value a : API.decodeList(b.get(6))) { - att.add(Attribute.fromValue(a)); - } // end for - return new ClassDefinition(flags, - API.stringOfClassName(b.get(1)), - b.get(2) == Value.ZERO - ? null - : API.stringOfClassName(b.get(2).asBlock().get(0)), - itf, - fld, - mth, - att); - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - final String fl = AccessFlag.listToString(this.flags); - if (fl.length() > 0) { - sb.append(fl); - sb.append(" "); - } // end if - sb.append("class "); - sb.append(this.name); - if (this.parent != null) { - sb.append(" extends "); - sb.append(this.parent); - } // end for - if (this.interfaces.size() > 0) { - sb.append(" implements "); - boolean first = true; - for (String s : this.interfaces) { - if (first) { - first = false; - } else { - sb.append(", "); - } // end if/else - sb.append(s); - } // end for - } // end if - sb.append(" {\n"); - for (Field f : this.fields) { - sb.append(" "); - sb.append(f.toString()); - sb.append(";\n"); - } // end for - for (Method m : this.methods) { - sb.append(" "); - sb.append(m.toString()); - sb.append(";\n"); - } // end for - sb.append("}"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.flags.hashCode() - + this.name.hashCode() - + (this.parent != null ? this.parent.hashCode() : 0) - + this.interfaces.hashCode() - + this.fields.hashCode() - + this.methods.hashCode() - + this.attributes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassDefinition) { - final ClassDefinition that = (ClassDefinition) obj; - return this.flags.equals(that.flags) - && this.name.equals(that.name) - && API.nullOrEquals(this.parent, that.parent) - && this.interfaces.equals(that.interfaces) - && this.fields.equals(that.fields) - && this.methods.equals(that.methods) - && this.attributes.equals(that.attributes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - -} // end class 'ClassDefinition' rmfile ./api/src/fr/x9c/barista/api/ClassDefinition.java hunk ./api/src/fr/x9c/barista/api/ClassPath.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a classpath used to locate class files.
- * Such a classpath does not include the classpath of the running Java - * program. This means that an empty classpath will be unable to find any - * class, even the java.lang.Object class. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class ClassPath implements ToValue { - - /** Classpath elements. */ - private final List elements; - - /** - * Constructs an empty class path. - */ - public ClassPath() { - this.elements = new LinkedList(); - } // end empty constructor - - /** - * Constructs a classpath with one element. - * @param elem classpath element - should not be null - */ - public ClassPath(final String elem) { - assert elem != null : "null elem"; - this.elements = new LinkedList(); - this.elements.add(elem); - } // end constructor(String) - - /** - * Constructs a classpath from a list of elements. - * @param elems classpath elements - should not be null - */ - public ClassPath(final String... elems) { - assert elems != null : "null elems"; - this.elements = new LinkedList(); - for (String s : elems) { - this.elements.add(s); - } // end for - } // end constructor(String...) - - /** - * Constructs a classpath from a collection of elements. - * @param elems classpath elements - should not be null - */ - public ClassPath(final Collection elems) { - this.elements = new LinkedList(elems); - } // end constructor(Collection) - - /** - * Converts the classpath into a list of elements. - * @return the classpath as a list of elements - */ - public List toList() { - return new LinkedList(this.elements); - } // end method 'toList()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - boolean first = true; - for (String s : this.elements) { - if (first) { - first = false; - } else { - sb.append(":"); - } // end if/else - sb.append(s); - } // end for - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.elements.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassPath) { - final ClassPath that = (ClassPath) obj; - return this.elements.equals(that.elements); - } else { - return false; - } // end if/else - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Value.createFromBlock(Block.createString(toString())); - } // end method 'toValue()' - -} // end class 'ClassPath' rmfile ./api/src/fr/x9c/barista/api/ClassPath.java hunk ./api/src/fr/x9c/barista/api/Descriptor.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.primitives.stdlib.Hash; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a descriptor for a Java element. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public abstract class Descriptor implements ToValue { - - /** Hash for 'Array' variant. */ - private static final Value HASH_ARRAY = Hash.hashVariant("Array"); - - /** Hash for 'Class' variant. */ - private static final Value HASH_CLASS = Hash.hashVariant("Class"); - - /** Map from tag values to flags. */ - private static final Map MAP = - new HashMap(); - - /** - * Ensures that no descriptor could be defined outside this file. - */ - private Descriptor() { - } // end empty constructor - - /** - * This class represents simple descriptor elements. - */ - private static final class Simple extends Descriptor { - - /** Descriptor name. */ - private final String name; - - /** Print value. */ - private final String print; - - /** - * Constructs a descriptor from its tag name. - * @param n tag name - should not be null - * @param p value to print - should not be null - */ - private Simple(final String n, final String p) { - assert n != null : "null n"; - assert p != null : "null p"; - this.name = n; - this.print = p; - } // end constructor(String, String) - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Hash.hashVariant(this.name); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.print; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.name.hashCode(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Simple) { - final Simple that = (Simple) obj; - return this.name.equals(that.name); - } else { - return false; - } // end if/else - } // end method 'toString()' - - } // end inner-class 'Simple' - - /** Descriptor for array type. */ - public static final class Array extends Descriptor { - - /** Elements type. */ - private final Descriptor type; - - /** - * Constucts array descriptor from array element. - * @param t element type - should be neither null nor VOID - */ - public Array(final Descriptor t) { - assert t != null : "null t"; - assert t != VOID : "t should not be VOID"; - this.type = t; - } // end constructor(Descriptor) - - /** - * Returns the type of array elements. - * @return the type of array elements - */ - public Descriptor getType() { - return this.type; - } // end method 'getType()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block res = Block.createBlock(0, - HASH_ARRAY, - this.type.toValue()); - return Value.createFromBlock(res); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.type.toString() + "[]"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.type.hashCode(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Array) { - final Array that = (Array) obj; - return this.type.equals(that.type); - } else { - return false; - } // end if/else - } // end method 'toString()' - - } // end inner-class 'Array' - - /** Descriptor for boolean type. */ - public static final Descriptor BOOLEAN = new Simple("Boolean", "boolean"); - - /** Descriptor for byte type. */ - public static final Descriptor BYTE = new Simple("Byte", "byte"); - - /** Descriptor for char type. */ - public static final Descriptor CHAR = new Simple("Char", "char"); - - /** Descriptor for class type. */ - public static final class Class extends Descriptor { - - /** Class name. */ - private final String name; - - /** - * Constucts class name from string. - * @param n class name - should not be null - */ - public Class(final String n) { - assert n != null : "null n"; - this.name = n; - } // end constructor(String) - - /** - * Returns the class name. - * @return the class name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block res = Block.createBlock(0, - HASH_CLASS, - API.createClassName(this.name)); - return Value.createFromBlock(res); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.name; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.name.hashCode(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Class) { - final Class that = (Class) obj; - return this.name.equals(that.name); - } else { - return false; - } // end if/else - } // end method 'toString()' - - } // end inner-class 'Class' - - /** Descriptor for double type. */ - public static final Descriptor DOUBLE = new Simple("Double", "double"); - - /** Descriptor for float type. */ - public static final Descriptor FLOAT = new Simple("Float", "float"); - - /** Descriptor for int type. */ - public static final Descriptor INT = new Simple("Int", "int"); - - /** Descriptor for long type. */ - public static final Descriptor LONG = new Simple("Long", "int"); - - /** Descriptor for short type. */ - public static final Descriptor SHORT = new Simple("Short", "short"); - - /** Descriptor for void type. */ - public static final Descriptor VOID = new Simple("Void", "void"); - - /** - * Tests whether the descriptor can be a field descriptor. - * @return true if the descriptor can be a field descriptor, - * false otherwise - */ - public final boolean isFieldDescriptor() { - return this != VOID; - } // end method 'isFieldDescriptor()' - - /** - * Tests whether a list contains only field descriptors. - * @param l list to test - should not be null - * @return true if the list contains only field descriptors, - * false otherwise - */ - public static boolean areFieldDescriptors(final List l) { - assert l != null : "null l"; - for (Descriptor d : l) { - if (!d.isFieldDescriptor()) { - return false; - } // end if - } // end for - return true; - } // end method 'areFieldDescriptors(List)' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Descriptor fromValue(final Value v) { - assert v != null : "null v"; - if (v.isLong()) { - return MAP.get(v.asLong()); - } else { - final Block b = v.asBlock(); - final int tag = b.get(0).asLong(); - if (tag == HASH_ARRAY.asLong()) { - return new Array(fromValue(b.get(1))); - } else if (tag == HASH_CLASS.asLong()) { - return new Class(API.stringOfClassName(b.get(1))); - } else { - assert false : "invalid descriptor"; - return null; - } // end if/elsif/else - } // end if/else - } // end method 'fromValue(Value)' - - /** - * Converts a descriptor list into a string. - * @param l list to convert - should not be null - * @return the concatenation of all list elements - */ - public static String listToString(final List l) { - assert l != null : "null l"; - final StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Descriptor d : l) { - if (first) { - first = false; - } else { - sb.append(" "); - } // end if/else - sb.append(d.toString()); - } // end for - return sb.toString(); - } // end method 'listToString(List)' - - /** Map initilization. */ - static { - MAP.put(BOOLEAN.toValue().asLong(), BOOLEAN); - MAP.put(BYTE.toValue().asLong(), BYTE); - MAP.put(CHAR.toValue().asLong(), CHAR); - MAP.put(DOUBLE.toValue().asLong(), DOUBLE); - MAP.put(FLOAT.toValue().asLong(), FLOAT); - MAP.put(INT.toValue().asLong(), INT); - MAP.put(LONG.toValue().asLong(), LONG); - MAP.put(SHORT.toValue().asLong(), SHORT); - MAP.put(VOID.toValue().asLong(), VOID); - } // end static block - -} // end class 'Descriptor' rmfile ./api/src/fr/x9c/barista/api/Descriptor.java hunk ./api/src/fr/x9c/barista/api/Disassembler.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.OutputStream; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Channel; -import fr.x9c.cadmium.kernel.Custom; -import fr.x9c.cadmium.kernel.Value; - -/** - * This class provides methods for class textual disassembling. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class Disassembler { - - /** - * No instance of this class. - */ - private Disassembler() { - } // end empty constructor - - /** - * Calls the callback to disassemble a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while disassembling - */ - private static void callDisassemble(final String name, - final ClassPath cp, - final OutputStream out) - throws BaristaException { - assert name != null : "null name"; - assert cp != null : "null cp"; - assert out != null : "null out"; - final Value n = API.createUTF8(name); - final Value c = cp.toValue(); - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(out)); - final Value o = Value.createFromBlock(b); - API.callback("fr.x9c.barista.api.Disassembler.disassemble", n, c, o); - } // end method 'callDisassemble(String, ClassPath, OutputStream)' - - /** - * Disassembles a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while disassembling - */ - public static void disassemble(final String name, - final ClassPath cp, - final OutputStream out) - throws BaristaException { - callDisassemble(name, cp, out); - } // end method 'disassemble(String, ClassPath, OutputStream)' - - /** - * Disassembles a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while disassembling - */ - public static void disassemble(final String name, - final ClassPath cp, - final Appendable out) - throws BaristaException { - try { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - callDisassemble(name, cp, baos); - out.append(baos.toString("UTF-8")); - } catch (final UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } catch (final IOException ioe) { - throw new BaristaException("I/O error", ioe); - } // and try/catch - } // end method 'disassemble(String, ClassPath, Appendable)' - - /** - * Disassembles a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @return the disassembled class - * @throws BaristaException if an errors occurs while disassembling - */ - public static String disassemble(final String name, final ClassPath cp) - throws BaristaException { - try { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - callDisassemble(name, cp, baos); - return baos.toString("UTF-8"); - } catch (final UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } // and try/catch - } // end method 'disassemble(String, ClassPath)' - -} // end class 'Disassembler' rmfile ./api/src/fr/x9c/barista/api/Disassembler.java hunk ./api/src/fr/x9c/barista/api/ExtendedAnnotation.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.Helper; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java extended annotation. - * - * @author Xavier Clerc - * @version 2.0 - * @since 2.0 - */ -public final class ExtendedAnnotation implements ToValue { - - /** - * This class represents a local variable element, that is: pc, length, and index. - */ - public static final class LocalVariableElement implements ToValue { - - /** Start pc. */ - private final int pc; - - /** Length. */ - private final int length; - - /** Local index. */ - private final int index; - - /** - * Constructs an instance. - * @param p start pc - should be in 0..65535 - * @param l length - should be in 0..65535 - * @param i local index - should be in 0..65535 - */ - public LocalVariableElement(final int p, final int l, final int i) { - assert (p >= 0) && (p <= 65535) : "invalid start pc value"; - assert (l >= 0) && (l <= 65535) : "invalid length value"; - assert (i >= 0) && (i <= 65535) : "invalid local value"; - this.pc = p; - this.length = l; - this.index = i; - } // end constructor(int, int, int) - - /** - * Returns the start pc. - * @return the start pc - */ - public int getPc() { - return this.pc; - } // end method 'getPc()' - - /** - * Returns the length. - * @return the length - */ - public int getLength() { - return this.length; - } // end method 'getLength()' - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - Value.createFromLong(this.pc), - Value.createFromLong(this.length), - Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LocalVariableElement(" + this.pc + ", " + this.length + ", " + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.pc + this.length + this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LocalVariableElement) { - final LocalVariableElement that = (LocalVariableElement) obj; - return this.pc == that.pc - && this.length == that.length - && this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LocalVariableElement' - - /** - * Parent class of all target value embedded inside extended annotations. - */ - public static abstract class Target implements ToValue { - - /** - * Ensures that no element value could be defined outside this file. - */ - private Target() { - } // end empty constructor - - } // end inner-class 'Target' - - /** - * This class represents a simple target. - */ - private static class SimpleTarget extends Target { - - /** Identifier. */ - private final int id; - - /** - * Constructs an instance. - * @param id identifier - */ - public SimpleTarget(final int id) { - this.id = id; - } // end constructor(int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Value.createFromLong(this.id); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.getClass().getSimpleName(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.id; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof SimpleTarget) { - final SimpleTarget that = (SimpleTarget) obj; - return this.id == that.id; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SimpleTarget' - - - /** - * This class represents a 'method receiver' target. - */ - public static final class MethodReceiver extends SimpleTarget { - - /** - * Constructs an instance. - */ - public MethodReceiver() { - super(0); - } // end empty constructor - - } // end inner-class 'MethodReceiver' - - /** - * This class represents a 'method return type' target. - */ - public static final class MethodReturnType extends SimpleTarget { - - /** - * Constructs an instance. - */ - public MethodReturnType() { - super(1); - } // end empty constructor - - } // end inner-class 'MethodReturnType' - - /** - * This class represents a 'field' target. - */ - public static final class Field extends SimpleTarget { - - /** - * Constructs an instance. - */ - public Field() { - super(2); - } // end empty constructor - - } // end inner-class 'Field' - - /** - * This class represents a 'typecast' target. - */ - public static final class Typecast extends Target { - - /** Offset. */ - private final int offset; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - */ - public Typecast(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Typecast(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Typecast) { - final Typecast that = (Typecast) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Typecast' - - /** - * This class represents a 'typecast' target. - */ - public static final class TypecastLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param l location - should not be null - */ - public TypecastLoc(final int o, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert l != null : "invalid location"; - this.offset = o; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, Value.createFromLong(this.offset), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TypecastLoc(" + this.offset + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypecastLoc) { - final TypecastLoc that = (TypecastLoc) obj; - return this.offset == that.offset - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TypecastLoc' - - /** - * This class represents a 'instanceof' target. - */ - public static final class InstanceOf extends Target { - - /** Offset. */ - private final int offset; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - */ - public InstanceOf(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "InstanceOf(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof InstanceOf) { - final InstanceOf that = (InstanceOf) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'InstanceOf' - - /** - * This class represents a 'instanceof' target. - */ - public static final class InstanceOfLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param l location - should not be null - */ - public InstanceOfLoc(final int o, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert l != null : "invalid location"; - this.offset = o; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(3, Value.createFromLong(this.offset), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "InstanceOfLoc(" + this.offset + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof InstanceOfLoc) { - final InstanceOfLoc that = (InstanceOfLoc) obj; - return this.offset == that.offset - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'InstanceOfLoc' - - /** - * This class represents a 'new' target. - */ - public static final class New extends Target { - - /** Offset. */ - private final int offset; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - */ - public New(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(4, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "New(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof New) { - final New that = (New) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'New' - - /** - * This class represents a 'new' target. - */ - public static final class NewLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param l location - should not be null - */ - public NewLoc(final int o, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert l != null : "invalid location"; - this.offset = o; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(5, Value.createFromLong(this.offset), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "NewLoc(" + this.offset + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof NewLoc) { - final NewLoc that = (NewLoc) obj; - return this.offset == that.offset - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'NewLoc' - - /** - * This class represents a 'local variable' target. - */ - public static final class LocalVariable extends Target { - - /** Intervals. */ - private final List intervals; - - /** - * Constructs an instance. - * @param i intervals - should not be null - */ - public LocalVariable(final List i) { - assert i != null : "invalid intervals"; - this.intervals = i; - } // end constructor(List) - - /** - * Returns the intervals. - * @return the intervals - */ - public List getIntervals() { - return this.intervals; - } // end method 'getIntervals()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(6, valueOfIntervals(this.intervals)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LocalVariable(" + this.intervals + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.intervals.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LocalVariable) { - final LocalVariable that = (LocalVariable) obj; - return this.intervals.equals(that.intervals); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LocalVariable' - - /** - * This class represents a 'local variable' target. - */ - public static final class LocalVariableLoc extends Target { - - /** Intervals. */ - private final List intervals; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param i intervals - should not be null - * @param l location - should not be null - */ - public LocalVariableLoc(final List i, final List l) { - assert i != null : "invalid intervals"; - assert l != null : "invalid location"; - this.intervals = i; - this.location = l; - } // end constructor(List, List) - - /** - * Returns the intervals. - * @return the intervals - */ - public List getIntervals() { - return this.intervals; - } // end method 'getIntervals()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(7, valueOfIntervals(this.intervals), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LocalVariableLoc(" + this.intervals + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.intervals.hashCode() + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LocalVariableLoc) { - final LocalVariableLoc that = (LocalVariableLoc) obj; - return this.intervals.equals(that.intervals) - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LocalVariableLoc' - - /** - * This class represents a 'method return type' target. - */ - public static final class MethodReturnTypeLoc extends Target { - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param l location - should not be null - */ - public MethodReturnTypeLoc(final List l) { - assert l != null : "invalid location"; - this.location = l; - } // end constructor(List) - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(8, valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodReturnTypeLoc(" + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodReturnTypeLoc) { - final MethodReturnTypeLoc that = (MethodReturnTypeLoc) obj; - return this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodReturnTypeLoc' - - /** - * This class represents a 'method parameter' target. - */ - public static final class MethodParameter extends Target { - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param i index - should be in 0..127 - */ - public MethodParameter(final int i) { - assert (i >= 0) && (i <= 127) : "invalid index value"; - this.index = i; - } // end constructor(int) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(9, Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodParameter(" + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodParameter) { - final MethodParameter that = (MethodParameter) obj; - return this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodParameter' - - /** - * This class represents a 'method parameter' target. - */ - public static final class MethodParameterLoc extends Target { - - /** Index. */ - private final int index; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param i index - should be in 0..127 - * @param l location - should not be null - */ - public MethodParameterLoc(final int i, final List l) { - assert (i >= 0) && (i <= 127) : "invalid index value"; - assert l != null : "invalid location"; - this.index = i; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(10, Value.createFromLong(this.index), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodParameterLoc(" + this.index + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodParameterLoc) { - final MethodParameterLoc that = (MethodParameterLoc) obj; - return this.index == that.index - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodParameterLoc' - - /** - * This class represents a 'field' target. - */ - public static final class FieldLoc extends Target { - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param l location - should not be null - */ - public FieldLoc(final List l) { - assert l != null : "invalid location"; - this.location = l; - } // end constructor(List) - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(11, valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "FieldLoc(" + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof FieldLoc) { - final FieldLoc that = (FieldLoc) obj; - return this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'FieldLoc' - - /** - * This class represents a 'class type parameter bound' target. - */ - public static final class ClassTypeParameterBound extends Target { - - /** Parameter index. */ - private final int paramIndex; - - /** Bound index. */ - private final int boundIndex; - - /** - * Constructs an instance. - * @param p parameter index - should be in 0..127 - * @param b bound index - should be in 0..127 - */ - public ClassTypeParameterBound(final int p, final int b) { - assert (p >= 0) && (p <= 127) : "invalid parameter index value"; - assert (b >= 0) && (b <= 127) : "invalid bound index value"; - this.paramIndex = p; - this.boundIndex = b; - } // end constructor(int, int) - - /** - * Returns the parameter index. - * @return the parameter index - */ - public int getParameterIndex() { - return this.paramIndex; - } // end method getParameterIndex ()' - - /** - * Returns the bound index. - * @return the bound index - */ - public int getBoundIndex() { - return this.boundIndex; - } // end method getBoundIndex ()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(12, Value.createFromLong(this.paramIndex), Value.createFromLong(this.boundIndex)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassTypeParameterBound(" + this.paramIndex + ", "+ this.boundIndex + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.paramIndex + this.boundIndex; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassTypeParameterBound) { - final ClassTypeParameterBound that = (ClassTypeParameterBound) obj; - return this.paramIndex == that.paramIndex - && this.boundIndex == that.boundIndex; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassTypeParameterBound' - - /** - * This class represents a 'class type parameter bound' target. - */ - public static final class ClassTypeParameterBoundLoc extends Target { - - /** Parameter index. */ - private final int paramIndex; - - /** Bound index. */ - private final int boundIndex; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param p parameter index - should be in 0..127 - * @param b bound index - should be in 0..127 - * @param l location - should not be null - */ - public ClassTypeParameterBoundLoc(final int p, final int b, final List l) { - assert (p >= 0) && (p <= 127) : "invalid parameter index value"; - assert (b >= 0) && (b <= 127) : "invalid bound index value"; - assert l != null : "invalid location"; - this.paramIndex = p; - this.boundIndex = b; - this.location = l; - } // end constructor(int, int, List) - - /** - * Returns the parameter index. - * @return the parameter index - */ - public int getParameterIndex() { - return this.paramIndex; - } // end method getParameterIndex ()' - - /** - * Returns the bound index. - * @return the bound index - */ - public int getBoundIndex() { - return this.boundIndex; - } // end method getBoundIndex ()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(13, Value.createFromLong(this.paramIndex), Value.createFromLong(this.boundIndex), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassTypeParameterBoundLoc(" + this.paramIndex + ", " + this.boundIndex + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.paramIndex + this.boundIndex + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassTypeParameterBoundLoc) { - final ClassTypeParameterBoundLoc that = (ClassTypeParameterBoundLoc) obj; - return this.paramIndex == that.paramIndex - && this.boundIndex == that.boundIndex - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassTypeParameterBoundLoc' - - /** - * This class represents a 'method type parameter bound' target. - */ - public static final class MethodTypeParameterBound extends Target { - - /** Parameter index. */ - private final int paramIndex; - - /** Bound index. */ - private final int boundIndex; - - /** - * Constructs an instance. - * @param p parameter index - should be in 0..127 - * @param b bound index - should be in 0..127 - */ - public MethodTypeParameterBound(final int p, final int b) { - assert (p >= 0) && (p <= 127) : "invalid parameter index value"; - assert (b >= 0) && (b <= 127) : "invalid bound index value"; - this.paramIndex = p; - this.boundIndex = b; - } // end constructor(int, int) - - /** - * Returns the parameter index. - * @return the parameter index - */ - public int getParameterIndex() { - return this.paramIndex; - } // end method getParameterIndex ()' - - /** - * Returns the bound index. - * @return the bound index - */ - public int getBoundIndex() { - return this.boundIndex; - } // end method getBoundIndex ()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(14, Value.createFromLong(this.paramIndex), Value.createFromLong(this.boundIndex)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodTypeParameterBound(" + this.paramIndex + ", "+ this.boundIndex + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.paramIndex + this.boundIndex; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodTypeParameterBound) { - final MethodTypeParameterBound that = (MethodTypeParameterBound) obj; - return this.paramIndex == that.paramIndex - && this.boundIndex == that.boundIndex; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodTypeParameterBound' - - /** - * This class represents a 'method type parameter bound' target. - */ - public static final class MethodTypeParameterBoundLoc extends Target { - - /** Parameter index. */ - private final int paramIndex; - - /** Bound index. */ - private final int boundIndex; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param p parameter index - should be in 0..127 - * @param b bound index - should be in 0..127 - * @param l location - should not be null - */ - public MethodTypeParameterBoundLoc(final int p, final int b, final List l) { - assert (p >= 0) && (p <= 127) : "invalid parameter index value"; - assert (b >= 0) && (b <= 127) : "invalid bound index value"; - assert l != null : "invalid location"; - this.paramIndex = p; - this.boundIndex = b; - this.location = l; - } // end constructor(int, int, List) - - /** - * Returns the parameter index. - * @return the parameter index - */ - public int getParameterIndex() { - return this.paramIndex; - } // end method getParameterIndex ()' - - /** - * Returns the bound index. - * @return the bound index - */ - public int getBoundIndex() { - return this.boundIndex; - } // end method getBoundIndex ()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(15, Value.createFromLong(this.paramIndex), Value.createFromLong(this.boundIndex), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodTypeParameterBoundLoc(" + this.paramIndex + ", " + this.boundIndex + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.paramIndex + this.boundIndex + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodTypeParameterBoundLoc) { - final MethodTypeParameterBoundLoc that = (MethodTypeParameterBoundLoc) obj; - return this.paramIndex == that.paramIndex - && this.boundIndex == that.boundIndex - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodTypeParameterBoundLoc' - - /** - * This class represents a 'super type' target. - */ - public static final class SuperType extends Target { - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param i index - should be in 0..65535 - */ - public SuperType(final int i) { - assert (i >= 0) && (i <= 65535) : "invalid index value"; - this.index = i; - } // end constructor(int) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(16, Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "SuperType(" + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof SuperType) { - final SuperType that = (SuperType) obj; - return this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SuperType' - - /** - * This class represents a 'super type' target. - */ - public static final class SuperTypeLoc extends Target { - - /** Index. */ - private final int index; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param i index - should be in 0..65535 - * @param l location - should not be null - */ - public SuperTypeLoc(final int i, final List l) { - assert (i >= 0) && (i <= 65535) : "invalid index value"; - assert l != null : "invalid location"; - this.index = i; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(17, Value.createFromLong(this.index), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "SuperTypeLoc(" + this.index + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof SuperTypeLoc) { - final SuperTypeLoc that = (SuperTypeLoc) obj; - return this.index == that.index - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SuperTypeLoc' - - /** - * This class represents a 'thrown exception' target. - */ - public static final class ThrownException extends Target { - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param i index - should be in 0..65535 - */ - public ThrownException(final int i) { - assert (i >= 0) && (i <= 65535) : "invalid index value"; - this.index = i; - } // end constructor(int) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(18, Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ThrownException(" + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ThrownException) { - final ThrownException that = (ThrownException) obj; - return this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ThrownException' - - /** - * This class represents a 'type argument constructor call' target. - */ - public static final class TypeArgumentConstructorCall extends Target { - - /** Offset. */ - private final int offset; - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param i index - should be in 0..127 - */ - public TypeArgumentConstructorCall(final int o, final int i) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert (i >= 0) && (i <=127) : "invalid index value"; - this.offset = o; - this.index = i; - } // end constructor(int, int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(19, Value.createFromLong(this.offset), Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TypeArgumentConstructorCall(" + this.offset + ", " + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypeArgumentConstructorCall) { - final TypeArgumentConstructorCall that = (TypeArgumentConstructorCall) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TypeArgumentConstructorCall' - - /** - * This class represents a 'type argument constructor call' target. - */ - public static final class TypeArgumentConstructorCallLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Index. */ - private final int index; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param i index - should be in 0..127 - * @param l location - should not be null - */ - public TypeArgumentConstructorCallLoc(final int o, final int i, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert (i >= 0) && (i <=127) : "invalid index value"; - assert l != null : "invalid location"; - this.offset = o; - this.index = i; - this.location = l; - } // end constructor(int, int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(20, Value.createFromLong(this.offset), Value.createFromLong(this.index), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TypeArgumentConstructorCallLoc(" + this.offset + ", " + this.index + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.index + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypeArgumentConstructorCallLoc) { - final TypeArgumentConstructorCallLoc that = (TypeArgumentConstructorCallLoc) obj; - return this.offset == that.offset - && this.index == that.index - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TypeArgumentConstructorCallLoc' - - /** - * This class represents a 'type argument method call' target. - */ - public static final class TypeArgumentMethodCall extends Target { - - /** Offset. */ - private final int offset; - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param i index - should be in 0..127 - */ - public TypeArgumentMethodCall(final int o, final int i) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert (i >= 0) && (i <=127) : "invalid index value"; - this.offset = o; - this.index = i; - } // end constructor(int, int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(21, Value.createFromLong(this.offset), Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TypeArgumentMethodCall(" + this.offset + ", " + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypeArgumentMethodCall) { - final TypeArgumentMethodCall that = (TypeArgumentMethodCall) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TypeArgumentMethodCall' - - /** - * This class represents a 'type argument method call' target. - */ - public static final class TypeArgumentMethodCallLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Index. */ - private final int index; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param i index - should be in 0..127 - * @param l location - should not be null - */ - public TypeArgumentMethodCallLoc(final int o, final int i, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert (i >= 0) && (i <=127) : "invalid index value"; - assert l != null : "invalid location"; - this.offset = o; - this.index = i; - this.location = l; - } // end constructor(int, int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(22, Value.createFromLong(this.offset), Value.createFromLong(this.index), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TypeArgumentMethodCallLoc(" + this.offset + ", " + this.index + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.index + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypeArgumentMethodCallLoc) { - final TypeArgumentMethodCallLoc that = (TypeArgumentMethodCallLoc) obj; - return this.offset == that.offset - && this.index == that.index - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TypeArgumentMethodCallLoc' - - /** - * This class represents a 'wildcard bound' target. - */ - public static final class WildcardBound extends Target { - - /** Target. */ - private final Target target; - - /** - * Constructs an instance. - * @param t target - should not be null - */ - public WildcardBound(final Target t) { - assert t != null : "invalid target"; - this.target = t; - } // end constructor(Target) - - /** - * Returns the target. - * @return the target - */ - public Target getTarget() { - return this.target; - } // end method 'getTarget()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(23, this.target.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WildcardBound(" + this.target + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.target.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WildcardBound) { - final WildcardBound that = (WildcardBound) obj; - return this.target.equals(that.target); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class WildcardBound' - - /** - * This class represents a 'wildcard bound' target. - */ - public static final class WildcardBoundLoc extends Target { - - /** Target. */ - private final Target target; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param t target - should not be null - * @param l location - should not be null - */ - public WildcardBoundLoc(final Target t, final List l) { - assert t != null : "invalid target"; - assert l != null : "invalid location"; - this.target = t; - this.location = l; - } // end constructor(Target, List) - - /** - * Returns the target. - * @return the target - */ - public Target getTarget() { - return this.target; - } // end method 'getTarget()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(24, this.target.toValue(), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WildcardBoundLoc(" + this.target + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.target.hashCode() + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WildcardBoundLoc) { - final WildcardBoundLoc that = (WildcardBoundLoc) obj; - return this.target.equals(that.target) - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WildcardBoundLoc' - - /** - * This class represents a 'class literal' target. - */ - public static final class ClassLiteral extends Target { - - /** Offset. */ - private final int offset; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - */ - public ClassLiteral(final int o) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - this.offset = o; - } // end constructor(int) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(25, Value.createFromLong(this.offset)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassLiteral(" + this.offset + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassLiteral) { - final ClassLiteral that = (ClassLiteral) obj; - return this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassLiteral' - - /** - * This class represents a 'typecast't target. - */ - public static final class ClassLiteralLoc extends Target { - - /** Offset. */ - private final int offset; - - /** Location. */ - private final List location; - - /** - * Constructs an instance. - * @param o offset - should be in 0..65535 - * @param l location - should not be null - */ - public ClassLiteralLoc(final int o, final List l) { - assert (o >= 0) && (o <= 65535) : "invalid offset value"; - assert l != null : "invalid location"; - this.offset = o; - this.location = l; - } // end constructor(int, List) - - /** - * Returns the offset. - * @return the offset - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * Returns the location. - * @return the location - */ - public List getLocation() { - return this.location; - } // end method 'getLocation()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(26, Value.createFromLong(this.offset), valueOfLocation(this.location)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassLiteralLoc(" + this.offset + ", " + stringOfLocation(this.location) + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.offset + this.location.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassLiteralLoc) { - final ClassLiteralLoc that = (ClassLiteralLoc) obj; - return this.offset == that.offset - && this.location.equals(that.location); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassLiteralLoc' - - /** - * This class represents a 'method type parameter' target. - */ - public static final class MethodTypeParameter extends Target { - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param i index - should be in 0..127 - */ - public MethodTypeParameter(final int i) { - assert (i >= 0) && (i <= 127) : "invalid index value"; - this.index = i; - } // end constructor(int) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(27, Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MethodTypeParameter(" + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodTypeParameter) { - final MethodTypeParameter that = (MethodTypeParameter) obj; - return this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MethodTypeParameter' - - /** - * This class represents a class type parameter' target. - */ - public static final class ClassTypeParameter extends Target { - - /** Index. */ - private final int index; - - /** - * Constructs an instance. - * @param i index - should be in 0..127 - */ - public ClassTypeParameter(final int i) { - assert (i >= 0) && (i <= 127) : "invalid index value"; - this.index = i; - } // end constructor(int) - - /** - * Returns the index. - * @return the index - */ - public int getIndex() { - return this.index; - } // end method 'getIndex()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(28, Value.createFromLong(this.index)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ClassTypeParameter(" + this.index + ")"; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.index; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ClassTypeParameter) { - final ClassTypeParameter that = (ClassTypeParameter) obj; - return this.index == that.index; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ClassTypeParameter' - - /** Annotation name. */ - private final String name; - - /** Annotation element names. */ - private final List names; - - /** Annotation element values. */ - private final List values; - - /** Annotation target. */ - private final Target target; - - /** - * Constructs an extended annotation. - * @param nm annotation name - should not be null - * @param n element names - should not be null, - * should also have the same size as v - * @param v element values - should not be null, - * should also have the same size as n - * @param t annotation target - should not be null, - */ - public ExtendedAnnotation(final String nm, - final List n, - final List v, - final Target t) { - assert nm != null : "null nm"; - assert n != null : "null n"; - assert v != null : "null v"; - assert t != null : "null t"; - assert n.size() == v.size() : "n and v have different sizes"; - this.name = nm; - this.names = new LinkedList(n); - this.values = new LinkedList(v); - this.target = t; - } // end constructor(String, List, List, Target) - - /** - * Returns the name of the annotation. - * @return the name of the annotation - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the names of the annotations elements. - * @return the names of the annotations elements - */ - public List getNames() { - return new LinkedList(this.names); - } // end method 'getNames()' - - /** - * Returns the values of the annotations elements. - * @return the values of the annotations elements - */ - public List getValues() { - return new LinkedList(this.values); - } // end method 'getValues()' - - /** - * Returns the target of the annotation. - * @return the target of the annotation - */ - public Target getTarget() { - return this.target; - } // end method 'getTarget()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - Value list = Value.EMPTY_LIST; - final ListIterator itNames = this.names.listIterator(this.names.size()); - final ListIterator itValues = this.values.listIterator(this.values.size()); - while (itNames.hasPrevious() && itValues.hasPrevious()) { - final Block b = Block.createBlock(0, - API.createUTF8(itNames.previous()), - itValues.previous().toValue()); - final Block cons = Block.createBlock(Block.TAG_CONS, - Value.createFromBlock(b), - list); - list = Value.createFromBlock(cons); - } // end while - final Block res = Block.createBlock(0, - API.createClassName(this.name), - list, - this.target.toValue()); - return Value.createFromBlock(res); - } // end method 'toValue()' - - /** - * Constructs a location from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static List locationFromValue(final Value v) { - assert v != null : "null v"; - final List list = API.decodeList(v); - final List res = new LinkedList(); - for (Value e : list) { - res.add(new Short((short) e.asLong())); - } // end for - return res; - } // end method 'locationFromValue(Value)' - - /** - * Constructs a string from a location. - * @param l location to convert - should not be null - * @return the corresponding instance - */ - static Value valueOfLocation(final List l) { - assert l != null : "null l"; - Value res = Value.EMPTY_LIST; - final ListIterator it = l.listIterator(l.size()); - while (it.hasPrevious()) { - final Block cons = Block.createBlock(Block.TAG_CONS, - Value.createFromLong(it.previous()), - res); - res = Value.createFromBlock(cons); - } // end while - return res; - } // end method 'valueOfLocation(List)' - - /** - * Constructs a string from a location. - * @param l location to convert - should not be null - * @return the corresponding string - */ - static String stringOfLocation(final List l) { - assert l != null : "null l"; - final StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Short s : l) { - if (first) { - first = false; - } else { - sb.append(", "); - } // end if/else - sb.append(s.shortValue()); - } // end for - return sb.toString(); - } // end method 'stringOfLocation(List)' - - /** - * Constructs intervals from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static List intervalsFromValue(final Value v) { - assert v != null : "null v"; - final List list = API.decodeList(v); - final List res = new LinkedList(); - for (Value e : list) { - final Block b = e.asBlock(); - final LocalVariableElement lve = new LocalVariableElement(b.get(0).asLong(), b.get(1).asLong(), b.get(2).asLong()); - res.add(lve); - } // end for - return res; - } // end method 'intervalsFromValue(Value)' - - /** - * Constructs a string from intervals. - * @param l intervals to convert - should not be null - * @return the corresponding instance - */ - static Value valueOfIntervals(final List l) { - assert l != null : "null l"; - Value res = Value.EMPTY_LIST; - final ListIterator it = l.listIterator(l.size()); - while (it.hasPrevious()) { - final Block cons = Block.createBlock(Block.TAG_CONS, - it.previous().toValue(), - res); - res = Value.createFromBlock(cons); - } // end while - return res; - } // end method 'valueOfIntervals(List)' - - /** - * Constructs a target from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Target targetFromValue(final Value t) { - assert t != null : "null t"; - if (t.isLong()) { - switch (t.asLong()) { - case 0: return new MethodReceiver(); - case 1: return new MethodReturnType(); - case 2: return new Field(); - default: - assert false : "invalid tag"; - return null; - } // end switch - } else { - final Block b = t.asBlock(); - switch (b.getTag()) { - case 0: return new Typecast(b.get(0).asLong()); - case 1: return new TypecastLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 2: return new InstanceOf(b.get(0).asLong()); - case 3: return new InstanceOfLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 4: return new New(b.get(0).asLong()); - case 5: return new NewLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 6: return new LocalVariable(intervalsFromValue(b.get(0))); - case 7: return new LocalVariableLoc(intervalsFromValue(b.get(0)), locationFromValue(b.get(1))); - case 8: return new MethodReturnTypeLoc(locationFromValue(b.get(0))); - case 9: return new MethodParameter(b.get(0).asLong()); - case 10: return new MethodParameterLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 11: return new FieldLoc(locationFromValue(b.get(0))); - case 12: return new ClassTypeParameterBound(b.get(0).asLong(), b.get(1).asLong()); - case 13: return new ClassTypeParameterBoundLoc(b.get(0).asLong(), b.get(1).asLong(), locationFromValue(b.get(2))); - case 14: return new MethodTypeParameterBound(b.get(0).asLong(), b.get(1).asLong()); - case 15: return new MethodTypeParameterBoundLoc(b.get(0).asLong(), b.get(1).asLong(), locationFromValue(b.get(2))); - case 16: return new SuperType(b.get(0).asLong()); - case 17: return new SuperTypeLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 18: return new ThrownException(b.get(0).asLong()); - case 19: return new TypeArgumentConstructorCall(b.get(0).asLong(), b.get(1).asLong()); - case 20: return new TypeArgumentConstructorCallLoc(b.get(0).asLong(), b.get(1).asLong(), locationFromValue(b.get(2))); - case 21: return new TypeArgumentMethodCall(b.get(0).asLong(), b.get(1).asLong()); - case 22: return new TypeArgumentMethodCallLoc(b.get(0).asLong(), b.get(1).asLong(), locationFromValue(b.get(2))); - case 23: return new WildcardBound(targetFromValue(b.get(0))); - case 24: return new WildcardBoundLoc(targetFromValue(b.get(0)), locationFromValue(b.get(1))); - case 25: return new ClassLiteral(b.get(0).asLong()); - case 26: return new ClassLiteralLoc(b.get(0).asLong(), locationFromValue(b.get(1))); - case 27: return new MethodTypeParameter(b.get(0).asLong()); - case 28: return new ClassTypeParameter(b.get(0).asLong()); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end if/else - } // end method 'targetFromValue(Value)' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static ExtendedAnnotation fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final String name = API.stringOfClassName(b.get(0)); - final List list = API.decodeList(b.get(1)); - final List names = new LinkedList(); - final List values = new LinkedList(); - for (Value e : list) { - final Block bl = e.asBlock(); - names.add(API.stringOfUTF8(bl.get(0))); - values.add(Annotation.elementFromValue(bl.get(1))); - } // end for - final Target target = targetFromValue(b.get(2)); - return new ExtendedAnnotation(name, names, values, target); - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("@"); - sb.append(this.name); - sb.append("("); - final Iterator itNames = this.names.iterator(); - final Iterator itValues = this.values.iterator(); - boolean first = true; - while (itNames.hasNext() && itValues.hasNext()) { - if (first) { - first = false; - } else { - sb.append(", "); - } // end if/else - sb.append(itNames.next()); - sb.append("="); - sb.append(itValues.next().toString()); - } // end while - if (!first) { - sb.append(", "); - } // end if - sb.append(this.target.toString()); - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.name.hashCode() - + this.names.hashCode() - + this.values.hashCode() - + this.target.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ExtendedAnnotation) { - final ExtendedAnnotation that = (ExtendedAnnotation) obj; - return this.name.equals(that.name) - && this.names.equals(that.names) - && this.values.equals(that.values) - && this.target.equals(that.target); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - -} // end class 'ExtendedAnnotation' rmfile ./api/src/fr/x9c/barista/api/ExtendedAnnotation.java hunk ./api/src/fr/x9c/barista/api/Field.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.LinkedList; -import java.util.List; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java field. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class Field implements ToValue { - - /** Field flags. */ - private final List flags; - - /** Field name. */ - private final String name; - - /** Field descriptor. */ - private final Descriptor descriptor; - - /** Field attribute. */ - private final List attributes; - - /** - * Constructs a field. - * @param f field flags - should not be null, - * should also be field flags - * @param n field name - should not be null - * @param d field descriptor - should not be null, - * should also be a non-void descriptor - * @param a field attributes - should not be null, - * should also be field attributes - * @throws BaristaException if the descriptor is not a valid descriptor - * @throws BaristaException if one of the flags is not a valid flag - */ - public Field(final List f, - final String n, - final Descriptor d, - final List a) - throws BaristaException { - assert f != null : "null f"; - assert n != null : "null n"; - assert d != null : "null d"; - assert a != null : "null a"; - if (!AccessFlag.areFieldFlags(f)) { - throw new BaristaException("invalid flag"); - } // end if - if (!d.isFieldDescriptor()) { - throw new BaristaException("invalid descriptor"); - } // end if - if (!Attribute.areFieldAttributes(a)) { - throw new BaristaException("invalid attribute"); - } // end if - this.flags = new LinkedList(f); - this.name = n; - this.descriptor = d; - this.attributes = new LinkedList(a); - } // end constructor(List, String, Descriptor, List) - - /** - * Returns the field's flags. - * @return the field's flags - */ - public List getFlags() { - return new LinkedList(this.flags); - } // end method 'getFlags()' - - /** - * Returns the field's name. - * @return the field's name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the field's descriptor. - * @return the field's descriptor - */ - public Descriptor getDescriptor() { - return this.descriptor; - } // end method 'getDescriptor()' - - /** - * Returns the field's attributes. - * @return the field's attributes - */ - public List getAttributes() { - return new LinkedList(this.attributes); - } // end method 'getAttributes()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - API.encodeList(this.flags), - API.createFieldName(this.name), - this.descriptor.toValue(), - API.encodeList(this.attributes)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Field fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final List flags = new LinkedList(); - for (Value f : API.decodeList(b.get(0))) { - flags.add(AccessFlag.fromValue(f)); - } // end for - final String name = API.stringOfFieldName(b.get(1)); - final Descriptor desc = Descriptor.fromValue(b.get(2)); - final List attrs = new LinkedList(); - for (Value a : API.decodeList(b.get(3))) { - attrs.add(Attribute.fromValue(a)); - } // end for - return new Field(flags, name, desc, attrs); - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - final String f = AccessFlag.listToString(this.flags); - if (f.length() > 0) { - sb.append(f); - sb.append(" "); - } // end if - sb.append(this.descriptor.toString()); - sb.append(" "); - sb.append(this.name); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.flags.hashCode() - + this.name.hashCode() - + this.descriptor.hashCode() - + this.attributes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Field) { - final Field that = (Field) obj; - return this.flags.equals(that.flags) - && this.name.equals(that.name) - && this.descriptor.equals(that.descriptor) - && this.attributes.equals(that.attributes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - -} // end class 'Field' rmfile ./api/src/fr/x9c/barista/api/Field.java hunk ./api/src/fr/x9c/barista/api/Instruction.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.primitives.stdlib.Hash; -import fr.x9c.cadmium.support.Helper; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class implements the various Java instructions. - * - * @author Xavier Clerc - * @version 1.2 - * @since 1.0 - */ -public abstract class Instruction implements ToValue { - - /** - * Ensures that no instruction could be defined outside this file. - */ - private Instruction() { - } // end empty constructor - - /* This class represents a reference to a class or interface name. */ - public static final class TypeName implements ToValue { - - /** Class name. */ - private final String className; - - /** - * Constructs an instance from a class or interface name. - * @param n class or interface name - should not be null - */ - public TypeName(final String n) { - assert n != null : "null n"; - this.className = n; - } // end constructor (String) - - /** - * Returns the class or interface name. - * @return the class or interface name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.className; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.className.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TypeName) { - final TypeName that = (TypeName) obj; - return this.className.equals(that.className); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - return API.createClassName(this.className); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static TypeName fromValue(final Value v) { - return new TypeName(API.stringOfClassName(v)); - } // end method 'fromValue(Value)' - - } // end inner-class 'TypeName' - - /* This class represents a reference to a dynamic method. */ - public static final class DynamicMethodRef implements ToValue { - - /** Method name. */ - private final String methodName; - - /** Method return type. */ - private final Descriptor returnType; - - /** Method parameter types. */ - private final List parameterTypes; - - /** - * Constructs a method reference from name, and return and parameter - * types. - * @param n method name - should not be null - * @param r method return type - should not be null - * @param p method parameter types - should not be null - */ - public DynamicMethodRef(final String n, - final Descriptor r, - final List p) { - assert n != null : "null n"; - assert r != null : "null r"; - assert p != null : "null p"; - this.methodName = n; - this.returnType = r; - this.parameterTypes = new LinkedList(p); - } // end constructor (String, Descriptor, List) - - /** - * Returns the method name. - * @return the method name - */ - public String getMethodName() { - return this.methodName; - } // end method 'getMethodName()' - - /** - * Returns the method return type. - * @return the method return type - */ - public Descriptor getReturnType() { - return this.returnType; - } // end method 'getReturnType()' - - /** - * Returns the method parameter types. - * @return the method parameter types - */ - public List getParameterTypes() { - return new LinkedList(this.parameterTypes); - } // end method 'getParameterTypes()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(this.returnType.toString()); - sb.append(" "); - sb.append(this.methodName); - sb.append("("); - sb.append(Descriptor.listToString(this.parameterTypes)); - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.methodName.hashCode() - + this.returnType.hashCode() - + this.parameterTypes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof DynamicMethodRef) { - final DynamicMethodRef that = (DynamicMethodRef) obj; - return this.methodName.equals(that.methodName) - && this.returnType.equals(that.returnType) - && this.parameterTypes.equals(that.parameterTypes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b = Block.createBlock(0, - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static DynamicMethodRef fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final Descriptor r = Descriptor.fromValue(b.get(1).asBlock().get(1)); - final List p = new LinkedList(); - for (Value d : API.decodeList(b.get(1).asBlock().get(0))) { - p.add(Descriptor.fromValue(d)); - } // end for - return new DynamicMethodRef(API.stringOfMethodName(b.get(0)), r, p); - } // end method 'fromValue(Value)' - - } // end inner-class 'DynamicMethodRef' - - /* This class represents a reference to a method. */ - public static final class MethodRef implements ToValue { - - /** Class name. */ - private final String className; - - /** Method name. */ - private final String methodName; - - /** Method return type. */ - private final Descriptor returnType; - - /** Method parameter types. */ - private final List parameterTypes; - - /** - * Constructs a method reference from class and method names, - * and return and parameter types. - * @param c class name - should not be null - * @param n method name - should not be null - * @param r method return type - should not be null - * @param p method parameter types - should not be null - */ - public MethodRef(final String c, - final String n, - final Descriptor r, - final List p) { - assert c != null : "null c"; - assert n != null : "null n"; - assert r != null : "null r"; - assert p != null : "null p"; - this.className = c; - this.methodName = n; - this.returnType = r; - this.parameterTypes = new LinkedList(p); - } // end constructor (String, String, Descriptor, List) - - /** - * Returns the class name. - * @return the class name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * Returns the method name. - * @return the method name - */ - public String getMethodName() { - return this.methodName; - } // end method 'getMethodName()' - - /** - * Returns the method return type. - * @return the method return type - */ - public Descriptor getReturnType() { - return this.returnType; - } // end method 'getReturnType()' - - /** - * Returns the method parameter types. - * @return the method parameter types - */ - public List getParameterTypes() { - return new LinkedList(this.parameterTypes); - } // end method 'getParameterTypes()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(this.returnType.toString()); - sb.append(" "); - sb.append(this.className); - sb.append("."); - sb.append(this.methodName); - sb.append("("); - sb.append(Descriptor.listToString(this.parameterTypes)); - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.className.hashCode() - + this.methodName.hashCode() - + this.returnType.hashCode() - + this.parameterTypes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MethodRef) { - final MethodRef that = (MethodRef) obj; - return this.className.equals(that.className) - && this.methodName.equals(that.methodName) - && this.returnType.equals(that.returnType) - && this.parameterTypes.equals(that.parameterTypes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b = Block.createBlock(0, - API.createClassName(this.className), - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Same as {@link #toValue()}, but building a tagged value. - * @return the instance, as a tagged value - */ - public Value toTaggedValue() { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b = Block.createBlock(0, - wrap("Class_or_interface", API.createClassName(this.className)), - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - return Value.createFromBlock(b); - } // end method 'toTaggedValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static MethodRef fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final Descriptor r = Descriptor.fromValue(b.get(2).asBlock().get(1)); - final List p = new LinkedList(); - for (Value d : API.decodeList(b.get(2).asBlock().get(0))) { - p.add(Descriptor.fromValue(d)); - } // end for - return new MethodRef(API.stringOfClassName(b.get(0)), - API.stringOfMethodName(b.get(1)), - r, - p); - } // end method 'fromValue(Value)' - - /** - * Constructs an instance from a (tagged) value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static MethodRef fromTaggedValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final Descriptor r = Descriptor.fromValue(b.get(2).asBlock().get(1)); - final List p = new LinkedList(); - for (Value d : API.decodeList(b.get(2).asBlock().get(0))) { - p.add(Descriptor.fromValue(d)); - } // end for - return new MethodRef(API.stringOfClassName(b.get(0).asBlock().get(1)), - API.stringOfMethodName(b.get(1)), - r, - p); - } // end method 'fromTaggedValue(Value)' - - } // end inner-class 'MethodRef' - - /* This class represents a reference to an array method. */ - public static final class ArrayMethodRef implements ToValue { - - /** Array type. */ - private final Descriptor.Array arrayType; - - /** Method name. */ - private final String methodName; - - /** Method return type. */ - private final Descriptor returnType; - - /** Method parameter types. */ - private final List parameterTypes; - - /** - * Constructs a method reference from class and method names, - * and return and parameter types. - * @param a array type - should not be null - * @param n method name - should not be null - * @param r method return type - should not be null - * @param p method parameter types - should not be null - */ - public ArrayMethodRef(final Descriptor.Array a, - final String n, - final Descriptor r, - final List p) { - assert a != null : "null a"; - assert n != null : "null n"; - assert r != null : "null r"; - assert p != null : "null p"; - this.arrayType = a; - this.methodName = n; - this.returnType = r; - this.parameterTypes = new LinkedList(p); - } // end constructor (Descriptor.Array, String, Descriptor, List) - - /** - * Returns the array type. - * @return the array type - */ - public Descriptor.Array getArrayType() { - return this.arrayType; - } // end method getArrayType()' - - /** - * Returns the method name. - * @return the method name - */ - public String getMethodName() { - return this.methodName; - } // end method 'getMethodName()' - - /** - * Returns the method return type. - * @return the method return type - */ - public Descriptor getReturnType() { - return this.returnType; - } // end method 'getReturnType()' - - /** - * Returns the method parameter types. - * @return the method parameter types - */ - public List getParameterTypes() { - return new LinkedList(this.parameterTypes); - } // end method 'getParameterTypes()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(this.returnType.toString()); - sb.append(" "); - sb.append(this.arrayType); - sb.append("."); - sb.append(this.methodName); - sb.append("("); - sb.append(Descriptor.listToString(this.parameterTypes)); - sb.append(")"); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.arrayType.hashCode() - + this.methodName.hashCode() - + this.returnType.hashCode() - + this.parameterTypes.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ArrayMethodRef) { - final ArrayMethodRef that = (ArrayMethodRef) obj; - return this.arrayType.equals(that.arrayType) - && this.methodName.equals(that.methodName) - && this.returnType.equals(that.returnType) - && this.parameterTypes.equals(that.parameterTypes); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b = Block.createBlock(0, - this.arrayType.toValue(), - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Same as {@link #toValue()}, but building a tagged value. - * @return the instance, as a tagged value - */ - public Value toTaggedValue() { - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b = Block.createBlock(0, - wrap("Array_type", this.arrayType.toValue()), - API.createMethodName(this.methodName), - Value.createFromBlock(desc)); - return Value.createFromBlock(b); - } // end method 'toTaggedValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static ArrayMethodRef fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final Descriptor r = Descriptor.fromValue(b.get(2).asBlock().get(1)); - final List p = new LinkedList(); - for (Value d : API.decodeList(b.get(2).asBlock().get(0))) { - p.add(Descriptor.fromValue(d)); - } // end for - return new ArrayMethodRef((Descriptor.Array) Descriptor.fromValue(b.get(0)), - API.stringOfMethodName(b.get(1)), - r, - p); - } // end method 'fromValue(Value)' - - /** - * Constructs an instance from a (tagged) value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static ArrayMethodRef fromTaggedValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - final Descriptor r = Descriptor.fromValue(b.get(2).asBlock().get(1)); - final List p = new LinkedList(); - for (Value d : API.decodeList(b.get(2).asBlock().get(0))) { - p.add(Descriptor.fromValue(d)); - } // end for - return new ArrayMethodRef((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1)), - API.stringOfMethodName(b.get(1)), - r, - p); - } // end method 'fromTaggedValue(Value)' - - } // end inner-class 'ArrayMethodRef' - - /* This class represents a reference to a field. */ - public static final class FieldRef implements ToValue { - - /** Class name. */ - private final String className; - - /** Field name. */ - private final String fieldName; - - /** Field type. */ - private final Descriptor fieldType; - - /** - * Constructs and instance from class name, and field name and descriptor. - * @param cn class name - should not be null - * @param fn field name - should not be null - * @param ft field type - should not be null - * @throws BaristaException if the descriptor is not a valid descriptor - */ - public FieldRef(final String cn, final String fn, final Descriptor ft) - throws BaristaException { - assert cn != null : "null cn"; - assert fn != null : "null fn"; - assert ft != null : "null ft"; - if (!ft.isFieldDescriptor()) { - throw new BaristaException("invalid descriptor"); - } // end if - this.className = cn; - this.fieldName = fn; - this.fieldType = ft; - } // end constructor (String, String, Descriptor) - - /** - * Returns the class name. - * @return the class name - */ - public String getClassName() { - return this.className; - } // end method 'getClassName()' - - /** - * Returns the field name. - * @return the field name - */ - public String getFieldName() { - return this.fieldName; - } // end method 'getFieldName()' - - /** - * Returns the field type. - * @return the field type - */ - public Descriptor getFieldType() { - return this.fieldType; - } // end method 'getFieldType()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(this.fieldType.toString()); - sb.append(" "); - sb.append(this.className); - sb.append("."); - sb.append(this.fieldName); - return sb.toString(); - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.className.hashCode() - + this.fieldName.hashCode() - + this.fieldType.hashCode(); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof FieldRef) { - final FieldRef that = (FieldRef) obj; - return this.className.equals(that.className) - && this.fieldName.equals(that.fieldName) - && this.fieldType.equals(that.fieldType); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(0, - API.createClassName(this.className), - API.createFieldName(this.fieldName), - this.fieldType.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static FieldRef fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - return new FieldRef(API.stringOfClassName(b.get(0)), - API.stringOfFieldName(b.get(1)), - Descriptor.fromValue(b.get(2))); - } // end method 'fromValue(Value)' - - } // end inner-class 'FieldRef' - - /** - * This class implements a match/offset pair. - */ - public static final class MatchOffsetPair implements ToValue { - - /** The match value. */ - private final int match; - - /** The offset value. */ - private final int offset; - - /** - * Constructs a match/offset pair. - * @param m match value - * @param o offset value - */ - public MatchOffsetPair(final int m, final int o) { - this.match = m; - this.offset = o; - } // end constructor (int, int) - - /** - * Returns the match value. - * @return the match value - */ - public int getMatch() { - return this.match; - } // end method 'getMatch()' - - /** - * Returns the offset value. - * @return the offset value - */ - public int getOffset() { - return this.offset; - } // end method 'getOffset()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.match + " => " + this.offset; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.match + this.offset; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MatchOffsetPair) { - final MatchOffsetPair that = (MatchOffsetPair) obj; - return this.match == that.match - && this.offset == that.offset; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Value m = Helper.createInt32(this.match); - final Value o = Helper.createInt32(this.offset); - return Value.createFromBlock(Block.createBlock(0, m, o)); - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static MatchOffsetPair fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - return new MatchOffsetPair(b.get(0).asBlock().asInt32(), - b.get(1).asBlock().asInt32()); - } // end method 'fromValue(Value)' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - private static List listFromValue(final Value v) { - assert v != null : "null v"; - final List l = API.decodeList(v); - final List res = new LinkedList(); - for (Value x : l) { - res.add(fromValue(x)); - } // end for - return res; - } // end method 'listFromValue(Value)' - - } // end inner-class 'MatchOffsetPair' - - /** - * Decodes a list of integers from a value. - * @param v value to decode - should not be null - * @return the corresponding list - */ - private static List readIntegerList(final Value v) { - assert v != null : "null v"; - final List res = new LinkedList(); - Value list = v; - while (list != Value.EMPTY_LIST) { - final Block b = list.asBlock(); - res.add(b.get(0).asBlock().asInt32()); - list = b.get(1); - } // end while - return res; - } // end method 'readIntegerList(Value)' - - /** - * Encodes a list of integers into a value. - * @param l list to encode - should not be null - * @return the passed list as a value - */ - private static Value encodeIntegerList(final List l) { - assert l != null : "null l"; - Value res = Value.EMPTY_LIST; - final ListIterator it = l.listIterator(l.size()); - while (it.hasPrevious()) { - final Block cons = Block.createBlock(Block.TAG_CONS, - Helper.createInt32(it.previous()), - res); - res = Value.createFromBlock(cons); - } // end while - return res; - } // end method 'encodeIntegerList(final List)' - - /** - * Wraps a value inside a variant. - * @param id variant identifier - should not be null - * @param v value to wrap - should not be null - * @return the wrapped value - */ - static Value wrap(final String id, final Value v) { - assert id != null : "null id"; - assert v != null : "null v"; - final Block b = Block.createBlock(0, Hash.hashVariant(id), v); - return Value.createFromBlock(b); - } // end method 'wrap(String, Value)' - - /** - * This class represents instructions with no parameter. - */ - private static final class Simple extends Instruction { - - /** Instruction name. */ - private final String name; - - /** Instruction code. */ - private final int code; - - /** - * Constructs an instruction from name and code. - * @param n instruction name - should not be null - * @param c instruction code - */ - private Simple(final String n, final int c) { - assert n != null : "null n"; - this.name = n; - this.code = c; - } // end constructor(String, int) - - /** - * {@inheritDoc} - */ - public Value toValue() { - return Value.createFromLong(this.code); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return this.name; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.code; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Simple) { - final Simple that = (Simple) obj; - return this.code == that.code; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'Simple' - - /** Defines the AALOAD instruction (no parameter): load reference from array. */ - public static final Instruction AALOAD = new Simple("AALOAD", 0); - - /** Defines the AASTORE instruction (no parameter): store into reference array. */ - public static final Instruction AASTORE = new Simple("AASTORE", 1); - - /** Defines the ACONST_NULL instruction (no parameter): push null. */ - public static final Instruction ACONST_NULL = new Simple("ACONST_NULL", 2); - - /** Defines the ALOAD_0 instruction (no parameter): load reference from local variable. */ - public static final Instruction ALOAD_0 = new Simple("ALOAD_0", 3); - - /** Defines the ALOAD_1 instruction (no parameter): load reference from local variable. */ - public static final Instruction ALOAD_1 = new Simple("ALOAD_1", 4); - - /** Defines the ALOAD_2 instruction (no parameter): load reference from local variable. */ - public static final Instruction ALOAD_2 = new Simple("ALOAD_2", 5); - - /** Defines the ALOAD_3 instruction (no parameter): load reference from local variable. */ - public static final Instruction ALOAD_3 = new Simple("ALOAD_3", 6); - - /** Defines the ARETURN instruction (no parameter): return reference from method. */ - public static final Instruction ARETURN = new Simple("ARETURN", 7); - - /** Defines the ARRAYLENGTH instruction (no parameter): get length of array. */ - public static final Instruction ARRAYLENGTH = new Simple("ARRAYLENGTH", 8); - - /** Defines the ASTORE_0 instruction (no parameter): store reference into local variable. */ - public static final Instruction ASTORE_0 = new Simple("ASTORE_0", 9); - - /** Defines the ASTORE_1 instruction (no parameter): store reference into local variable. */ - public static final Instruction ASTORE_1 = new Simple("ASTORE_1", 10); - - /** Defines the ASTORE_2 instruction (no parameter): store reference into local variable. */ - public static final Instruction ASTORE_2 = new Simple("ASTORE_2", 11); - - /** Defines the ASTORE_3 instruction (no parameter): store reference into local variable. */ - public static final Instruction ASTORE_3 = new Simple("ASTORE_3", 12); - - /** Defines the ATHROW instruction (no parameter): throw exception or error. */ - public static final Instruction ATHROW = new Simple("ATHROW", 13); - - /** Defines the BALOAD instruction (no parameter): load byte or boolean from array. */ - public static final Instruction BALOAD = new Simple("BALOAD", 14); - - /** Defines the BASTORE instruction (no parameter): store into byte or boolean array. */ - public static final Instruction BASTORE = new Simple("BASTORE", 15); - - /** Defines the CALOAD instruction (no parameter): load char from array. */ - public static final Instruction CALOAD = new Simple("CALOAD", 16); - - /** Defines the CASTORE instruction (no parameter): store into char array. */ - public static final Instruction CASTORE = new Simple("CASTORE", 17); - - /** Defines the D2F instruction (no parameter): convert double to float. */ - public static final Instruction D2F = new Simple("D2F", 18); - - /** Defines the D2I instruction (no parameter): convert double to int. */ - public static final Instruction D2I = new Simple("D2I", 19); - - /** Defines the D2L instruction (no parameter): convert double to long. */ - public static final Instruction D2L = new Simple("D2L", 20); - - /** Defines the DADD instruction (no parameter): add double. */ - public static final Instruction DADD = new Simple("DADD", 21); - - /** Defines the DALOAD instruction (no parameter): load double from array. */ - public static final Instruction DALOAD = new Simple("DALOAD", 22); - - /** Defines the DASTORE instruction (no parameter): store into double array. */ - public static final Instruction DASTORE = new Simple("DASTORE", 23); - - /** Defines the DCMPG instruction (no parameter): compare double. */ - public static final Instruction DCMPG = new Simple("DCMPG", 24); - - /** Defines the DCMPL instruction (no parameter): compare double. */ - public static final Instruction DCMPL = new Simple("DCMPL", 25); - - /** Defines the DCONST_0 instruction (no parameter): push double. */ - public static final Instruction DCONST_0 = new Simple("DCONST_0", 26); - - /** Defines the DCONST_1 instruction (no parameter): push double. */ - public static final Instruction DCONST_1 = new Simple("DCONST_1", 27); - - /** Defines the DDIV instruction (no parameter): divide double. */ - public static final Instruction DDIV = new Simple("DDIV", 28); - - /** Defines the DLOAD_0 instruction (no parameter): load double from local variable. */ - public static final Instruction DLOAD_0 = new Simple("DLOAD_0", 29); - - /** Defines the DLOAD_1 instruction (no parameter): load double from local variable. */ - public static final Instruction DLOAD_1 = new Simple("DLOAD_1", 30); - - /** Defines the DLOAD_2 instruction (no parameter): load double from local variable. */ - public static final Instruction DLOAD_2 = new Simple("DLOAD_2", 31); - - /** Defines the DLOAD_3 instruction (no parameter): load double from local variable. */ - public static final Instruction DLOAD_3 = new Simple("DLOAD_3", 32); - - /** Defines the DMUL instruction (no parameter): multiply double. */ - public static final Instruction DMUL = new Simple("DMUL", 33); - - /** Defines the DNEG instruction (no parameter): negate double. */ - public static final Instruction DNEG = new Simple("DNEG", 34); - - /** Defines the DREM instruction (no parameter): remainder double. */ - public static final Instruction DREM = new Simple("DREM", 35); - - /** Defines the DRETURN instruction (no parameter): return double from method. */ - public static final Instruction DRETURN = new Simple("DRETURN", 36); - - /** Defines the DSTORE_0 instruction (no parameter): store double into local variable. */ - public static final Instruction DSTORE_0 = new Simple("DSTORE_0", 37); - - /** Defines the DSTORE_1 instruction (no parameter): store double into local variable. */ - public static final Instruction DSTORE_1 = new Simple("DSTORE_1", 38); - - /** Defines the DSTORE_2 instruction (no parameter): store double into local variable. */ - public static final Instruction DSTORE_2 = new Simple("DSTORE_2", 39); - - /** Defines the DSTORE_3 instruction (no parameter): store double into local variable. */ - public static final Instruction DSTORE_3 = new Simple("DSTORE_3", 40); - - /** Defines the DSUB instruction (no parameter): subtract double. */ - public static final Instruction DSUB = new Simple("DSUB", 41); - - /** Defines the DUP instruction (no parameter): duplicate the top operand stack value. */ - public static final Instruction DUP = new Simple("DUP", 42); - - /** Defines the DUP2 instruction (no parameter): duplicate the top one or two operand stack values. */ - public static final Instruction DUP2 = new Simple("DUP2", 43); - - /** Defines the DUP2_X1 instruction (no parameter): duplicate the top one or two operand stack values and insert two or three values down. */ - public static final Instruction DUP2_X1 = new Simple("DUP2_X1", 44); - - /** Defines the DUP2_X2 instruction (no parameter): duplicate the top one or two operand stack values and insert two, three, or four values down. */ - public static final Instruction DUP2_X2 = new Simple("DUP2_X2", 45); - - /** Defines the DUP_X1 instruction (no parameter): duplicate the top operand stack value and insert two values down. */ - public static final Instruction DUP_X1 = new Simple("DUP_X1", 46); - - /** Defines the DUP_X2 instruction (no parameter): duplicate the top operand stack value and insert two or threee values down. */ - public static final Instruction DUP_X2 = new Simple("DUP_X2", 47); - - /** Defines the F2D instruction (no parameter): convert float to double. */ - public static final Instruction F2D = new Simple("F2D", 48); - - /** Defines the F2I instruction (no parameter): convert float to int. */ - public static final Instruction F2I = new Simple("F2I", 49); - - /** Defines the F2L instruction (no parameter): convert float to long. */ - public static final Instruction F2L = new Simple("F2L", 50); - - /** Defines the FADD instruction (no parameter): add float. */ - public static final Instruction FADD = new Simple("FADD", 51); - - /** Defines the FALOAD instruction (no parameter): load float from array. */ - public static final Instruction FALOAD = new Simple("FALOAD", 52); - - /** Defines the FASTORE instruction (no parameter): store into float array. */ - public static final Instruction FASTORE = new Simple("FASTORE", 53); - - /** Defines the FCMPG instruction (no parameter): compare float. */ - public static final Instruction FCMPG = new Simple("FCMPG", 54); - - /** Defines the FCMPL instruction (no parameter): compare float. */ - public static final Instruction FCMPL = new Simple("FCMPL", 55); - - /** Defines the FCONST_0 instruction (no parameter): push float. */ - public static final Instruction FCONST_0 = new Simple("FCONST_0", 56); - - /** Defines the FCONST_1 instruction (no parameter): push float. */ - public static final Instruction FCONST_1 = new Simple("FCONST_1", 57); - - /** Defines the FCONST_2 instruction (no parameter): push float. */ - public static final Instruction FCONST_2 = new Simple("FCONST_2", 58); - - /** Defines the FDIV instruction (no parameter): divide float. */ - public static final Instruction FDIV = new Simple("FDIV", 59); - - /** Defines the FLOAD_0 instruction (no parameter): load float from local variable. */ - public static final Instruction FLOAD_0 = new Simple("FLOAD_0", 60); - - /** Defines the FLOAD_1 instruction (no parameter): load float from local variable. */ - public static final Instruction FLOAD_1 = new Simple("FLOAD_1", 61); - - /** Defines the FLOAD_2 instruction (no parameter): load float from local variable. */ - public static final Instruction FLOAD_2 = new Simple("FLOAD_2", 62); - - /** Defines the FLOAD_3 instruction (no parameter): load float from local variable. */ - public static final Instruction FLOAD_3 = new Simple("FLOAD_3", 63); - - /** Defines the FMUL instruction (no parameter): multiply float. */ - public static final Instruction FMUL = new Simple("FMUL", 64); - - /** Defines the FNEG instruction (no parameter): negate float. */ - public static final Instruction FNEG = new Simple("FNEG", 65); - - /** Defines the FREM instruction (no parameter): remainder float. */ - public static final Instruction FREM = new Simple("FREM", 66); - - /** Defines the FRETURN instruction (no parameter): return float from method. */ - public static final Instruction FRETURN = new Simple("FRETURN", 67); - - /** Defines the FSTORE_0 instruction (no parameter): store float into local variable. */ - public static final Instruction FSTORE_0 = new Simple("FSTORE_0", 68); - - /** Defines the FSTORE_1 instruction (no parameter): store float into local variable. */ - public static final Instruction FSTORE_1 = new Simple("FSTORE_1", 69); - - /** Defines the FSTORE_2 instruction (no parameter): store float into local variable. */ - public static final Instruction FSTORE_2 = new Simple("FSTORE_2", 70); - - /** Defines the FSTORE_3 instruction (no parameter): store float into local variable. */ - public static final Instruction FSTORE_3 = new Simple("FSTORE_3", 71); - - /** Defines the FSUB instruction (no parameter): subtract float. */ - public static final Instruction FSUB = new Simple("FSUB", 72); - - /** Defines the I2B instruction (no parameter): convert int to byte. */ - public static final Instruction I2B = new Simple("I2B", 73); - - /** Defines the I2C instruction (no parameter): convert int to char. */ - public static final Instruction I2C = new Simple("I2C", 74); - - /** Defines the I2D instruction (no parameter): convert int to double. */ - public static final Instruction I2D = new Simple("I2D", 75); - - /** Defines the I2F instruction (no parameter): convert int to float. */ - public static final Instruction I2F = new Simple("I2F", 76); - - /** Defines the I2L instruction (no parameter): convert int to long. */ - public static final Instruction I2L = new Simple("I2L", 77); - - /** Defines the I2S instruction (no parameter): convert int to short. */ - public static final Instruction I2S = new Simple("I2S", 78); - - /** Defines the IADD instruction (no parameter): add int. */ - public static final Instruction IADD = new Simple("IADD", 79); - - /** Defines the IALOAD instruction (no parameter): load int from array. */ - public static final Instruction IALOAD = new Simple("IALOAD", 80); - - /** Defines the IAND instruction (no parameter): boolean AND int. */ - public static final Instruction IAND = new Simple("IAND", 81); - - /** Defines the IASTORE instruction (no parameter): store into int array. */ - public static final Instruction IASTORE = new Simple("IASTORE", 82); - - /** Defines the ICONST_0 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_0 = new Simple("ICONST_0", 83); - - /** Defines the ICONST_1 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_1 = new Simple("ICONST_1", 84); - - /** Defines the ICONST_2 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_2 = new Simple("ICONST_2", 85); - - /** Defines the ICONST_3 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_3 = new Simple("ICONST_3", 86); - - /** Defines the ICONST_4 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_4 = new Simple("ICONST_4", 87); - - /** Defines the ICONST_5 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_5 = new Simple("ICONST_5", 88); - - /** Defines the ICONST_M1 instruction (no parameter): push int constant. */ - public static final Instruction ICONST_M1 = new Simple("ICONST_M1", 89); - - /** Defines the IDIV instruction (no parameter): divide int. */ - public static final Instruction IDIV = new Simple("IDIV", 90); - - /** Defines the ILOAD_0 instruction (no parameter): load int from local variable. */ - public static final Instruction ILOAD_0 = new Simple("ILOAD_0", 91); - - /** Defines the ILOAD_1 instruction (no parameter): load int from local variable. */ - public static final Instruction ILOAD_1 = new Simple("ILOAD_1", 92); - - /** Defines the ILOAD_2 instruction (no parameter): load int from local variable. */ - public static final Instruction ILOAD_2 = new Simple("ILOAD_2", 93); - - /** Defines the ILOAD_3 instruction (no parameter): load int from local variable. */ - public static final Instruction ILOAD_3 = new Simple("ILOAD_3", 94); - - /** Defines the IMUL instruction (no parameter): multiply int. */ - public static final Instruction IMUL = new Simple("IMUL", 95); - - /** Defines the INEG instruction (no parameter): negate int. */ - public static final Instruction INEG = new Simple("INEG", 96); - - /** Defines the IOR instruction (no parameter): boolean OR int. */ - public static final Instruction IOR = new Simple("IOR", 97); - - /** Defines the IREM instruction (no parameter): remainder int. */ - public static final Instruction IREM = new Simple("IREM", 98); - - /** Defines the IRETURN instruction (no parameter): return int from method. */ - public static final Instruction IRETURN = new Simple("IRETURN", 99); - - /** Defines the ISHL instruction (no parameter): shift left int. */ - public static final Instruction ISHL = new Simple("ISHL", 100); - - /** Defines the ISHR instruction (no parameter): arithmetic shift right int. */ - public static final Instruction ISHR = new Simple("ISHR", 101); - - /** Defines the ISTORE_0 instruction (no parameter): store int into local variable. */ - public static final Instruction ISTORE_0 = new Simple("ISTORE_0", 102); - - /** Defines the ISTORE_1 instruction (no parameter): store int into local variable. */ - public static final Instruction ISTORE_1 = new Simple("ISTORE_1", 103); - - /** Defines the ISTORE_2 instruction (no parameter): store int into local variable. */ - public static final Instruction ISTORE_2 = new Simple("ISTORE_2", 104); - - /** Defines the ISTORE_3 instruction (no parameter): store int into local variable. */ - public static final Instruction ISTORE_3 = new Simple("ISTORE_3", 105); - - /** Defines the ISUB instruction (no parameter): subtract int. */ - public static final Instruction ISUB = new Simple("ISUB", 106); - - /** Defines the IUSHR instruction (no parameter): logical shift right int. */ - public static final Instruction IUSHR = new Simple("IUSHR", 107); - - /** Defines the IXOR instruction (no parameter): boolean XOR int. */ - public static final Instruction IXOR = new Simple("IXOR", 108); - - /** Defines the L2D instruction (no parameter): convert long to double. */ - public static final Instruction L2D = new Simple("L2D", 109); - - /** Defines the L2F instruction (no parameter): convert long to float. */ - public static final Instruction L2F = new Simple("L2F", 110); - - /** Defines the L2I instruction (no parameter): convert long to int. */ - public static final Instruction L2I = new Simple("L2I", 111); - - /** Defines the LADD instruction (no parameter): add long. */ - public static final Instruction LADD = new Simple("LADD", 112); - - /** Defines the LALOAD instruction (no parameter): load long from array. */ - public static final Instruction LALOAD = new Simple("LALOAD", 113); - - /** Defines the LAND instruction (no parameter): boolean AND long. */ - public static final Instruction LAND = new Simple("LAND", 114); - - /** Defines the LASTORE instruction (no parameter): store into long array. */ - public static final Instruction LASTORE = new Simple("LASTORE", 115); - - /** Defines the LCMP instruction (no parameter): compare long. */ - public static final Instruction LCMP = new Simple("LCMP", 116); - - /** Defines the LCONST_0 instruction (no parameter): push long constant. */ - public static final Instruction LCONST_0 = new Simple("LCONST_0", 117); - - /** Defines the LCONST_1 instruction (no parameter): push long constant. */ - public static final Instruction LCONST_1 = new Simple("LCONST_1", 118); - - /** Defines the LDIV instruction (no parameter): divide long. */ - public static final Instruction LDIV = new Simple("LDIV", 119); - - /** Defines the LLOAD_0 instruction (no parameter): load long from local variable. */ - public static final Instruction LLOAD_0 = new Simple("LLOAD_0", 120); - - /** Defines the LLOAD_1 instruction (no parameter): load long from local variable. */ - public static final Instruction LLOAD_1 = new Simple("LLOAD_1", 121); - - /** Defines the LLOAD_2 instruction (no parameter): load long from local variable. */ - public static final Instruction LLOAD_2 = new Simple("LLOAD_2", 122); - - /** Defines the LLOAD_3 instruction (no parameter): load long from local variable. */ - public static final Instruction LLOAD_3 = new Simple("LLOAD_3", 123); - - /** Defines the LMUL instruction (no parameter): multiply long. */ - public static final Instruction LMUL = new Simple("LMUL", 124); - - /** Defines the LNEG instruction (no parameter): negate long. */ - public static final Instruction LNEG = new Simple("LNEG", 125); - - /** Defines the LOR instruction (no parameter): boolean OR long. */ - public static final Instruction LOR = new Simple("LOR", 126); - - /** Defines the LREM instruction (no parameter): remainder long. */ - public static final Instruction LREM = new Simple("LREM", 127); - - /** Defines the LRETURN instruction (no parameter): return long from method. */ - public static final Instruction LRETURN = new Simple("LRETURN", 128); - - /** Defines the LSHL instruction (no parameter): shift left long. */ - public static final Instruction LSHL = new Simple("LSHL", 129); - - /** Defines the LSHR instruction (no parameter): arithmetic shift right long. */ - public static final Instruction LSHR = new Simple("LSHR", 130); - - /** Defines the LSTORE_0 instruction (no parameter): store long into local variable. */ - public static final Instruction LSTORE_0 = new Simple("LSTORE_0", 131); - - /** Defines the LSTORE_1 instruction (no parameter): store long into local variable. */ - public static final Instruction LSTORE_1 = new Simple("LSTORE_1", 132); - - /** Defines the LSTORE_2 instruction (no parameter): store long into local variable. */ - public static final Instruction LSTORE_2 = new Simple("LSTORE_2", 133); - - /** Defines the LSTORE_3 instruction (no parameter): store long into local variable. */ - public static final Instruction LSTORE_3 = new Simple("LSTORE_3", 134); - - /** Defines the LSUB instruction (no parameter): subtract long. */ - public static final Instruction LSUB = new Simple("LSUB", 135); - - /** Defines the LUSHR instruction (no parameter): logical shift right long. */ - public static final Instruction LUSHR = new Simple("LUSHR", 136); - - /** Defines the LXOR instruction (no parameter): boolean XOR long. */ - public static final Instruction LXOR = new Simple("LXOR", 137); - - /** Defines the MONITORENTER instruction (no parameter): enter monitor for object. */ - public static final Instruction MONITORENTER = new Simple("MONITORENTER", 138); - - /** Defines the MONITOREXIT instruction (no parameter): exit monitor for object. */ - public static final Instruction MONITOREXIT = new Simple("MONITOREXIT", 139); - - /** Defines the NOP instruction (no parameter): do nothing. */ - public static final Instruction NOP = new Simple("NOP", 140); - - /** Defines the POP instruction (no parameter): pop the top operand stack value. */ - public static final Instruction POP = new Simple("POP", 141); - - /** Defines the POP2 instruction (no parameter): pop the top one or two operand stack values. */ - public static final Instruction POP2 = new Simple("POP2", 142); - - /** Defines the RETURN instruction (no parameter): return void from method. */ - public static final Instruction RETURN = new Simple("RETURN", 143); - - /** Defines the SALOAD instruction (no parameter): load short from array. */ - public static final Instruction SALOAD = new Simple("SALOAD", 144); - - /** Defines the SASTORE instruction (no parameter): store into short array. */ - public static final Instruction SASTORE = new Simple("SASTORE", 145); - - /** Defines the SWAP instruction (no parameter): swap the top two operand stack values. */ - public static final Instruction SWAP = new Simple("SWAP", 146); - - /** Defines the ALOAD instruction: load reference from local variable. */ - public static final class ALOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the ALOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public ALOAD(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 0); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ALOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 0; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ALOAD) { - final ALOAD that = (ALOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ALOAD' - - /** Defines the ANEWARRAY instruction: create new array of references. */ - public static final class ANEWARRAY_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the ANEWARRAY instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public ANEWARRAY_TYPE(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 1); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ANEWARRAY_TYPE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 1; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ANEWARRAY_TYPE) { - final ANEWARRAY_TYPE that = (ANEWARRAY_TYPE) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ANEWARRAY_TYPE' - - /** Defines the ANEWARRAY instruction: create new array of references. */ - public static final class ANEWARRAY_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** - * Constructs an instance of the ANEWARRAY instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public ANEWARRAY_ARRAY(final Descriptor.Array p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor.Array) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 1); - b.set(0, wrap("Array_type", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ANEWARRAY_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 1; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ANEWARRAY_ARRAY) { - final ANEWARRAY_ARRAY that = (ANEWARRAY_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ANEWARRAY_ARRAY' - - /** Defines the ASTORE instruction: store reference into local variable. */ - public static final class ASTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the ASTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public ASTORE(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 2); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ASTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 2; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ASTORE) { - final ASTORE that = (ASTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ASTORE' - - /** Defines the BIPUSH instruction: push byte. */ - public static final class BIPUSH extends Instruction { - - /** Value of first instruction parameter. */ - private final byte p1; - - /** - * Constructs an instance of the BIPUSH instruction. - * @param p1 value of first instruction parameter - */ - public BIPUSH(final byte p1) { - this.p1 = p1; - } // end constructor (byte) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public byte getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 3); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "BIPUSH" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 3; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof BIPUSH) { - final BIPUSH that = (BIPUSH) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'BIPUSH' - - /** Defines the CHECKCAST instruction: check whether object is of given type. */ - public static final class CHECKCAST_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the CHECKCAST instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public CHECKCAST_TYPE(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 4); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "CHECKCAST_TYPE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 4; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof CHECKCAST_TYPE) { - final CHECKCAST_TYPE that = (CHECKCAST_TYPE) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'CHECKCAST_TYPE' - - /** Defines the CHECKCAST instruction: check whether object is of given type. */ - public static final class CHECKCAST_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** - * Constructs an instance of the CHECKCAST instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public CHECKCAST_ARRAY(final Descriptor.Array p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor.Array) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 4); - b.set(0, wrap("Array_type", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "CHECKCAST_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 4; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof CHECKCAST_ARRAY) { - final CHECKCAST_ARRAY that = (CHECKCAST_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'CHECKCAST_ARRAY' - - /** Defines the DLOAD instruction: load double from local variable. */ - public static final class DLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the DLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public DLOAD(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 5); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "DLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 5; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof DLOAD) { - final DLOAD that = (DLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'DLOAD' - - /** Defines the DSTORE instruction: store double into local variable. */ - public static final class DSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the DSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public DSTORE(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 6); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "DSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 6; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof DSTORE) { - final DSTORE that = (DSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'DSTORE' - - /** Defines the FLOAD instruction: load float from local variable. */ - public static final class FLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the FLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public FLOAD(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 7); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "FLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 7; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof FLOAD) { - final FLOAD that = (FLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'FLOAD' - - /** Defines the FSTORE instruction: store float into local variable. */ - public static final class FSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the FSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public FSTORE(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 8); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "FSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 8; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof FSTORE) { - final FSTORE that = (FSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'FSTORE' - - /** Defines the GETFIELD instruction: fetch field from object. */ - public static final class GETFIELD extends Instruction { - - /** Value of first instruction parameter. */ - private final FieldRef p1; - - /** - * Constructs an instance of the GETFIELD instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public GETFIELD(final FieldRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (FieldRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public FieldRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 9); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "GETFIELD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 9; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof GETFIELD) { - final GETFIELD that = (GETFIELD) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'GETFIELD' - - /** Defines the GETSTATIC instruction: get static field from class. */ - public static final class GETSTATIC extends Instruction { - - /** Value of first instruction parameter. */ - private final FieldRef p1; - - /** - * Constructs an instance of the GETSTATIC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public GETSTATIC(final FieldRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (FieldRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public FieldRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 10); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "GETSTATIC" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 10; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof GETSTATIC) { - final GETSTATIC that = (GETSTATIC) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'GETSTATIC' - - /** Defines the GOTO instruction: branch always. */ - public static final class GOTO extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the GOTO instruction. - * @param p1 value of first instruction parameter - */ - public GOTO(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 11); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "GOTO" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 11; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof GOTO) { - final GOTO that = (GOTO) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'GOTO' - - /** Defines the GOTO_W instruction: branch always. */ - public static final class GOTO_W extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the GOTO_W instruction. - * @param p1 value of first instruction parameter - */ - public GOTO_W(final int p1) { - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 12); - b.set(0, Helper.createInt32(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "GOTO_W" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 12; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof GOTO_W) { - final GOTO_W that = (GOTO_W) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'GOTO_W' - - /** Defines the IF_ACMPEQ instruction: branch if reference comparison succeeds. */ - public static final class IF_ACMPEQ extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ACMPEQ instruction. - * @param p1 value of first instruction parameter - */ - public IF_ACMPEQ(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 13); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ACMPEQ" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 13; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ACMPEQ) { - final IF_ACMPEQ that = (IF_ACMPEQ) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ACMPEQ' - - /** Defines the IF_ACMPNE instruction: branch if reference comparison succeeds. */ - public static final class IF_ACMPNE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ACMPNE instruction. - * @param p1 value of first instruction parameter - */ - public IF_ACMPNE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 14); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ACMPNE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 14; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ACMPNE) { - final IF_ACMPNE that = (IF_ACMPNE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ACMPNE' - - /** Defines the IF_ICMPEQ instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPEQ extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPEQ instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPEQ(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 15); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPEQ" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 15; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPEQ) { - final IF_ICMPEQ that = (IF_ICMPEQ) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPEQ' - - /** Defines the IF_ICMPGE instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPGE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPGE instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPGE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 16); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPGE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 16; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPGE) { - final IF_ICMPGE that = (IF_ICMPGE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPGE' - - /** Defines the IF_ICMPGT instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPGT extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPGT instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPGT(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 17); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPGT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 17; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPGT) { - final IF_ICMPGT that = (IF_ICMPGT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPGT' - - /** Defines the IF_ICMPLE instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPLE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPLE instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPLE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 18); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPLE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 18; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPLE) { - final IF_ICMPLE that = (IF_ICMPLE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPLE' - - /** Defines the IF_ICMPLT instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPLT extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPLT instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPLT(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 19); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPLT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 19; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPLT) { - final IF_ICMPLT that = (IF_ICMPLT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPLT' - - /** Defines the IF_ICMPNE instruction: branch if int comparison succeeds. */ - public static final class IF_ICMPNE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IF_ICMPNE instruction. - * @param p1 value of first instruction parameter - */ - public IF_ICMPNE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 20); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IF_ICMPNE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 20; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IF_ICMPNE) { - final IF_ICMPNE that = (IF_ICMPNE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IF_ICMPNE' - - /** Defines the IFEQ instruction: branch if int comparison with zero succeeds. */ - public static final class IFEQ extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFEQ instruction. - * @param p1 value of first instruction parameter - */ - public IFEQ(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 21); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFEQ" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 21; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFEQ) { - final IFEQ that = (IFEQ) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFEQ' - - /** Defines the IFGE instruction: branch if int comparison with zero succeeds. */ - public static final class IFGE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFGE instruction. - * @param p1 value of first instruction parameter - */ - public IFGE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 22); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFGE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 22; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFGE) { - final IFGE that = (IFGE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFGE' - - /** Defines the IFGT instruction: branch if int comparison with zero succeeds. */ - public static final class IFGT extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFGT instruction. - * @param p1 value of first instruction parameter - */ - public IFGT(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 23); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFGT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 23; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFGT) { - final IFGT that = (IFGT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFGT' - - /** Defines the IFLE instruction: branch if int comparison with zero succeeds. */ - public static final class IFLE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFLE instruction. - * @param p1 value of first instruction parameter - */ - public IFLE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 24); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFLE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 24; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFLE) { - final IFLE that = (IFLE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFLE' - - /** Defines the IFLT instruction: branch if int comparison with zero succeeds. */ - public static final class IFLT extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFLT instruction. - * @param p1 value of first instruction parameter - */ - public IFLT(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 25); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFLT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 25; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFLT) { - final IFLT that = (IFLT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFLT' - - /** Defines the IFNE instruction: branch if int comparison with zero succeeds. */ - public static final class IFNE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFNE instruction. - * @param p1 value of first instruction parameter - */ - public IFNE(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 26); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFNE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 26; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFNE) { - final IFNE that = (IFNE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFNE' - - /** Defines the IFNONNULL instruction: branch if reference not null. */ - public static final class IFNONNULL extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFNONNULL instruction. - * @param p1 value of first instruction parameter - */ - public IFNONNULL(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 27); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFNONNULL" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 27; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFNONNULL) { - final IFNONNULL that = (IFNONNULL) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFNONNULL' - - /** Defines the IFNULL instruction: branch if reference not null. */ - public static final class IFNULL extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the IFNULL instruction. - * @param p1 value of first instruction parameter - */ - public IFNULL(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 28); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IFNULL" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 28; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IFNULL) { - final IFNULL that = (IFNULL) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IFNULL' - - /** Defines the IINC instruction: increment local variable by constant. */ - public static final class IINC extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** Value of second instruction parameter. */ - private final byte p2; - - /** - * Constructs an instance of the IINC instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - * @param p2 value of second instruction parameter - */ - public IINC(final short p1, final byte p2) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - this.p2 = p2; - } // end constructor (short, byte) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public byte getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, 29); - b.set(0, Helper.createInt(this.p1)); - b.set(1, Helper.createInt(this.p2)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "IINC" + " " + this.p1 + " " + this.p2; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 29; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof IINC) { - final IINC that = (IINC) obj; - return this.p1 == that.p1 - && this.p2 == that.p2; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'IINC' - - /** Defines the ILOAD instruction: load int from local variable. */ - public static final class ILOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the ILOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public ILOAD(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 30); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ILOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 30; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ILOAD) { - final ILOAD that = (ILOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ILOAD' - - /** Defines the INSTANCEOF instruction: determine if object is of given type. */ - public static final class INSTANCEOF_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the INSTANCEOF instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INSTANCEOF_TYPE(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 31); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INSTANCEOF_TYPE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 31; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INSTANCEOF_TYPE) { - final INSTANCEOF_TYPE that = (INSTANCEOF_TYPE) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INSTANCEOF_TYPE' - - /** Defines the INSTANCEOF instruction: determine if object is of given type. */ - public static final class INSTANCEOF_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** - * Constructs an instance of the INSTANCEOF instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INSTANCEOF_ARRAY(final Descriptor.Array p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor.Array) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 31); - b.set(0, wrap("Array_type", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INSTANCEOF_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 31; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INSTANCEOF_ARRAY) { - final INSTANCEOF_ARRAY that = (INSTANCEOF_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INSTANCEOF_ARRAY' - - /** Defines the INVOKEDYNAMIC instruction: invoke instance method; resolve and dispatch based on class. */ - public static final class INVOKEDYNAMIC extends Instruction { - - /** Value of first instruction parameter. */ - private final DynamicMethodRef p1; - - /** - * Constructs an instance of the INVOKEDYNAMIC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INVOKEDYNAMIC(final DynamicMethodRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (DynamicMethodRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public DynamicMethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 32); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKEDYNAMIC" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 32; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKEDYNAMIC) { - final INVOKEDYNAMIC that = (INVOKEDYNAMIC) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKEDYNAMIC' - - /** Defines the INVOKEINTERFACE instruction: invoke interface method. */ - public static final class INVOKEINTERFACE extends Instruction { - - /** Value of first instruction parameter. */ - private final MethodRef p1; - - /** Value of second instruction parameter. */ - private final short p2; - - /** - * Constructs an instance of the INVOKEINTERFACE instruction. - * @param p1 value of first instruction parameter - should not be null - * @param p2 value of second instruction parameter - should be in 0..255 - */ - public INVOKEINTERFACE(final MethodRef p1, final short p2) { - assert p1 != null : "null value"; - assert p2 >= 0 && p2 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - this.p2 = p2; - } // end constructor (MethodRef, short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public MethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public short getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, 33); - b.set(0, this.p1.toValue()); - b.set(1, Helper.createInt(this.p2)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKEINTERFACE" + " " + this.p1 + " " + this.p2; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 33; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKEINTERFACE) { - final INVOKEINTERFACE that = (INVOKEINTERFACE) obj; - return this.p1.equals(that.p1) - && this.p2 == that.p2; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKEINTERFACE' - - /** Defines the INVOKESPECIAL instruction: invoke instance method; special handling for superclass, private, and instance initialization method invocations. */ - public static final class INVOKESPECIAL extends Instruction { - - /** Value of first instruction parameter. */ - private final MethodRef p1; - - /** - * Constructs an instance of the INVOKESPECIAL instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INVOKESPECIAL(final MethodRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (MethodRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public MethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 34); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKESPECIAL" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 34; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKESPECIAL) { - final INVOKESPECIAL that = (INVOKESPECIAL) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKESPECIAL' - - /** Defines the INVOKESTATIC instruction: invoke a class (static) method. */ - public static final class INVOKESTATIC extends Instruction { - - /** Value of first instruction parameter. */ - private final MethodRef p1; - - /** - * Constructs an instance of the INVOKESTATIC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INVOKESTATIC(final MethodRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (MethodRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public MethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 35); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKESTATIC" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 35; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKESTATIC) { - final INVOKESTATIC that = (INVOKESTATIC) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKESTATIC' - - /** Defines the INVOKEVIRTUAL instruction: invoke instance method; dispatch based on class. */ - public static final class INVOKEVIRTUAL extends Instruction { - - /** Value of first instruction parameter. */ - private final MethodRef p1; - - /** - * Constructs an instance of the INVOKEVIRTUAL instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INVOKEVIRTUAL(final MethodRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (MethodRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public MethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 36); - b.set(0, this.p1.toTaggedValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKEVIRTUAL" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 36; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKEVIRTUAL) { - final INVOKEVIRTUAL that = (INVOKEVIRTUAL) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKEVIRTUAL' - - /** Defines the INVOKEVIRTUAL instruction: invoke instance method; dispatch based on class. */ - public static final class INVOKEVIRTUAL_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final ArrayMethodRef p1; - - /** - * Constructs an instance of the INVOKEVIRTUAL instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public INVOKEVIRTUAL_ARRAY(final ArrayMethodRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (ArrayMethodRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public ArrayMethodRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 36); - b.set(0, this.p1.toTaggedValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "INVOKEVIRTUAL_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 36; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof INVOKEVIRTUAL_ARRAY) { - final INVOKEVIRTUAL_ARRAY that = (INVOKEVIRTUAL_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'INVOKEVIRTUAL_ARRAY' - - /** Defines the ISTORE instruction: store int into local variable. */ - public static final class ISTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the ISTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public ISTORE(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 37); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "ISTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 37; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof ISTORE) { - final ISTORE that = (ISTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'ISTORE' - - /** Defines the JSR instruction: jump subroutine. */ - public static final class JSR extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the JSR instruction. - * @param p1 value of first instruction parameter - */ - public JSR(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 38); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "JSR" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 38; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof JSR) { - final JSR that = (JSR) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'JSR' - - /** Defines the JSR_W instruction: jump subroutine (wide index). */ - public static final class JSR_W extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the JSR_W instruction. - * @param p1 value of first instruction parameter - */ - public JSR_W(final int p1) { - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 39); - b.set(0, Helper.createInt32(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "JSR_W" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 39; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof JSR_W) { - final JSR_W that = (JSR_W) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'JSR_W' - - /** Defines the LDC instruction: push item from runtime constant pool. */ - public static final class LDC_INT extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the LDC instruction. - * @param p1 value of first instruction parameter - */ - public LDC_INT(final int p1) { - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 40); - b.set(0, wrap("Int", Helper.createInt32(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_INT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 40; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_INT) { - final LDC_INT that = (LDC_INT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_INT' - - /** Defines the LDC instruction: push item from runtime constant pool. */ - public static final class LDC_FLOAT extends Instruction { - - /** Value of first instruction parameter. */ - private final float p1; - - /** - * Constructs an instance of the LDC instruction. - * @param p1 value of first instruction parameter - */ - public LDC_FLOAT(final float p1) { - this.p1 = p1; - } // end constructor (float) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public float getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 40); - b.set(0, wrap("Float", Helper.createFloat(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_FLOAT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 40; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_FLOAT) { - final LDC_FLOAT that = (LDC_FLOAT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_FLOAT' - - /** Defines the LDC instruction: push item from runtime constant pool. */ - public static final class LDC_STRING extends Instruction { - - /** Value of first instruction parameter. */ - private final String p1; - - /** - * Constructs an instance of the LDC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_STRING(final String p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (String) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public String getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 40); - b.set(0, wrap("String", Helper.createString(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_STRING" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 40; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_STRING) { - final LDC_STRING that = (LDC_STRING) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_STRING' - - /** Defines the LDC instruction: push item from runtime constant pool. */ - public static final class LDC_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the LDC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_TYPE(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 40); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_TYPE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 40; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_TYPE) { - final LDC_TYPE that = (LDC_TYPE) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_TYPE' - - /** Defines the LDC instruction: push item from runtime constant pool. */ - public static final class LDC_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** - * Constructs an instance of the LDC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_ARRAY(final Descriptor.Array p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor.Array) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 40); - b.set(0, wrap("Array_type", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 40; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_ARRAY) { - final LDC_ARRAY that = (LDC_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_ARRAY' - - /** Defines the LDC2_W instruction: push long or double from runtime constant pool (wide index). */ - public static final class LDC2_W_LONG extends Instruction { - - /** Value of first instruction parameter. */ - private final long p1; - - /** - * Constructs an instance of the LDC2_W instruction. - * @param p1 value of first instruction parameter - */ - public LDC2_W_LONG(final long p1) { - this.p1 = p1; - } // end constructor (long) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public long getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 41); - b.set(0, wrap("Long", Helper.createInt64(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC2_W_LONG" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 41; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC2_W_LONG) { - final LDC2_W_LONG that = (LDC2_W_LONG) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC2_W_LONG' - - /** Defines the LDC2_W instruction: push long or double from runtime constant pool (wide index). */ - public static final class LDC2_W_DOUBLE extends Instruction { - - /** Value of first instruction parameter. */ - private final double p1; - - /** - * Constructs an instance of the LDC2_W instruction. - * @param p1 value of first instruction parameter - */ - public LDC2_W_DOUBLE(final double p1) { - this.p1 = p1; - } // end constructor (double) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public double getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 41); - b.set(0, wrap("Double", Helper.createFloat(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC2_W_DOUBLE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 41; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC2_W_DOUBLE) { - final LDC2_W_DOUBLE that = (LDC2_W_DOUBLE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC2_W_DOUBLE' - - /** Defines the LDC_W instruction: push item from runtime constant pool (wide index). */ - public static final class LDC_W_INT extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the LDC_W instruction. - * @param p1 value of first instruction parameter - */ - public LDC_W_INT(final int p1) { - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 42); - b.set(0, wrap("Int", Helper.createInt32(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_W_INT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 42; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_W_INT) { - final LDC_W_INT that = (LDC_W_INT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_W_INT' - - /** Defines the LDC_W instruction: push item from runtime constant pool (wide index). */ - public static final class LDC_W_FLOAT extends Instruction { - - /** Value of first instruction parameter. */ - private final float p1; - - /** - * Constructs an instance of the LDC_W instruction. - * @param p1 value of first instruction parameter - */ - public LDC_W_FLOAT(final float p1) { - this.p1 = p1; - } // end constructor (float) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public float getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 42); - b.set(0, wrap("Float", Helper.createFloat(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_W_FLOAT" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 42; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_W_FLOAT) { - final LDC_W_FLOAT that = (LDC_W_FLOAT) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_W_FLOAT' - - /** Defines the LDC_W instruction: push item from runtime constant pool (wide index). */ - public static final class LDC_W_STRING extends Instruction { - - /** Value of first instruction parameter. */ - private final String p1; - - /** - * Constructs an instance of the LDC_W instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_W_STRING(final String p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (String) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public String getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 42); - b.set(0, wrap("String", Helper.createString(this.p1))); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_W_STRING" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 42; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_W_STRING) { - final LDC_W_STRING that = (LDC_W_STRING) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_W_STRING' - - /** Defines the LDC_W instruction: push item from runtime constant pool (wide index). */ - public static final class LDC_W_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the LDC_W instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_W_TYPE(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 42); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_W_TYPE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 42; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_W_TYPE) { - final LDC_W_TYPE that = (LDC_W_TYPE) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_W_TYPE' - - /** Defines the LDC_W instruction: push item from runtime constant pool (wide index). */ - public static final class LDC_W_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** - * Constructs an instance of the LDC_W instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public LDC_W_ARRAY(final Descriptor.Array p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor.Array) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 42); - b.set(0, wrap("Array_type", this.p1.toValue())); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LDC_W_ARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 42; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LDC_W_ARRAY) { - final LDC_W_ARRAY that = (LDC_W_ARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LDC_W_ARRAY' - - /** Defines the LLOAD instruction: load long from local variable. */ - public static final class LLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the LLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public LLOAD(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 43); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 43; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LLOAD) { - final LLOAD that = (LLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LLOAD' - - /** Defines the LOOKUPSWITCH instruction: access jump table by key match and jump. */ - public static final class LOOKUPSWITCH extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** Value of second instruction parameter. */ - private final int p2; - - /** Value of third instruction parameter. */ - private final List p3; - - /** - * Constructs an instance of the LOOKUPSWITCH instruction. - * @param p1 value of first instruction parameter - * @param p2 value of second instruction parameter - * @param p3 value of third instruction parameter - should not be null - */ - public LOOKUPSWITCH(final int p1, final int p2, final List p3) { - assert p3 != null : "null value"; - this.p1 = p1; - this.p2 = p2; - this.p3 = new LinkedList(p3); - } // end constructor (int, int, List) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public int getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * Returns the value of the third parameter. - * @return the value of the third parameter - */ - public List getThirdParameter() { - return new LinkedList(this.p3); - } // end method 'getThirdParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(3, 44); - b.set(0, Helper.createInt32(this.p1)); - b.set(1, Helper.createInt32(this.p2)); - b.set(2, API.encodeList(this.p3)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LOOKUPSWITCH" + " " + this.p1 + " " + this.p2 + " " + this.p3; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 44; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LOOKUPSWITCH) { - final LOOKUPSWITCH that = (LOOKUPSWITCH) obj; - return this.p1 == that.p1 - && this.p2 == that.p2 - && this.p3.equals(that.p3); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LOOKUPSWITCH' - - /** Defines the LSTORE instruction: store long into local variable. */ - public static final class LSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the LSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public LSTORE(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 45); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "LSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 45; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof LSTORE) { - final LSTORE that = (LSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'LSTORE' - - /** Defines the MULTIANEWARRAY instruction: create new multidimensional array. */ - public static final class MULTIANEWARRAY_TYPE extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** Value of second instruction parameter. */ - private final short p2; - - /** - * Constructs an instance of the MULTIANEWARRAY instruction. - * @param p1 value of first instruction parameter - should not be null - * @param p2 value of second instruction parameter - should be in 0..255 - */ - public MULTIANEWARRAY_TYPE(final TypeName p1, final short p2) { - assert p1 != null : "null value"; - assert p2 >= 0 && p2 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - this.p2 = p2; - } // end constructor (TypeName, short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public short getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, 46); - b.set(0, wrap("Class_or_interface", this.p1.toValue())); - b.set(1, Helper.createInt(this.p2)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MULTIANEWARRAY_TYPE" + " " + this.p1 + " " + this.p2; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 46; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MULTIANEWARRAY_TYPE) { - final MULTIANEWARRAY_TYPE that = (MULTIANEWARRAY_TYPE) obj; - return this.p1.equals(that.p1) - && this.p2 == that.p2; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MULTIANEWARRAY_TYPE' - - /** Defines the MULTIANEWARRAY instruction: create new multidimensional array. */ - public static final class MULTIANEWARRAY_ARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor.Array p1; - - /** Value of second instruction parameter. */ - private final short p2; - - /** - * Constructs an instance of the MULTIANEWARRAY instruction. - * @param p1 value of first instruction parameter - should not be null - * @param p2 value of second instruction parameter - should be in 0..255 - */ - public MULTIANEWARRAY_ARRAY(final Descriptor.Array p1, final short p2) { - assert p1 != null : "null value"; - assert p2 >= 0 && p2 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - this.p2 = p2; - } // end constructor (Descriptor.Array, short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor.Array getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public short getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, 46); - b.set(0, wrap("Array_type", this.p1.toValue())); - b.set(1, Helper.createInt(this.p2)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "MULTIANEWARRAY_ARRAY" + " " + this.p1 + " " + this.p2; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 46; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof MULTIANEWARRAY_ARRAY) { - final MULTIANEWARRAY_ARRAY that = (MULTIANEWARRAY_ARRAY) obj; - return this.p1.equals(that.p1) - && this.p2 == that.p2; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'MULTIANEWARRAY_ARRAY' - - /** Defines the NEW instruction: create new object. */ - public static final class NEW extends Instruction { - - /** Value of first instruction parameter. */ - private final TypeName p1; - - /** - * Constructs an instance of the NEW instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public NEW(final TypeName p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (TypeName) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public TypeName getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 47); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "NEW" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 47; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof NEW) { - final NEW that = (NEW) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'NEW' - - /** Defines the NEWARRAY instruction: create new arrayhandler. */ - public static final class NEWARRAY extends Instruction { - - /** Value of first instruction parameter. */ - private final Descriptor p1; - - /** - * Constructs an instance of the NEWARRAY instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public NEWARRAY(final Descriptor p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (Descriptor) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public Descriptor getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 48); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "NEWARRAY" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 48; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof NEWARRAY) { - final NEWARRAY that = (NEWARRAY) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'NEWARRAY' - - /** Defines the PUTFIELD instruction: set field in object. */ - public static final class PUTFIELD extends Instruction { - - /** Value of first instruction parameter. */ - private final FieldRef p1; - - /** - * Constructs an instance of the PUTFIELD instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public PUTFIELD(final FieldRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (FieldRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public FieldRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 49); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "PUTFIELD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 49; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof PUTFIELD) { - final PUTFIELD that = (PUTFIELD) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'PUTFIELD' - - /** Defines the PUTSTATIC instruction: set static field in class. */ - public static final class PUTSTATIC extends Instruction { - - /** Value of first instruction parameter. */ - private final FieldRef p1; - - /** - * Constructs an instance of the PUTSTATIC instruction. - * @param p1 value of first instruction parameter - should not be null - */ - public PUTSTATIC(final FieldRef p1) { - assert p1 != null : "null value"; - this.p1 = p1; - } // end constructor (FieldRef) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public FieldRef getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 50); - b.set(0, this.p1.toValue()); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "PUTSTATIC" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 50; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof PUTSTATIC) { - final PUTSTATIC that = (PUTSTATIC) obj; - return this.p1.equals(that.p1); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'PUTSTATIC' - - /** Defines the RET instruction: return from subroutine. */ - public static final class RET extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the RET instruction. - * @param p1 value of first instruction parameter - should be in 0..255 - */ - public RET(final short p1) { - assert p1 >= 0 && p1 <= 255 : "invalid unsigned byte"; - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 51); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "RET" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 51; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof RET) { - final RET that = (RET) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'RET' - - /** Defines the SIPUSH instruction: push short. */ - public static final class SIPUSH extends Instruction { - - /** Value of first instruction parameter. */ - private final short p1; - - /** - * Constructs an instance of the SIPUSH instruction. - * @param p1 value of first instruction parameter - */ - public SIPUSH(final short p1) { - this.p1 = p1; - } // end constructor (short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public short getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 52); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "SIPUSH" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 52; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof SIPUSH) { - final SIPUSH that = (SIPUSH) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'SIPUSH' - - /** Defines the TABLESWITCH instruction: access jump table by index and jump. */ - public static final class TABLESWITCH extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** Value of second instruction parameter. */ - private final int p2; - - /** Value of third instruction parameter. */ - private final int p3; - - /** Value of fourth instruction parameter. */ - private final List p4; - - /** - * Constructs an instance of the TABLESWITCH instruction. - * @param p1 value of first instruction parameter - * @param p2 value of second instruction parameter - * @param p3 value of third instruction parameter - * @param p4 value of fourth instruction parameter - should not be null - */ - public TABLESWITCH(final int p1, final int p2, final int p3, final List p4) { - assert p4 != null : "null value"; - assert (p3 - p2) + 1 != p4.size() : "invalid list length"; - this.p1 = p1; - this.p2 = p2; - this.p3 = p3; - this.p4 = new LinkedList(p4); - } // end constructor (int, int, int, List) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public int getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * Returns the value of the third parameter. - * @return the value of the third parameter - */ - public int getThirdParameter() { - return this.p3; - } // end method 'getThirdParameter()' - - /** - * Returns the value of the fourth parameter. - * @return the value of the fourth parameter - */ - public List getFourthParameter() { - return new LinkedList(this.p4); - } // end method 'getFourthParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(4, 53); - b.set(0, Helper.createInt32(this.p1)); - b.set(1, Helper.createInt32(this.p2)); - b.set(2, Helper.createInt32(this.p3)); - b.set(3, encodeIntegerList(this.p4)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "TABLESWITCH" + " " + this.p1 + " " + this.p2 + " " + this.p3 + " " + this.p4; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 53; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof TABLESWITCH) { - final TABLESWITCH that = (TABLESWITCH) obj; - return this.p1 == that.p1 - && this.p2 == that.p2 - && this.p3 == that.p3 - && this.p4.equals(that.p4); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'TABLESWITCH' - - /** Defines the WIDE_ALOAD instruction: load reference from local variable. */ - public static final class WIDE_ALOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_ALOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_ALOAD(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 54); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_ALOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 54; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_ALOAD) { - final WIDE_ALOAD that = (WIDE_ALOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_ALOAD' - - /** Defines the WIDE_ASTORE instruction: store reference into local variable. */ - public static final class WIDE_ASTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_ASTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_ASTORE(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 55); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_ASTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 55; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_ASTORE) { - final WIDE_ASTORE that = (WIDE_ASTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_ASTORE' - - /** Defines the WIDE_DLOAD instruction: load double from local variable. */ - public static final class WIDE_DLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_DLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_DLOAD(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 56); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_DLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 56; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_DLOAD) { - final WIDE_DLOAD that = (WIDE_DLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_DLOAD' - - /** Defines the WIDE_DSTORE instruction: store double into local variable. */ - public static final class WIDE_DSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_DSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_DSTORE(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 57); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_DSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 57; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_DSTORE) { - final WIDE_DSTORE that = (WIDE_DSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_DSTORE' - - /** Defines the WIDE_FLOAD instruction: load float from local variable. */ - public static final class WIDE_FLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_FLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_FLOAD(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 58); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_FLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 58; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_FLOAD) { - final WIDE_FLOAD that = (WIDE_FLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_FLOAD' - - /** Defines the WIDE_FSTORE instruction: store float into local variable. */ - public static final class WIDE_FSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_FSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_FSTORE(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 59); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_FSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 59; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_FSTORE) { - final WIDE_FSTORE that = (WIDE_FSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_FSTORE' - - /** Defines the WIDE_IINC instruction: increment local variable by constant. */ - public static final class WIDE_IINC extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** Value of second instruction parameter. */ - private final short p2; - - /** - * Constructs an instance of the WIDE_IINC instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - * @param p2 value of second instruction parameter - */ - public WIDE_IINC(final int p1, final short p2) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - this.p2 = p2; - } // end constructor (int, short) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * Returns the value of the second parameter. - * @return the value of the second parameter - */ - public short getSecondParameter() { - return this.p2; - } // end method 'getSecondParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(2, 60); - b.set(0, Helper.createInt(this.p1)); - b.set(1, Helper.createInt(this.p2)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_IINC" + " " + this.p1 + " " + this.p2; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 60; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_IINC) { - final WIDE_IINC that = (WIDE_IINC) obj; - return this.p1 == that.p1 - && this.p2 == that.p2; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_IINC' - - /** Defines the WIDE_ILOAD instruction: load int from local variable. */ - public static final class WIDE_ILOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_ILOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_ILOAD(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 61); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_ILOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 61; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_ILOAD) { - final WIDE_ILOAD that = (WIDE_ILOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_ILOAD' - - /** Defines the WIDE_ISTORE instruction: store int into local variable. */ - public static final class WIDE_ISTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_ISTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_ISTORE(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 62); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_ISTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 62; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_ISTORE) { - final WIDE_ISTORE that = (WIDE_ISTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_ISTORE' - - /** Defines the WIDE_LLOAD instruction: load long from local variable. */ - public static final class WIDE_LLOAD extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_LLOAD instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_LLOAD(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 63); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_LLOAD" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 63; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_LLOAD) { - final WIDE_LLOAD that = (WIDE_LLOAD) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_LLOAD' - - /** Defines the WIDE_LSTORE instruction: store long into local variable. */ - public static final class WIDE_LSTORE extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_LSTORE instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_LSTORE(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 64); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_LSTORE" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 64; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_LSTORE) { - final WIDE_LSTORE that = (WIDE_LSTORE) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_LSTORE' - - /** Defines the WIDE_RET instruction: return from subroutine. */ - public static final class WIDE_RET extends Instruction { - - /** Value of first instruction parameter. */ - private final int p1; - - /** - * Constructs an instance of the WIDE_RET instruction. - * @param p1 value of first instruction parameter - should be in 0..65535 - */ - public WIDE_RET(final int p1) { - assert p1 >= 0 && p1 <= 65535 : "invalid unsigned short"; - this.p1 = p1; - } // end constructor (int) - - /** - * Returns the value of the first parameter. - * @return the value of the first parameter - */ - public int getFirstParameter() { - return this.p1; - } // end method 'getFirstParameter()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - final Block b = Block.createBlock(1, 65); - b.set(0, Helper.createInt(this.p1)); - return Value.createFromBlock(b); - } // end method 'toValue()' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "WIDE_RET" + " " + this.p1; - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return 65; - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof WIDE_RET) { - final WIDE_RET that = (WIDE_RET) obj; - return this.p1 == that.p1; - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - - } // end inner-class 'WIDE_RET' - - /** The tag for 'type' elements. */ - private static final int TAG_TYPE = Hash.hashVariant("Class_or_interface").asLong(); - - /** The tag for 'array' elements. */ - private static final int TAG_ARRAY = Hash.hashVariant("Array_type").asLong(); - - /** The tag for 'int' elements. */ - private static final int TAG_INT = Hash.hashVariant("Int").asLong(); - - /** The tag for 'float' elements. */ - private static final int TAG_FLOAT = Hash.hashVariant("Float").asLong(); - - /** The tag for 'double' elements. */ - private static final int TAG_DOUBLE = Hash.hashVariant("Double").asLong(); - - /** The tag for 'long' elements. */ - private static final int TAG_LONG = Hash.hashVariant("Long").asLong(); - - /** The tag for 'string' elements. */ - private static final int TAG_STRING = Hash.hashVariant("String").asLong(); - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - @SuppressWarnings("fallthrough") - static Instruction fromValue(final Value v) { - assert v != null : "null v"; - if (v.isLong()) { - switch (v.asLong()) { - case 0: return AALOAD; - case 1: return AASTORE; - case 2: return ACONST_NULL; - case 3: return ALOAD_0; - case 4: return ALOAD_1; - case 5: return ALOAD_2; - case 6: return ALOAD_3; - case 7: return ARETURN; - case 8: return ARRAYLENGTH; - case 9: return ASTORE_0; - case 10: return ASTORE_1; - case 11: return ASTORE_2; - case 12: return ASTORE_3; - case 13: return ATHROW; - case 14: return BALOAD; - case 15: return BASTORE; - case 16: return CALOAD; - case 17: return CASTORE; - case 18: return D2F; - case 19: return D2I; - case 20: return D2L; - case 21: return DADD; - case 22: return DALOAD; - case 23: return DASTORE; - case 24: return DCMPG; - case 25: return DCMPL; - case 26: return DCONST_0; - case 27: return DCONST_1; - case 28: return DDIV; - case 29: return DLOAD_0; - case 30: return DLOAD_1; - case 31: return DLOAD_2; - case 32: return DLOAD_3; - case 33: return DMUL; - case 34: return DNEG; - case 35: return DREM; - case 36: return DRETURN; - case 37: return DSTORE_0; - case 38: return DSTORE_1; - case 39: return DSTORE_2; - case 40: return DSTORE_3; - case 41: return DSUB; - case 42: return DUP; - case 43: return DUP2; - case 44: return DUP2_X1; - case 45: return DUP2_X2; - case 46: return DUP_X1; - case 47: return DUP_X2; - case 48: return F2D; - case 49: return F2I; - case 50: return F2L; - case 51: return FADD; - case 52: return FALOAD; - case 53: return FASTORE; - case 54: return FCMPG; - case 55: return FCMPL; - case 56: return FCONST_0; - case 57: return FCONST_1; - case 58: return FCONST_2; - case 59: return FDIV; - case 60: return FLOAD_0; - case 61: return FLOAD_1; - case 62: return FLOAD_2; - case 63: return FLOAD_3; - case 64: return FMUL; - case 65: return FNEG; - case 66: return FREM; - case 67: return FRETURN; - case 68: return FSTORE_0; - case 69: return FSTORE_1; - case 70: return FSTORE_2; - case 71: return FSTORE_3; - case 72: return FSUB; - case 73: return I2B; - case 74: return I2C; - case 75: return I2D; - case 76: return I2F; - case 77: return I2L; - case 78: return I2S; - case 79: return IADD; - case 80: return IALOAD; - case 81: return IAND; - case 82: return IASTORE; - case 83: return ICONST_0; - case 84: return ICONST_1; - case 85: return ICONST_2; - case 86: return ICONST_3; - case 87: return ICONST_4; - case 88: return ICONST_5; - case 89: return ICONST_M1; - case 90: return IDIV; - case 91: return ILOAD_0; - case 92: return ILOAD_1; - case 93: return ILOAD_2; - case 94: return ILOAD_3; - case 95: return IMUL; - case 96: return INEG; - case 97: return IOR; - case 98: return IREM; - case 99: return IRETURN; - case 100: return ISHL; - case 101: return ISHR; - case 102: return ISTORE_0; - case 103: return ISTORE_1; - case 104: return ISTORE_2; - case 105: return ISTORE_3; - case 106: return ISUB; - case 107: return IUSHR; - case 108: return IXOR; - case 109: return L2D; - case 110: return L2F; - case 111: return L2I; - case 112: return LADD; - case 113: return LALOAD; - case 114: return LAND; - case 115: return LASTORE; - case 116: return LCMP; - case 117: return LCONST_0; - case 118: return LCONST_1; - case 119: return LDIV; - case 120: return LLOAD_0; - case 121: return LLOAD_1; - case 122: return LLOAD_2; - case 123: return LLOAD_3; - case 124: return LMUL; - case 125: return LNEG; - case 126: return LOR; - case 127: return LREM; - case 128: return LRETURN; - case 129: return LSHL; - case 130: return LSHR; - case 131: return LSTORE_0; - case 132: return LSTORE_1; - case 133: return LSTORE_2; - case 134: return LSTORE_3; - case 135: return LSUB; - case 136: return LUSHR; - case 137: return LXOR; - case 138: return MONITORENTER; - case 139: return MONITOREXIT; - case 140: return NOP; - case 141: return POP; - case 142: return POP2; - case 143: return RETURN; - case 144: return SALOAD; - case 145: return SASTORE; - case 146: return SWAP; - default: - assert false : "invalid tag"; - return null; - } // end switch - } else { - final Block b = v.asBlock(); - switch (b.getTag()) { - case 0: return new ALOAD((short) b.get(0).asLong()); - case 1: if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new ANEWARRAY_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new ANEWARRAY_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 2: return new ASTORE((short) b.get(0).asLong()); - case 3: return new BIPUSH((byte) b.get(0).asLong()); - case 4: if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new CHECKCAST_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new CHECKCAST_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 5: return new DLOAD((short) b.get(0).asLong()); - case 6: return new DSTORE((short) b.get(0).asLong()); - case 7: return new FLOAD((short) b.get(0).asLong()); - case 8: return new FSTORE((short) b.get(0).asLong()); - case 9: return new GETFIELD(FieldRef.fromValue(b.get(0))); - case 10: return new GETSTATIC(FieldRef.fromValue(b.get(0))); - case 11: return new GOTO((short) b.get(0).asLong()); - case 12: return new GOTO_W(b.get(0).asBlock().asInt32()); - case 13: return new IF_ACMPEQ((short) b.get(0).asLong()); - case 14: return new IF_ACMPNE((short) b.get(0).asLong()); - case 15: return new IF_ICMPEQ((short) b.get(0).asLong()); - case 16: return new IF_ICMPGE((short) b.get(0).asLong()); - case 17: return new IF_ICMPGT((short) b.get(0).asLong()); - case 18: return new IF_ICMPLE((short) b.get(0).asLong()); - case 19: return new IF_ICMPLT((short) b.get(0).asLong()); - case 20: return new IF_ICMPNE((short) b.get(0).asLong()); - case 21: return new IFEQ((short) b.get(0).asLong()); - case 22: return new IFGE((short) b.get(0).asLong()); - case 23: return new IFGT((short) b.get(0).asLong()); - case 24: return new IFLE((short) b.get(0).asLong()); - case 25: return new IFLT((short) b.get(0).asLong()); - case 26: return new IFNE((short) b.get(0).asLong()); - case 27: return new IFNONNULL((short) b.get(0).asLong()); - case 28: return new IFNULL((short) b.get(0).asLong()); - case 29: return new IINC((short) b.get(0).asLong(), (byte) b.get(1).asLong()); - case 30: return new ILOAD((short) b.get(0).asLong()); - case 31: if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new INSTANCEOF_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new INSTANCEOF_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 32: return new INVOKEDYNAMIC(DynamicMethodRef.fromValue(b.get(0))); - case 33: return new INVOKEINTERFACE(MethodRef.fromValue(b.get(0)), (short) b.get(1).asLong()); - case 34: return new INVOKESPECIAL(MethodRef.fromValue(b.get(0))); - case 35: return new INVOKESTATIC(MethodRef.fromValue(b.get(0))); - case 36: if (b.get(0).asBlock().get(0).asBlock().get(0).asLong() == TAG_TYPE) return new INVOKEVIRTUAL(MethodRef.fromTaggedValue(b.get(0))); else if (b.get(0).asBlock().get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new INVOKEVIRTUAL_ARRAY(ArrayMethodRef.fromTaggedValue(b.get(0))); - case 37: return new ISTORE((short) b.get(0).asLong()); - case 38: return new JSR((short) b.get(0).asLong()); - case 39: return new JSR_W(b.get(0).asBlock().asInt32()); - case 40: if (b.get(0).asBlock().get(0).asLong() == TAG_INT) return new LDC_INT(b.get(0).asBlock().get(1).asBlock().asInt32()); else if (b.get(0).asBlock().get(0).asLong() == TAG_FLOAT) return new LDC_FLOAT((float) b.get(0).asBlock().get(1).asBlock().asDouble()); else if (b.get(0).asBlock().get(0).asLong() == TAG_STRING) return new LDC_STRING(b.get(0).asBlock().get(1).asBlock().asString()); else if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new LDC_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new LDC_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 41: if (b.get(0).asBlock().get(0).asLong() == TAG_LONG) return new LDC2_W_LONG(b.get(0).asBlock().get(1).asBlock().asInt64()); else if (b.get(0).asBlock().get(0).asLong() == TAG_DOUBLE) return new LDC2_W_DOUBLE(b.get(0).asBlock().get(1).asBlock().asDouble()); - case 42: if (b.get(0).asBlock().get(0).asLong() == TAG_INT) return new LDC_W_INT(b.get(0).asBlock().get(1).asBlock().asInt32()); else if (b.get(0).asBlock().get(0).asLong() == TAG_FLOAT) return new LDC_W_FLOAT((float) b.get(0).asBlock().get(1).asBlock().asDouble()); else if (b.get(0).asBlock().get(0).asLong() == TAG_STRING) return new LDC_W_STRING(b.get(0).asBlock().get(1).asBlock().asString()); else if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new LDC_W_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1))); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new LDC_W_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1))); - case 43: return new LLOAD((short) b.get(0).asLong()); - case 44: return new LOOKUPSWITCH(b.get(0).asBlock().asInt32(), b.get(1).asBlock().asInt32(), MatchOffsetPair.listFromValue(b.get(2))); - case 45: return new LSTORE((short) b.get(0).asLong()); - case 46: if (b.get(0).asBlock().get(0).asLong() == TAG_TYPE) return new MULTIANEWARRAY_TYPE(TypeName.fromValue(b.get(0).asBlock().get(1)), (short) b.get(0).asBlock().get(2).asLong()); else if (b.get(0).asBlock().get(0).asLong() == TAG_ARRAY) return new MULTIANEWARRAY_ARRAY((Descriptor.Array) Descriptor.fromValue(b.get(0).asBlock().get(1)), (short) b.get(0).asBlock().get(2).asLong()); - case 47: return new NEW(TypeName.fromValue(b.get(0))); - case 48: return new NEWARRAY(Descriptor.fromValue(b.get(0))); - case 49: return new PUTFIELD(FieldRef.fromValue(b.get(0))); - case 50: return new PUTSTATIC(FieldRef.fromValue(b.get(0))); - case 51: return new RET((short) b.get(0).asLong()); - case 52: return new SIPUSH((short) b.get(0).asLong()); - case 53: return new TABLESWITCH(b.get(0).asBlock().asInt32(), b.get(1).asBlock().asInt32(), b.get(2).asBlock().asInt32(), readIntegerList(b.get(3))); - case 54: return new WIDE_ALOAD(b.get(0).asLong()); - case 55: return new WIDE_ASTORE(b.get(0).asLong()); - case 56: return new WIDE_DLOAD(b.get(0).asLong()); - case 57: return new WIDE_DSTORE(b.get(0).asLong()); - case 58: return new WIDE_FLOAD(b.get(0).asLong()); - case 59: return new WIDE_FSTORE(b.get(0).asLong()); - case 60: return new WIDE_IINC(b.get(0).asLong(), (short) b.get(1).asLong()); - case 61: return new WIDE_ILOAD(b.get(0).asLong()); - case 62: return new WIDE_ISTORE(b.get(0).asLong()); - case 63: return new WIDE_LLOAD(b.get(0).asLong()); - case 64: return new WIDE_LSTORE(b.get(0).asLong()); - case 65: return new WIDE_RET(b.get(0).asLong()); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end if/else - } // end method 'fromValue(Value)' - -} // end class 'Instruction' rmfile ./api/src/fr/x9c/barista/api/Instruction.java hunk ./api/src/fr/x9c/barista/api/Method.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.LinkedList; -import java.util.List; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a Java method. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class Method implements ToValue { - - /** This enum defines the different method kinds. */ - public enum Kind { REGULAR, CONSTRUCTOR, INITIALIZER } - - /** Method kind. */ - private final Kind kind; - - /** Method flags. */ - private final List flags; - - /** Method name. */ - private final String name; - - /** Method return type. */ - private final Descriptor returnType; - - /** Method parameter types. */ - private final List parameterTypes; - - /** Method attributes. */ - private final List attributes; - - /** Whether initializer is strictfp. */ - private final boolean strict; - - /** - * Constructs a regular method. - * @param f method flags - should not be null, - * should also be method flags - * @param n method name - should not be null - * @param r method return type - should not be null - * @param p method parameter types - should not be null, - * should also be non-void descriptors - * @param a method attributes - should not be null, - * should also be method attributes - * @throws BaristaException if one of the flags is not a valid flag - * @throws BaristaException if one of the descriptors is not a valid descriptor - * @throws BaristaException if one of the attributes is not a valid attribute - */ - public Method(final List f, - final String n, - final Descriptor r, - final List p, - final List a) - throws BaristaException { - assert f != null : "null f"; - assert n != null : "null n"; - assert r != null : "null r"; - assert p != null : "null p"; - assert a != null : "null a"; - if (!AccessFlag.areMethodFlags(f)) { - throw new BaristaException("invalid flag"); - } // end if - if (!Descriptor.areFieldDescriptors(p)) { - throw new BaristaException("invalid descriptor"); - } // end if - if (!Attribute.areMethodAttributes(a)) { - throw new BaristaException("invalid attribute"); - } // end if - this.kind = Kind.REGULAR; - this.flags = new LinkedList(f); - this.name = n; - this.returnType = r; - this.parameterTypes = new LinkedList(p); - this.attributes = new LinkedList(a); - this.strict = false; - } // end constructor(List, String, Descriptor, List, List) - - /** - * Constructs a constructor method. - * @param f constructor flags - should not be null, - * should also be constructor flags - * @param p constructor parameter types - should not be null, - * should also be non-void descriptors - * @param a constructor attributes - should not be null, - * should also be method attributes - * @throws BaristaException if one of the flags is not a valid flag - * @throws BaristaException if one of the descriptors is not a valid descriptor - * @throws BaristaException if one of the attributes is not a valid attribute - */ - public Method(final List f, - final List p, - final List a) - throws BaristaException { - assert f != null : "null f"; - assert p != null : "null p"; - assert a != null : "null a"; - if (!AccessFlag.areMethodFlags(f)) { - throw new BaristaException("invalid flag"); - } // end if - if (!Descriptor.areFieldDescriptors(p)) { - throw new BaristaException("invalid descriptor"); - } // end if - if (!Attribute.areMethodAttributes(a)) { - throw new BaristaException("invalid attribute"); - } // end if - this.kind = Kind.CONSTRUCTOR; - this.flags = new LinkedList(f); - this.name = null; - this.returnType = null; - this.parameterTypes = new LinkedList(p); - this.attributes = new LinkedList(a); - this.strict = false; - } // end constructor(List, List, List) - - /** - * Constructs an initializer method. - * @param s whether initializer is strictfp - * @param a initializer attributes - should not be null, - * should also be method attributes - * @throws BaristaException if one of the attributes is not a valid attribute - */ - public Method(final boolean s, final List a) - throws BaristaException { - assert a != null : "null a"; - if (!Attribute.areMethodAttributes(a)) { - throw new BaristaException("invalid attribute"); - } // end if - this.kind = Kind.INITIALIZER; - this.flags = null; - this.name = null; - this.returnType = null; - this.parameterTypes = null; - this.attributes = new LinkedList(a); - this.strict = s; - } // end constructor(boolean, List) - - /** - * Returns the method kind. - * @return the method kind - */ - public Kind getKind() { - return this.kind; - } // end method 'getKind()' - - /** - * Returns the method flags. - * @return the method flags - */ - public List getFlags() { - return new LinkedList(this.flags); - } // end method 'getFlags()' - - /** - * Returns the method name. - * @return the method name - */ - public String getName() { - return this.name; - } // end method 'getName()' - - /** - * Returns the method return type. - * @return the method return type - */ - public Descriptor getReturnType() { - return this.returnType; - } // end method 'getReturnType()' - - /** - * Returns the method parameter types. - * @return the method parameter types - */ - public List getParameterTypes() { - return new LinkedList(this.parameterTypes); - } // end method 'getParameterTypes()' - - /** - * Returns the method attributes. - * @return the method attributes - */ - public List getAttribute() { - return new LinkedList(this.attributes); - } // end method 'getAttribute()' - - /** - * Tests whether the method is an initializer that is strictfp. - * @return true if the method is an initializer that is strictfp, - * false otherwise - */ - public boolean isStrict() { - return this.strict; - } // end method 'isStrict()' - - /** - * {@inheritDoc} - */ - public Value toValue() { - switch (this.kind) { - case REGULAR: - final Block desc = Block.createBlock(0, - API.encodeList(this.parameterTypes), - this.returnType.toValue()); - final Block b1 = Block.createBlock(0, - API.encodeList(this.flags), - API.createMethodName(this.name), - Value.createFromBlock(desc), - API.encodeList(this.attributes)); - return Value.createFromBlock(b1); - case CONSTRUCTOR: - final Block b2 = Block.createBlock(1, - API.encodeList(this.flags), - API.encodeList(this.parameterTypes), - API.encodeList(this.attributes)); - return Value.createFromBlock(b2); - case INITIALIZER: - final Block b3 = Block.createBlock(2, - this.strict ? Value.TRUE : Value.FALSE, - API.encodeList(this.attributes)); - return Value.createFromBlock(b3); - default: - assert false : "invalid kind"; - return null; - } // end switch - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Method fromValue(final Value v) { - assert v != null : "null v"; - final Block b = v.asBlock(); - switch (b.getTag()) { - case 0: - final List f1 = new LinkedList(); - for (Value f : API.decodeList(b.get(0))) { - f1.add(AccessFlag.fromValue(f)); - } // end for - final Descriptor r1 = Descriptor.fromValue(b.get(2).asBlock().get(1)); - final List p1 = new LinkedList(); - for (Value d : API.decodeList(b.get(2).asBlock().get(0))) { - p1.add(Descriptor.fromValue(d)); - } // end for - final List a1 = new LinkedList(); - for (Value a : API.decodeList(b.get(3))) { - a1.add(Attribute.fromValue(a)); - } // end for - return new Method(f1, API.stringOfMethodName(b.get(1)), r1, p1, a1); - case 1: - final List f2 = new LinkedList(); - for (Value f : API.decodeList(b.get(0))) { - f2.add(AccessFlag.fromValue(f)); - } // end for - final List p2 = new LinkedList(); - for (Value d : API.decodeList(b.get(1))) { - p2.add(Descriptor.fromValue(d)); - } // end for - final List a2 = new LinkedList(); - for (Value a : API.decodeList(b.get(2))) { - a2.add(Attribute.fromValue(a)); - } // end for - return new Method(f2, p2, a2); - case 2: - final List a3 = new LinkedList(); - for (Value a : API.decodeList(b.get(1))) { - a3.add(Attribute.fromValue(a)); - } // end for - return new Method(b.get(0) == Value.TRUE, a3); - default: - assert false : "invalid tag"; - return null; - } // end switch - } // end method 'fromValue(Value)' - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - final String f = this.flags != null - ? AccessFlag.listToString(this.flags) - : ""; - switch (this.kind) { - case REGULAR: - if (f.length() > 0) { - sb.append(f); - sb.append(" "); - } // end if - sb.append(this.returnType.toString()); - sb.append(" "); - sb.append(this.name); - sb.append("("); - sb.append(Descriptor.listToString(this.parameterTypes)); - sb.append(")"); - return sb.toString(); - case CONSTRUCTOR: - if (f.length() > 0) { - sb.append(f); - sb.append(" "); - } // end if - sb.append(""); - sb.append("("); - sb.append(Descriptor.listToString(this.parameterTypes)); - sb.append(")"); - return sb.toString(); - case INITIALIZER: - if (this.strict) { - sb.append("strictfp "); - } // end if - sb.append("()"); - return sb.toString(); - default: - assert false : "invalid kind"; - return null; - } // end switch - } // end method 'toString()' - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return this.kind.hashCode() - + (this.flags != null ? this.flags.hashCode() : 0) - + (this.name != null ? this.name.hashCode() : 0) - + (this.returnType != null ? this.returnType.hashCode() : 0) - + (this.parameterTypes != null ? this.parameterTypes.hashCode() : 0) - + (this.attributes.hashCode()) - + (this.strict ? 1 : 0); - } // end method 'hashCode()' - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object obj) { - if (obj instanceof Method) { - final Method that = (Method) obj; - return this.kind.equals(that.kind) - && API.nullOrEquals(this.flags, that.flags) - && API.nullOrEquals(this.name, that.name) - && API.nullOrEquals(this.returnType, that.returnType) - && API.nullOrEquals(this.parameterTypes, that.parameterTypes) - && this.attributes.equals(that.attributes) - && (this.strict == that.strict); - } else { - return false; - } // end if/else - } // end method 'equals(Object)' - -} // end class 'Method' rmfile ./api/src/fr/x9c/barista/api/Method.java hunk ./api/src/fr/x9c/barista/api/Printer.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import fr.x9c.cadmium.kernel.Block; -import fr.x9c.cadmium.kernel.Channel; -import fr.x9c.cadmium.kernel.Custom; -import fr.x9c.cadmium.kernel.Value; - -/** - * This class provides methods for class pretty-printing. - * - * @author Xavier Clerc - * @version 1.0 - * @since 1.0 - */ -public final class Printer { - - /** - * No instance of this class. - */ - private Printer() { - } // end empty constructor - - /** - * Calls the callback to print a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while printing - */ - private static void callPrint(final String name, - final ClassPath cp, - final OutputStream out) - throws BaristaException { - assert name != null : "null name"; - assert cp != null : "null cp"; - assert out != null : "null out"; - final Value n = API.createUTF8(name); - final Value c = cp.toValue(); - final Block b = Block.createCustom(Custom.CHANNEL_SIZE, - Custom.CHANNEL_OPS); - b.setCustom(new Channel(out)); - final Value o = Value.createFromBlock(b); - API.callback("fr.x9c.barista.api.Printer.print", n, c, o); - } // end method 'callPrint(String, ClassPath, OutputStream)' - - /** - * Pretty-prints a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while printing - */ - public static void print(final String name, - final ClassPath cp, - final OutputStream out) - throws BaristaException { - callPrint(name, cp, out); - } // end method 'print(String, ClassPath, OutputStream)' - - /** - * Pretty-prints a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @param out where to output class description - should not be null - * @throws BaristaException if an errors occurs while printing - */ - public static void print(final String name, - final ClassPath cp, - final Appendable out) - throws BaristaException { - try { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - callPrint(name, cp, baos); - out.append(baos.toString("UTF-8")); - } catch (final UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } catch (final IOException ioe) { - throw new BaristaException("I/O error", ioe); - } // and try/catch - } // end method 'print(String, ClassPath, Appendable)' - - /** - * Pretty-prints a class. - * @param name class name - should not be null - * @param cp classpath for class loading - should not be null - * @return a string representation of the class - * @throws BaristaException if an errors occurs while printing - */ - public static String print(final String name, final ClassPath cp) - throws BaristaException { - try { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - callPrint(name, cp, baos); - return baos.toString("UTF-8"); - } catch (java.io.UnsupportedEncodingException uee) { - throw new BaristaException("UTF8 unsupported by Java platform"); - } // and try/catch - } // end method 'print(String, ClassPath)' - -} // end class 'Printer' rmfile ./api/src/fr/x9c/barista/api/Printer.java hunk ./api/src/fr/x9c/barista/api/Version.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package fr.x9c.barista.api; - -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import fr.x9c.cadmium.kernel.Value; -import fr.x9c.cadmium.primitives.stdlib.Hash; -import fr.x9c.cadmium.support.values.ToValue; - -/** - * This class represents a version of the Java class file format. - * - * @author Xavier Clerc - * @version 1.3 - * @since 1.3 - */ -public enum Version implements ToValue { - - /** JDK 1.0 (circa 1996). */ - Java_1_0, - - /** JDK 1.1 (circa 1997). */ - Java_1_1, - - /** J2SE 1.2 (circa 1998). */ - Java_1_2, - - /** J2SE 1.3 (circa 2000). */ - Java_1_3, - - /** J2SE 1.4 (circa 2002). */ - Java_1_4, - - /** J2SE 5.0 (circa 2004). */ - Java_1_5, - - /** Java SE 6 (circa 2006). */ - Java_1_6, - - /** Java SE 7 (to be released). */ - Java_1_7; - - /** - * {@inheritDoc} - */ - public Value toValue() { - switch (this) { - case Java_1_0: return Value.ZERO; - case Java_1_1: return Value.ONE; - case Java_1_2: return Value.TWO; - case Java_1_3: return Value.createFromLong(3); - case Java_1_4: return Value.createFromLong(4); - case Java_1_5: return Value.createFromLong(5); - case Java_1_6: return Value.createFromLong(6); - case Java_1_7: return Value.createFromLong(7); - default: - assert false : "invalid version"; - return Value.ZERO; - } // end switch - } // end method 'toValue()' - - /** - * Constructs an instance from a value. - * @param v value to construct instance from - should not be null - * @return the corresponding instance - */ - static Version fromValue(final Value v) { - assert v != null : "null v"; - switch (v.asLong()) { - case 0: return Java_1_0; - case 1: return Java_1_1; - case 2: return Java_1_2; - case 3: return Java_1_3; - case 4: return Java_1_4; - case 5: return Java_1_5; - case 6: return Java_1_6; - case 7: return Java_1_7; - default: - assert false : "invalid version"; - return null; - } // end switch - } // end method 'fromValue(Value)' - - /** - * Constructs an instance from a string. - * @param s string to construct instance from - should not be null - * @return the corresponding instance, null if the string does - * not represent a valid version - */ - static Version fromString(final String s) { - assert s != null : "null s"; - if (s.equals("1.0")) { - return Java_1_0; - } else if (s.equals("1.1")) { - return Java_1_1; - } else if (s.equals("1.2")) { - return Java_1_2; - } else if (s.equals("1.3")) { - return Java_1_3; - } else if (s.equals("1.4")) { - return Java_1_4; - } else if (s.equals("1.5")) { - return Java_1_5; - } else if (s.equals("1.6")) { - return Java_1_6; - } else if (s.equals("1.7")) { - return Java_1_7; - } else { - return null; - } // end if/elsif/else - } // end method 'fromString(String)' - -} // end class 'Version' rmfile ./api/src/fr/x9c/barista/api/Version.java hunk ./api/src/fr/x9c/barista/api/package-info.java 1 -/* - * This file is part of Barista. - * Copyright (C) 2007-2010 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ hunk ./api/src/fr/x9c/barista/api/package-info.java 2 -/** - * This package contains the classes allowing to use the Barista library - * from the Java language. Barista is implemented using the - * Objective Caml language. - * Nevertheless, when compiled using - * Cafesterol, - * a Java binary version is produced that can be used via the API presented - * in these Javadoc files. - */ -package fr.x9c.barista.api; rmfile ./api/src/fr/x9c/barista/api/package-info.java rmdir ./api/src/fr/x9c/barista/api rmdir ./api/src/fr/x9c/barista rmdir ./api/src/fr/x9c rmdir ./api/src/fr rmdir ./api/src rmdir ./api rmdir ./lib rmdir ./report/html rmdir ./report/out rmdir ./report hunk ./build.properties 1 -# -# This file is part of Barista. -# Copyright (C) 2007-2011 Xavier Clerc. -# -# Barista is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Barista is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program. If not, see . -# - -# Paths -path.api=${basedir}/api -path.cadmiumdoc=${basedir}/../Cadmium/javadoc/public -path.classes=${path.api}/classes -path.javadoc=${basedir}/javadoc -path.javadoc-dev=${path.javadoc}/dev -path.javadoc-public=${path.javadoc}/public -path.jdkdoc=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Resources/Documentation/Reference/doc/api -path.lib=${basedir}/lib -path.ocaml=/usr/local/lib/ocaml -path.src=${path.api}/src - -# Packages -packages=fr.x9c.barista.api - -# Project properties -project.name=Barista -project.version=1.4 -project.author=Xavier Clerc -project.copyright=Copyright (c) 2007-2011, Xavier Clerc -project.overview=${basedir}/javadoc/overview.html -project.jarfile=${path.api}/barista-api.jar -project.java-version=1.6 rmfile ./build.properties hunk ./build.xml 1 - - - - - - - - Barista: Java [dis]assembler - Author: Xavier Clerc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rmfile ./build.xml hunk ./src/helpers/api.ml 1 -(* - * This file is part of Barista. - * Copyright (C) 2007-2011 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - *) - -let is_barista_exception = function - | AccessFlag.Exception _ - | Annotation.Exception _ - | Assembler.Exception _ - | Attribute.Exception _ - | ByteCode.Exception _ - | ClassDefinition.Exception _ - | ClassFile.Exception _ - | ClassLoader.Exception _ - | ClassPath.Exception _ - | ConstantPool.Exception _ - | ControlFlow.Exception _ - | Descriptor.Exception _ - | Field.Exception _ - | InputStream.Exception _ - | Instruction.Exception _ - | Lexer.Exception _ - | Method.Exception _ - | ModuleDefinition.Exception _ - | Name.Exception _ - | OutputStream.Exception _ - | PackageDefinition.Exception _ - | Serialization.Exception _ - | Signature.Exception _ - | Source.Exception _ - | StackState.Exception _ - | Utils.UChar.Exception _ - | Utils.UTF8.Exception _ - | Utils.Lexer_state_exception _ - | JavaVersion.Exception _ -> true - | _ -> false - -let string_of_exception = function - | AccessFlag.Exception e -> AccessFlag.string_of_error e - | Annotation.Exception e -> Annotation.string_of_error e - | Assembler.Exception (l, e) -> Printf.sprintf "%d: %s" l (Assembler.string_of_error e) - | Attribute.Exception e -> Attribute.string_of_error e - | ByteCode.Exception e -> ByteCode.string_of_error e - | ClassDefinition.Exception e -> ClassDefinition.string_of_error e - | ClassFile.Exception e -> ClassFile.string_of_error e - | ClassLoader.Exception e -> ClassLoader.string_of_error e - | ClassPath.Exception e -> ClassPath.string_of_error e - | ConstantPool.Exception e -> ConstantPool.string_of_error e - | ControlFlow.Exception e -> ControlFlow.string_of_error e - | Descriptor.Exception e -> Descriptor.string_of_error e - | Field.Exception e -> Field.string_of_error e - | InputStream.Exception e -> InputStream.string_of_error e - | Instruction.Exception e -> Instruction.string_of_error e - | Lexer.Exception e -> Lexer.string_of_error e - | Method.Exception e -> Method.string_of_error e - | ModuleDefinition.Exception e -> ModuleDefinition.string_of_error e - | Name.Exception e -> Name.string_of_error e - | OutputStream.Exception e -> OutputStream.string_of_error e - | PackageDefinition.Exception e -> PackageDefinition.string_of_error e - | Serialization.Exception e -> Serialization.string_of_error e - | Signature.Exception e -> Signature.string_of_error e - | Source.Exception e -> Source.string_of_error e - | StackState.Exception e -> StackState.string_of_error e - | Utils.UChar.Exception e -> Utils.UChar.string_of_error e - | Utils.UTF8.Exception e -> Utils.UTF8.string_of_error e - | Utils.Lexer_state_exception e -> Utils.string_of_lexer_state_error e - | JavaVersion.Exception e -> JavaVersion.string_of_error e - | e -> Printexc.to_string e - -let register_callbacks () = - let reg = Callback.register in - let reg1 n f = - Callback.register - n - (fun x -> try f x with e -> failwith (string_of_exception e)) in - reg1 "fr.x9c.barista.api.Name.make_class" Name.make_for_class_from_external; - reg1 "fr.x9c.barista.api.Name.make_field" Name.make_for_field; - reg1 "fr.x9c.barista.api.Name.make_method" Name.make_for_method; - reg1 "fr.x9c.barista.api.Name.utf8_of_class" Name.external_utf8_for_class; - reg1 "fr.x9c.barista.api.Name.utf8_of_field" Name.utf8_for_field; - reg1 "fr.x9c.barista.api.Name.utf8_of_method" Name.utf8_for_method; - reg1 "fr.x9c.barista.api.Signature.make_field" Signature.field_type_signature_of_utf8; - reg1 "fr.x9c.barista.api.Signature.utf8_of_field_signature" Signature.utf8_of_field_type_signature; - reg1 "fr.x9c.barista.api.Signature.make_method" Signature.method_signature_of_utf8; - reg1 "fr.x9c.barista.api.Signature.utf8_of_method_signature" Signature.utf8_of_method_signature; - reg1 "fr.x9c.barista.api.Signature.make_class" Signature.class_signature_of_utf8; - reg1 "fr.x9c.barista.api.Signature.utf8_of_class_signature" Signature.utf8_of_class_signature; - reg "fr.x9c.barista.api.Printer.print" - (fun n c o -> - try - Printer.print_to_channel o (ClassPath.make_of_string c) n - with e -> failwith (string_of_exception e)); - reg "fr.x9c.barista.api.Disassembler.disassemble" - (fun n c o -> - try - Disassembler.disassemble_to_channel o (ClassPath.make_of_string c) n - with e -> failwith (string_of_exception e)); - reg "fr.x9c.barista.api.Assembler.assemble" - (fun v s p c i o -> - try - Name.external_utf8_for_class - (Assembler.assemble - ~version:v - ~compute_stacks:s - ~optimize:p - ~class_loader:(ClassLoader.make (ClassPath.make_of_string c)) - i - o) - with e -> failwith (string_of_exception e)); - reg "fr.x9c.barista.api.ClassDefinition.encode" - (fun v cd -> - try - let buff = Buffer.create 256 in - let os = OutputStream.make_of_buffer buff in - ClassFile.write (ClassDefinition.encode ~version:v cd) os; - OutputStream.close os; - Buffer.contents buff - with e -> failwith (string_of_exception e)); - reg "fr.x9c.barista.api.ClassDefinition.decode" - (fun ic -> - try - let is = InputStream.make_of_channel ic in - ClassDefinition.decode (ClassFile.read is) - with e -> failwith (string_of_exception e)) rmfile ./src/helpers/api.ml hunk ./src/helpers/api.mli 1 -(* - * This file is part of Barista. - * Copyright (C) 2007-2011 Xavier Clerc. - * - * Barista is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Barista is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - *) - -(** This module provides a function registering the callbacks to be used by - the Java API. *) - -val is_barista_exception : exn -> bool -(** Tests whether the passed exception is a Barista one. *) - -val string_of_exception : exn -> string -(** Converts the passed exception into a string, resorting to - [Printexc.to_sring] if the passed exception is not a Barista one. *) - -val register_callbacks : unit -> unit -(** Registers the callbacks to be used by the Java API. *) rmfile ./src/helpers/api.mli }