List of usage examples for org.eclipse.jdt.core Signature C_UNRESOLVED
char C_UNRESOLVED
To view the source code for org.eclipse.jdt.core Signature C_UNRESOLVED.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private StringBuffer internalGetSubstitutedTypeName(String typeSig, IMember context, boolean erasure, StringBuffer buf) throws JavaModelException { int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: return buf.append(Signature.toString(typeSig)); case Signature.ARRAY_TYPE_SIGNATURE: internalGetSubstitutedTypeName(Signature.getElementType(typeSig), context, erasure, buf); for (int i = Signature.getArrayCount(typeSig); i > 0; i--) { buf.append('[').append(']'); }/* w ww . ja va 2s . co m*/ return buf; case Signature.CLASS_TYPE_SIGNATURE: { String erasureSig = Signature.getTypeErasure(typeSig); String erasureName = Signature.getSimpleName(Signature.toString(erasureSig)); char ch = erasureSig.charAt(0); if (ch == Signature.C_RESOLVED) { buf.append(erasureName); } else if (ch == Signature.C_UNRESOLVED) { // could be a type variable if (erasure) { buf.append(getVariableErasure(context, erasureName)); } else { buf.append(getVariableSubstitution(context, erasureName)); } } else { Assert.isTrue(false, "Unknown class type signature"); //$NON-NLS-1$ } if (!erasure) { String[] typeArguments = Signature.getTypeArguments(typeSig); if (typeArguments.length > 0) { buf.append('<'); for (int i = 0; i < typeArguments.length; i++) { if (i > 0) { buf.append(','); } internalGetSubstitutedTypeName(typeArguments[i], context, erasure, buf); } buf.append('>'); } } return buf; } case Signature.TYPE_VARIABLE_SIGNATURE: String varName = Signature.toString(typeSig); if (erasure) { return buf.append(getVariableErasure(context, varName)); } else { return buf.append(getVariableSubstitution(context, varName)); } case Signature.WILDCARD_TYPE_SIGNATURE: { buf.append('?'); char ch = typeSig.charAt(0); if (ch == Signature.C_STAR) { return buf; } else if (ch == Signature.C_EXTENDS) { buf.append(" extends "); //$NON-NLS-1$ } else { buf.append(" super "); //$NON-NLS-1$ } return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); } case Signature.CAPTURE_TYPE_SIGNATURE: return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); default: Assert.isTrue(false, "Unhandled type signature kind"); //$NON-NLS-1$ return buf; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
/** * NOT API, public only for access by Unit tests. * Converts these type names to unqualified signatures. This needs to be done in order to be consistent * with the way the source range is retrieved. * * @see org.eclipse.jdt.internal.core.SourceMapper#getUnqualifiedMethodHandle * @see org.eclipse.jdt.core.Signature//from ww w . ja va 2 s. c om */ public String[] convertTypeNamesToSigs(char[][] typeNames) { if (typeNames == null) return CharOperation.NO_STRINGS; int n = typeNames.length; if (n == 0) return CharOperation.NO_STRINGS; String[] typeSigs = new String[n]; for (int i = 0; i < n; ++i) { char[] typeSig = Signature.createCharArrayTypeSignature(typeNames[i], false); // transforms signatures that contains a qualification into unqualified signatures // e.g. "QX<+QMap.Entry;>;" becomes "QX<+QEntry;>;" StringBuffer simpleTypeSig = null; int start = 0; int dot = -1; int length = typeSig.length; for (int j = 0; j < length; j++) { switch (typeSig[j]) { case Signature.C_UNRESOLVED: if (simpleTypeSig != null) simpleTypeSig.append(typeSig, start, j - start); start = j; break; case Signature.C_DOT: dot = j; break; case Signature.C_GENERIC_START: int matchingEnd = findMatchingGenericEnd(typeSig, j + 1); if (matchingEnd > 0 && matchingEnd + 1 < length && typeSig[matchingEnd + 1] == Signature.C_DOT) { // found Head<Param>.Tail -> discard everything except Tail if (simpleTypeSig == null) simpleTypeSig = new StringBuffer().append(typeSig, 0, start); simpleTypeSig.append(Signature.C_UNRESOLVED); start = j = matchingEnd + 2; break; } //$FALL-THROUGH$ case Signature.C_NAME_END: if (dot > start) { if (simpleTypeSig == null) simpleTypeSig = new StringBuffer().append(typeSig, 0, start); simpleTypeSig.append(Signature.C_UNRESOLVED); simpleTypeSig.append(typeSig, dot + 1, j - dot - 1); start = j; } break; } } if (simpleTypeSig == null) { typeSigs[i] = new String(typeSig); } else { simpleTypeSig.append(typeSig, start, length - start); typeSigs[i] = simpleTypeSig.toString(); } } return typeSigs; }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
private int getUnqualifiedTypeSignature(String qualifiedTypeSig, int start, int length, StringBuffer unqualifiedTypeSig, boolean noDollar) { char firstChar = qualifiedTypeSig.charAt(start); int end = start + 1; boolean sigStart = false; firstPass: for (int i = start; i < length; i++) { char current = qualifiedTypeSig.charAt(i); switch (current) { case Signature.C_ARRAY: case Signature.C_SUPER: case Signature.C_EXTENDS: unqualifiedTypeSig.append(current); start = i + 1;/*from w w w .jav a2 s. c o m*/ end = start + 1; firstChar = qualifiedTypeSig.charAt(start); break; case Signature.C_RESOLVED: case Signature.C_UNRESOLVED: case Signature.C_TYPE_VARIABLE: if (!sigStart) { start = ++i; sigStart = true; } break; case Signature.C_NAME_END: case Signature.C_GENERIC_START: end = i; break firstPass; case Signature.C_STAR: unqualifiedTypeSig.append(current); start = i + 1; end = start + 1; firstChar = qualifiedTypeSig.charAt(start); break; case Signature.C_GENERIC_END: return i; case Signature.C_DOT: start = ++i; break; case Signature.C_BOOLEAN: case Signature.C_BYTE: case Signature.C_CHAR: case Signature.C_DOUBLE: case Signature.C_FLOAT: case Signature.C_INT: case Signature.C_LONG: case Signature.C_SHORT: if (!sigStart) { unqualifiedTypeSig.append(current); return i + 1; } } } switch (firstChar) { case Signature.C_RESOLVED: case Signature.C_UNRESOLVED: case Signature.C_TYPE_VARIABLE: unqualifiedTypeSig.append(Signature.C_UNRESOLVED); if (noDollar) { int lastDollar = qualifiedTypeSig.lastIndexOf('$', end); if (lastDollar > start) start = lastDollar + 1; } for (int i = start; i < length; i++) { char current = qualifiedTypeSig.charAt(i); switch (current) { case Signature.C_GENERIC_START: unqualifiedTypeSig.append(current); i++; do { i = getUnqualifiedTypeSignature(qualifiedTypeSig, i, length, unqualifiedTypeSig, noDollar); } while (qualifiedTypeSig.charAt(i) != Signature.C_GENERIC_END); unqualifiedTypeSig.append(Signature.C_GENERIC_END); break; case Signature.C_NAME_END: unqualifiedTypeSig.append(current); return i + 1; default: unqualifiedTypeSig.append(current); break; } } return length; default: // primitive type or wildcard unqualifiedTypeSig.append(qualifiedTypeSig.substring(start, end)); return end; } }
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 w w w . j av a 2s . com*/ // 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. * //from w w w. j av a2 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.google.gdt.eclipse.core.java.JavaModelSearch.java
License:Open Source License
private static boolean methodSignaturesEqual(IType type2, String methodName, String[] paramTypes, boolean isConstructor, IMethod method2) { try {// w w w . j av a 2 s .c o m // Method names must match, unless we're comparing constructors if (!isConstructor && !method2.getElementName().equals(methodName)) { return false; } // Only compare ctors to ctors and methods to methods if (isConstructor != method2.isConstructor()) { return false; } // Parameter count must match String signature2 = method2.getSignature(); String[] paramTypes2 = Signature.getParameterTypes(signature2); if (paramTypes.length != paramTypes2.length) { return false; } // Compare each parameter type for (int i = 0; i < paramTypes.length; i++) { String paramType = paramTypes[i]; String paramType2 = paramTypes2[i]; // Compare array nesting depth ([] = 1, [][] = 2, etc.) if (Signature.getArrayCount(paramType) != Signature.getArrayCount(paramType2)) { return false; } // Remove any array nesting and generic type parameters paramType = getBaseType(paramType); paramType2 = getBaseType(paramType2); // Extract the full type names from the signatures String paramTypeName = getQualifiedTypeName(paramType); String paramTypeName2 = getQualifiedTypeName(paramType2); if (isTypeParameter(method2, paramTypeName2)) { // Skip parameters whose type is a generic type parameter of the // method we're comparing against, or the method's containing class continue; /* * TODO: we're currently not checking the bounds of generic type * parameters, so sometimes we may return true here even when the * caller's method signature doesn't match the method we're comparing * against. We could try to add that logic here, or better still, we * could integrate TypeOracle and take advantage of its type searching * capabilities. */ } // If we run into an unresolved parameter type in the method we're // searching, we'll need to resolve that before doing the comparison if (paramType2.charAt(0) == Signature.C_UNRESOLVED) { paramTypeName2 = resolveTypeName(type2, paramTypeName2); } // Finally, compare the type names if (!paramTypeName.equals(paramTypeName2)) { return false; } } // We passed all the checks, so the signatures are equal return true; } catch (JavaModelException e) { CorePluginLog.logError(e, "Error comparing method signatures of {0} and {1}", methodName, method2.getElementName()); return false; } }
From source file:com.mountainminds.eclemma.internal.core.analysis.SignatureResolver.java
License:Open Source License
private static final void resolveParameterType(final IMethod method, final String parameterType, final StringBuffer result) throws JavaModelException { final char kind = parameterType.charAt(0); switch (kind) { case Signature.C_UNRESOLVED: final String identifier = parameterType.substring(1, parameterType.length() - 1); if (resolveType(method.getDeclaringType(), identifier, result)) { return; }/* w w w .java 2s .co m*/ if (resolveTypeParameter(method, identifier, result)) { return; } break; } result.append(parameterType); }
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 w w . j av a2s . c o 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
private static void appendGenericType(StringBuffer sb, IMethod iMethod, String unresolvedType) throws JavaModelException { IType declaringType = iMethod.getDeclaringType(); // unresolvedType is here like "QA;" => we remove "Q" and ";" if (unresolvedType.length() < 3) { // ???? something wrong here .... sb.append(unresolvedType);//from w w w .j a v a 2s . com return; } unresolvedType = unresolvedType.substring(1, unresolvedType.length() - 1); ITypeParameter typeParameter = iMethod.getTypeParameter(unresolvedType); if (typeParameter == null || !typeParameter.exists()) { typeParameter = declaringType.getTypeParameter(unresolvedType); } String[] bounds = typeParameter.getBounds(); if (bounds.length == 0) { sb.append("Ljava/lang/Object;"); } else { for (int i = 0; i < bounds.length; i++) { String simplyName = bounds[i]; simplyName = Signature.C_UNRESOLVED + simplyName + Signature.C_NAME_END; String resolvedType = getResolvedType(simplyName, declaringType); sb.append(resolvedType); } } }
From source file:de.loskutov.bco.ui.JdtUtils.java
License:Open Source License
/** * @param refTypeSig//from w w w .j a va2 s.c o m * @param arrayCount expected array count in the signature * @return true if the given string is an unresolved signature (Eclipse - internal * representation) */ private static boolean isUnresolvedType(String refTypeSig, int arrayCount) { char type = refTypeSig.charAt(arrayCount); return type == Signature.C_UNRESOLVED; }