Example usage for org.eclipse.jdt.core Signature C_SEMICOLON

List of usage examples for org.eclipse.jdt.core Signature C_SEMICOLON

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Signature C_SEMICOLON.

Prototype

char C_SEMICOLON

To view the source code for org.eclipse.jdt.core Signature C_SEMICOLON.

Click Source Link

Document

Character constant indicating the semicolon in a signature.

Usage

From source file:at.bestsolution.fxide.jdt.editor.internal.SignatureUtil.java

License:Open Source License

private static int typeEnd(char[] signature, int pos) {
    int depth = 0;
    while (pos < signature.length) {
        switch (signature[pos]) {
        case Signature.C_GENERIC_START:
            depth++;/*from   w  w w .  j  ava 2 s  .  c  om*/
            break;
        case Signature.C_GENERIC_END:
            if (depth == 0)
                return pos;
            depth--;
            break;
        case Signature.C_SEMICOLON:
            if (depth == 0)
                return pos + 1;
            break;
        }
        pos++;
    }
    return pos + 1;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * Converts a type binding into a parameter-style binding Please see JVM
 * Specification 4.3.2//from www  . java2  s . co  m
 * {@link http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#84645}
 * .
 * 
 * @param pBinding
 *            The binding to convert. Cannot be null.
 * @return A class element representing this binding. Cannot be null.
 */
private static IElement convertParameterTypeBinding(final ITypeBinding pBinding) {
    ASTCrawler.checkForNull(pBinding);
    if (pBinding.getDimensions() == 0 && !pBinding.isPrimitive())
        return FlyweightElementFactory.getElement(Category.CLASS,
                Signature.C_RESOLVED + pBinding.getBinaryName() + Signature.C_SEMICOLON);
    else
        return FlyweightElementFactory.getElement(Category.CLASS, pBinding.getBinaryName());
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java

License:Open Source License

private static void appendClassTypeSignature(char[] string, int start, StringBuffer buffer, boolean compact) {
    char c = string[start];
    if (c != Signature.C_RESOLVED) {
        return;// w w  w  .j  a va  2  s  .  c  o  m
    }
    int p = start + 1;
    int checkpoint = buffer.length();
    while (true) {
        c = string[p];
        switch (c) {
        case Signature.C_SEMICOLON:
            // all done
            return;
        case Signature.C_DOT:
        case '/':
            // erase package prefix
            if (compact) {
                buffer.setLength(checkpoint);
            } else {
                buffer.append('.');
            }
            break;
        case Signature.C_DOLLAR:
            /**
             * Convert '$' in resolved type signatures into '.'. NOTE: This assumes that the type signature is an inner type
             * signature. This is true in most cases, but someone can define a non-inner type name containing a '$'.
             */
            buffer.append('.');
            break;
        default:
            buffer.append(c);
        }
        p++;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java

License:Open Source License

/**
 * Split signatures of all levels from a type unique key.
 * <p/>/* ww  w.j  a v  a 2 s.c  o m*/
 * Example: For following type X<Y<Z>,V<W>,U>.A<B>, unique key is: "LX<LY<LZ;>;LV<LW;>;LU;>.LA<LB;>;"
 * <p/>
 * The return splitted signatures array is: [ ['L','X','<','L','Y','<','L','Z'
 * ,';'>',';','L','V','<','L','W',';'>',';','L','U','>',';'], ['L','A','<','L','B',';','>',';']
 *
 * @param typeSignature
 *         ParameterizedSourceType type signature
 * @return char[][] Array of signatures for each level of given unique key
 */
public final static char[][] splitTypeLevelsSignature(String typeSignature) {
    // In case of IJavaElement signature, replace '$' by '.'
    char[] source = Signature.removeCapture(typeSignature.toCharArray());
    CharOperation.replace(source, '$', '.');

    // Init counters and arrays
    char[][] signatures = new char[10][];
    int signaturesCount = 0;
    // int[] lengthes = new int [10];
    int paramOpening = 0;

    // Scan each signature character
    for (int idx = 0, ln = source.length; idx < ln; idx++) {
        switch (source[idx]) {
        case '>':
            paramOpening--;
            if (paramOpening == 0) {
                if (signaturesCount == signatures.length) {
                    System.arraycopy(signatures, 0, signatures = new char[signaturesCount + 10][], 0,
                            signaturesCount);
                }
            }
            break;
        case '<':
            paramOpening++;
            break;
        case '.':
            if (paramOpening == 0) {
                if (signaturesCount == signatures.length) {
                    System.arraycopy(signatures, 0, signatures = new char[signaturesCount + 10][], 0,
                            signaturesCount);
                }
                signatures[signaturesCount] = new char[idx + 1];
                System.arraycopy(source, 0, signatures[signaturesCount], 0, idx);
                signatures[signaturesCount][idx] = Signature.C_SEMICOLON;
                signaturesCount++;
            }
            break;
        case '/':
            source[idx] = '.';
            break;
        }
    }

    // Resize signatures array
    char[][] typeSignatures = new char[signaturesCount + 1][];
    typeSignatures[0] = source;
    for (int i = 1, j = signaturesCount - 1; i <= signaturesCount; i++, j--)//NOSONAR
    {
        typeSignatures[i] = signatures[j];
    }
    return typeSignatures;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java

License:Open Source License

private static int appendClassTypeSignatureForAnchor(char[] string, int start, StringBuffer buffer) {
    // need a minimum 3 chars "Lx;"
    if (start >= string.length - 2) {
        throw new IllegalArgumentException();
    }/*from  ww  w. j a  va  2 s . c om*/
    // must start in "L" or "Q"
    char c = string[start];
    if (c != Signature.C_RESOLVED && c != Signature.C_UNRESOLVED) {
        throw new IllegalArgumentException();
    }
    int p = start + 1;
    while (true) {
        if (p >= string.length) {
            throw new IllegalArgumentException();
        }
        c = string[p];
        switch (c) {
        case Signature.C_SEMICOLON:
            // all done
            return p;
        case Signature.C_GENERIC_START:
            int e = scanGenericEnd(string, p + 1);
            // once we hit type arguments there are no more package prefixes
            p = e;
            break;
        case Signature.C_DOT:
            buffer.append('.');
            break;
        case '/':
            buffer.append('/');
            break;
        case Signature.C_DOLLAR:
            // once we hit "$" there are no more package prefixes
            /**
             * Convert '$' in resolved type signatures into '.'. NOTE: This assumes that the type signature is an inner type
             * signature. This is true in most cases, but someone can define a non-inner type name containing a '$'.
             */
            buffer.append('.');
            break;
        default:
            buffer.append(c);
        }
        p++;
    }
}

From source file:com.drgarbage.core.ActionUtils.java

License:Apache License

/**
 * Resolves a type name in the context of the declaring type.
 * /* w  w  w.j  a va  2 s.  c  o m*/
 * @param refTypeSig the type name in signature notation (for example 'QVector') this can also be an array type, but dimensions will be ignored.
 * @param declaringType the context for resolving (type where the reference was made in)
 * @return returns the fully qualified type name or build-in-type name. if a unresolved type couldn't be resolved null is returned
 */
public static String getResolvedTypeName(String refTypeSig, IType declaringType)
        throws JavaModelException, IllegalArgumentException {
    int arrayCount = Signature.getArrayCount(refTypeSig);

    /*
     * use the last element for resolving the type
     * For example: QString [QString or [[QString
     * The last element is always 'Q'
     */
    char type = refTypeSig.charAt(arrayCount);
    if (type == Signature.C_UNRESOLVED) {
        String name = ""; //$NON-NLS-1$
        int bracket = refTypeSig.indexOf(Signature.C_GENERIC_START, arrayCount + 1);
        if (bracket > 0)
            name = refTypeSig.substring(arrayCount + 1, bracket);
        else {
            int semi = refTypeSig.indexOf(Signature.C_SEMICOLON, arrayCount + 1);
            if (semi == -1) {
                throw new IllegalArgumentException();
            }
            name = refTypeSig.substring(arrayCount + 1, semi);
        }
        String[][] resolvedNames = declaringType.resolveType(name);
        if (resolvedNames != null && resolvedNames.length > 0) {
            StringBuffer res = new StringBuffer();
            for (int i = 0; i < arrayCount; i++) {
                res.append('[');
            }
            res.append(concatenateName(resolvedNames[0][0], resolvedNames[0][1]));
            return res.toString();
        }
        throw new IllegalArgumentException();
    } else {
        return refTypeSig;
    }
}

From source file:com.mountainminds.eclemma.internal.core.analysis.SignatureResolver.java

License:Open Source License

private static final boolean resolveType(final IType scope, final String identifier, final StringBuffer result)
        throws JavaModelException {
    final String[][] types = scope.resolveType(Signature.getTypeErasure(identifier));
    if (types == null || types.length != 1) {
        return false;
    }/*  w w w  .  j a  va 2  s  .  c o m*/
    result.append(Signature.C_RESOLVED);
    final String qualifier = types[0][0];
    if (qualifier.length() > 0) {
        replace(qualifier, Signature.C_DOT, SLASH, result);
        result.append(SLASH);
    }
    replace(types[0][1], Signature.C_DOT, Signature.C_DOLLAR, result);
    result.append(Signature.C_SEMICOLON);
    return true;
}

From source file:de.gebit.integrity.ui.utils.IntegrityDSLUIUtil.java

License:Open Source License

/**
 * Determines the fully qualified class name from a type signature and a type where that type signature is declared.
 * /*w  ww. j  a v  a2s. co m*/
 * @param aTypeSignature
 *            the type signature
 * @param aDeclaringType
 *            the type in which the type signature was found
 * @return the fully qualified class name, packaged up with generics parameter information
 * @throws JavaModelException
 */
public static ResolvedTypeName getResolvedTypeName(String aTypeSignature, IType aDeclaringType)
        throws JavaModelException {
    int tempArrayCount = Signature.getArrayCount(aTypeSignature);
    char tempType = aTypeSignature.charAt(tempArrayCount);
    if (tempType == Signature.C_UNRESOLVED) {
        String tempName = "";
        int tempBracketOpenPosition = aTypeSignature.indexOf(Signature.C_GENERIC_START, tempArrayCount + 1);
        if (tempBracketOpenPosition > 0) {
            tempName = aTypeSignature.substring(tempArrayCount + 1, tempBracketOpenPosition);
        } else {
            int tempSemicolonPosition = aTypeSignature.indexOf(Signature.C_SEMICOLON, tempArrayCount + 1);
            if (tempSemicolonPosition == -1) {
                throw new IllegalArgumentException();
            }
            tempName = aTypeSignature.substring(tempArrayCount + 1, tempSemicolonPosition);
        }
        String[][] tempResolvedNames = aDeclaringType.resolveType(tempName);
        if (tempResolvedNames != null && tempResolvedNames.length > 0) {
            StringBuffer tempBuffer = new StringBuffer();
            if (tempResolvedNames[0][0] != null && tempResolvedNames[0][0].length() > 0) {
                tempBuffer.append(tempResolvedNames[0][0]);
            }
            if (tempResolvedNames[0][1] != null && tempResolvedNames[0][1].length() > 0) {
                if (tempBuffer.length() > 0) {
                    tempBuffer.append('.');
                }
                tempBuffer.append(tempResolvedNames[0][1]);
            }
            String tempRawTypeName = tempBuffer.toString();

            // Now on to the generic parameters
            if (tempBracketOpenPosition > 0) {
                int tempBracketClosePosition = aTypeSignature.lastIndexOf(Signature.C_GENERIC_END);
                if (tempBracketClosePosition == -1) {
                    throw new IllegalArgumentException();
                }

                String tempParameterNamesSignature = aTypeSignature.substring(tempBracketOpenPosition + 1,
                        tempBracketClosePosition);

                // This one must be splitted now
                List<String> tempParameterNameSignatures = new ArrayList<String>();
                int tempGenericStackSize = 0;
                int tempStart = 0;
                for (int i = 0; i < tempParameterNamesSignature.length(); i++) {
                    char tempChar = tempParameterNamesSignature.charAt(i);
                    if (tempChar == Signature.C_GENERIC_START) {
                        tempGenericStackSize++;
                    } else if (tempChar == Signature.C_GENERIC_END) {
                        tempGenericStackSize--;
                    } else if (tempChar == Signature.C_SEMICOLON) {
                        if (tempGenericStackSize == 0) {
                            // this is a valid splitting point
                            tempParameterNameSignatures
                                    .add(tempParameterNamesSignature.substring(tempStart, i + 1));
                            tempStart = i + 1;
                        }
                    }
                }

                ResolvedTypeName[] tempGenericParameterTypes = new ResolvedTypeName[tempParameterNameSignatures
                        .size()];
                for (int i = 0; i < tempParameterNameSignatures.size(); i++) {
                    tempGenericParameterTypes[i] = getResolvedTypeName(tempParameterNameSignatures.get(i),
                            aDeclaringType);
                }

                return new ResolvedTypeName(tempRawTypeName, tempGenericParameterTypes);
            } else {
                return new ResolvedTypeName(tempRawTypeName);
            }
        }
        return null;
    } else {
        return new ResolvedTypeName(
                Signature.toString(aTypeSignature.substring(tempArrayCount)).replace('/', '.'));
    }
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param type//from w w w .j av a  2 s .c o  m
 * @return full qualified, resolved type name in bytecode notation
 */
private static String getTypeSignature(IType type) {
    if (type == null) {
        return null;
    }
    /*
     * getFullyQualifiedName() returns name, where package separator is '.',
     * but we need '/' for bytecode. The hack with ',' is to use a character
     * which is not allowed as Java char to be sure not to replace too much
     */
    String name = type.getFullyQualifiedName(',');
    // replace package separators
    name = name.replace(Signature.C_DOT, PACKAGE_SEPARATOR);
    // replace class separators
    name = name.replace(',', TYPE_SEPARATOR);
    return Signature.C_RESOLVED + name + Signature.C_SEMICOLON;
}

From source file:de.loskutov.bco.ui.JdtUtils.java

License:Open Source License

/**
 * @param typeToResolve//  w w  w .j  a  v a  2s  .  c om
 * @param declaringType
 * @return full qualified "bytecode formatted" type
 * @throws JavaModelException
 */
private static String getResolvedType(String typeToResolve, IType declaringType) throws JavaModelException {
    StringBuffer sb = new StringBuffer();
    int arrayCount = Signature.getArrayCount(typeToResolve);
    // test which letter is following - Q or L are for reference types
    boolean isPrimitive = isPrimitiveType(typeToResolve.charAt(arrayCount));
    if (isPrimitive) {
        // simply add whole string (probably with array chars like [[I etc.)
        sb.append(typeToResolve);
    } else {
        boolean isUnresolvedType = isUnresolvedType(typeToResolve, arrayCount);
        if (!isUnresolvedType) {
            sb.append(typeToResolve);
        } else {
            // we need resolved types
            String resolved = getResolvedTypeName(typeToResolve, declaringType);
            if (resolved != null) {
                while (arrayCount > 0) {
                    sb.append(Signature.C_ARRAY);
                    arrayCount--;
                }
                sb.append(Signature.C_RESOLVED);
                sb.append(resolved);
                sb.append(Signature.C_SEMICOLON);
            }
        }
    }
    return sb.toString();
}