Example usage for org.eclipse.jdt.internal.core.util Util scanTypeSignature

List of usage examples for org.eclipse.jdt.internal.core.util Util scanTypeSignature

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Util scanTypeSignature.

Prototype

public static int scanTypeSignature(char[] string, int start) 

Source Link

Document

Scans the given string for a type signature starting at the given index and returns the index of the last character.

Usage

From source file:com.ibm.research.tours.content.url.Signature.java

License:Open Source License

/**
 * Returns the number of parameter types in the given method signature.
 *
 * @param methodSignature the method signature
 * @return the number of parameters//ww w  . ja v  a  2 s.  co  m
 * @exception IllegalArgumentException if the signature is not syntactically
 *   correct
 * @since 2.0
 */
public static int getParameterCount(char[] methodSignature) throws IllegalArgumentException {
    try {
        int count = 0;
        int i = CharOperation.indexOf(C_PARAM_START, methodSignature);
        if (i < 0) {
            throw new IllegalArgumentException();
        } else {
            i++;
        }
        for (;;) {
            if (methodSignature[i] == C_PARAM_END) {
                return count;
            }
            int e = Util.scanTypeSignature(methodSignature, i);
            if (e < 0) {
                throw new IllegalArgumentException();
            } else {
                i = e + 1;
            }
            count++;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new IllegalArgumentException();
    }
}

From source file:com.ibm.research.tours.content.url.Signature.java

License:Open Source License

/**
 * Extracts the parameter type signatures from the given method signature. 
 * The method signature is expected to be dot-based.
 *
 * @param methodSignature the method signature
 * @return the list of parameter type signatures
 * @exception IllegalArgumentException if the signature is syntactically
 *   incorrect/*from w  ww .ja  v  a2  s. c  om*/
 * 
 * @since 2.0
 */
public static char[][] getParameterTypes(char[] methodSignature) throws IllegalArgumentException {
    try {
        int count = getParameterCount(methodSignature);
        char[][] result = new char[count][];
        if (count == 0) {
            return result;
        }
        int i = CharOperation.indexOf(C_PARAM_START, methodSignature);
        if (i < 0) {
            throw new IllegalArgumentException();
        } else {
            i++;
        }
        int t = 0;
        for (;;) {
            if (methodSignature[i] == C_PARAM_END) {
                return result;
            }
            int e = Util.scanTypeSignature(methodSignature, i);
            if (e < 0) {
                throw new IllegalArgumentException();
            }
            result[t] = CharOperation.subarray(methodSignature, i, e + 1);
            t++;
            i = e + 1;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new IllegalArgumentException();
    }
}

From source file:com.ibm.research.tours.content.url.Signature.java

License:Open Source License

/**
 * Extracts the thrown exception type signatures from the given method signature if any
 * The method signature is expected to be dot-based.
 *
 * @param methodSignature the method signature
 * @return the list of thrown exception type signatures
 * @exception IllegalArgumentException if the signature is syntactically
 *   incorrect/*  w w w.  java  2 s .c o  m*/
 *
 * @since 3.1
 */
public static char[][] getThrownExceptionTypes(char[] methodSignature) throws IllegalArgumentException {
    // skip type parameters
    int exceptionStart = CharOperation.indexOf(C_EXCEPTION_START, methodSignature);
    if (exceptionStart == -1) {
        int paren = CharOperation.lastIndexOf(C_PARAM_END, methodSignature);
        if (paren == -1) {
            throw new IllegalArgumentException();
        }
        // ignore return type
        exceptionStart = Util.scanTypeSignature(methodSignature, paren + 1) + 1;
        int length = methodSignature.length;
        if (exceptionStart == length)
            return CharOperation.NO_CHAR_CHAR;
        throw new IllegalArgumentException();
    }
    int length = methodSignature.length;
    int i = exceptionStart;
    ArrayList exceptionList = new ArrayList(1);
    while (i < length) {
        if (methodSignature[i] == C_EXCEPTION_START) {
            exceptionStart++;
            i++;
        } else {
            throw new IllegalArgumentException();
        }
        i = Util.scanTypeSignature(methodSignature, i) + 1;
        exceptionList.add(CharOperation.subarray(methodSignature, exceptionStart, i));
        exceptionStart = i;
    }
    char[][] result;
    exceptionList.toArray(result = new char[exceptionList.size()][]);
    return result;
}

From source file:com.ibm.research.tours.content.url.Signature.java

License:Open Source License

/**
 * Extracts the return type from the given method signature. The method signature is 
 * expected to be dot-based.//  ww  w  .j  av  a 2s  .c  o m
 *
 * @param methodSignature the method signature
 * @return the type signature of the return type
 * @exception IllegalArgumentException if the signature is syntactically
 *   incorrect
 * 
 * @since 2.0
 */
public static char[] getReturnType(char[] methodSignature) throws IllegalArgumentException {
    // skip type parameters
    int paren = CharOperation.lastIndexOf(C_PARAM_END, methodSignature);
    if (paren == -1) {
        throw new IllegalArgumentException();
    }
    // there could be thrown exceptions behind, thus scan one type exactly
    int last = Util.scanTypeSignature(methodSignature, paren + 1);
    return CharOperation.subarray(methodSignature, paren + 1, last + 1);
}