All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.codeAnalysis.decode.cp.CpUtf8 Maven / Gradle / Ivy

There is a newer version: 2.0-BETA
Show newest version
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.codeAnalysis.decode.cp;
import java.io.*;
import java.util.*;

public class CpUtf8 extends Cp {
    private StringBuffer value;
    private String stringValue;
    private Vector classes;

    CpUtf8( DataInputStream source ) throws IOException {
        int len = source.readUnsignedShort();
        int idx;
        value = new StringBuffer();

        for (idx=0; idx= 0)
                idx = decodeNextClassName(idx);
        }
        if (argNo == 0)
            return (String)classes.elementAt(classes.size()-1);
        else
            return (String)classes.elementAt(argNo-1);
    }

    private int decodeNextClassName(int startIdx) {
        int idx, len;
        StringBuffer str;
        StringBuffer arraySpec = new StringBuffer();

        idx = startIdx;
        len = value.length();
        if (idx >= len)
            return -1;

        while (value.charAt(idx) == ')' || value.charAt(idx) == '(')
            idx++;

        arraySpec = new StringBuffer();

        while (value.charAt(idx) == '[') {
            idx++;
            arraySpec.append("[]");
        }

        switch(value.charAt(idx)) {
            case 'B':
                str = new StringBuffer("byte");
                break;
            case 'C':
                str = new StringBuffer("char");
                break;
            case 'D':
                str = new StringBuffer("double");
                break;
            case 'F':
                str = new StringBuffer("float");
                break;
            case 'I':
                str = new StringBuffer("int");
                break;
            case 'J':
                str = new StringBuffer("long");
                break;
            case 'L':
                idx += 1;
                str = new StringBuffer();
                while (value.charAt(idx) != ';') {
                    str.append(value.charAt(idx));
                    idx += 1;
                }
                break;
            case 'S':
                str = new StringBuffer("short");
                break;
            case 'Z':
                str = new StringBuffer("boolean");
                break;
            case 'V':
                str = new StringBuffer("void");
                break;
            default:
                throw new Error("Unknown type specifier in descriptor: " + value.charAt(idx));
        }
        str.append(arraySpec);
        classes.addElement(str.toString());
        return idx + 1;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy