本文整理汇总了Java中org.eclipse.jdt.core.Signature.getTypeArguments方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.getTypeArguments方法的具体用法?Java Signature.getTypeArguments怎么用?Java Signature.getTypeArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.Signature
的用法示例。
在下文中一共展示了Signature.getTypeArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeTypeVariables
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* The type and method signatures received in <code>CompletionProposals</code> of type <code>
* METHOD_REF</code> contain concrete type bounds. When comparing parameters of the signature with
* an <code>IMethod</code>, we have to make sure that we match the case where the formal method
* declaration uses a type variable which in the signature is already substituted with a concrete
* type (bound).
*
* <p>This method creates a map from type variable names to type signatures based on the position
* they appear in the type declaration. The type signatures are filtered through {@link
* SignatureUtil#getLowerBound(char[])}.
*
* @param type the type to get the variables from
* @return a map from type variables to concrete type signatures
* @throws org.eclipse.jdt.core.JavaModelException if accessing the java model fails
*/
private Map<String, char[]> computeTypeVariables(IType type) throws JavaModelException {
Map<String, char[]> map = new HashMap<String, char[]>();
char[] declarationSignature = fProposal.getDeclarationSignature();
if (declarationSignature == null) // array methods don't contain a declaration signature
return map;
char[][] concreteParameters = Signature.getTypeArguments(declarationSignature);
ITypeParameter[] typeParameters = type.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
String variable = typeParameters[i].getElementName();
if (concreteParameters.length > i)
// use lower bound since method equality is only parameter based
map.put(variable, SignatureUtil.getLowerBound(concreteParameters[i]));
else
// fProposal.getDeclarationSignature() is a raw type - use Object
map.put(variable, "Ljava.lang.Object;".toCharArray()); // $NON-NLS-1$
}
return map;
}
示例2: findMatchingTypeArgumentIndex
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
static int findMatchingTypeArgumentIndex(String signature, String argument) {
String[] typeArguments= Signature.getTypeArguments(signature);
for (int i= 0; i < typeArguments.length; i++) {
if (Signature.getSignatureSimpleName(typeArguments[i]).equals(argument)) {
return i;
}
}
return -1;
}
示例3: appendTypeParameterList
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Appends the type parameter list to <code>buffer</code>.
*
* @param buffer the buffer to append to
* @param typeProposal the type proposal
* @return the modified <code>buffer</code>
*/
private StringBuilder appendTypeParameterList(StringBuilder buffer, CompletionProposal typeProposal) {
// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
// gets fixed.
char[] signature= SignatureUtil.fix83600(typeProposal.getSignature());
char[][] typeParameters= Signature.getTypeArguments(signature);
for (int i= 0; i < typeParameters.length; i++) {
char[] param= typeParameters[i];
typeParameters[i]= Signature.toCharArray(param);
}
return appendParameterSignature(buffer, typeParameters, null);
}
示例4: getVariableSignatures
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Returns the type variable signatures of the specified parameterized type
* signature, or an empty array if none.
*
* @param signature
* the signature to get its type variable signatures from. The
* signature must be a parameterized type signature.
* @return a possibly empty array of type variable signatures
* @see Signature#getTypeArguments(String)
*/
private static String[] getVariableSignatures(final String signature) {
Assert.isNotNull(signature);
String[] result = null;
try {
result = Signature.getTypeArguments(signature);
} catch (IllegalArgumentException exception) {
result = new String[0];
}
return result;
}
开发者ID:ponder-lab,项目名称:Migrate-Skeletal-Implementation-to-Interface-Refactoring,代码行数:22,代码来源:TypeVariableUtil.java
示例5: appendTypeParameterList
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Appends the type parameter list to <code>buffer</code>.
*
* @param buffer the buffer to append to
* @param typeProposal the type proposal
* @return the modified <code>buffer</code>
* @since 3.2
*/
private StyledString appendTypeParameterList(
StyledString buffer, CompletionProposal typeProposal) {
// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
// gets fixed.
char[] signature = SignatureUtil.fix83600(typeProposal.getSignature());
char[][] typeParameters = Signature.getTypeArguments(signature);
for (int i = 0; i < typeParameters.length; i++) {
char[] param = typeParameters[i];
typeParameters[i] = Signature.toCharArray(param);
}
return appendParameterSignature(buffer, typeParameters, null);
}
示例6: getLowerBound
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Returns the lower bound of a type signature. Returns the null type signature if <code>signature
* </code> is a wildcard or upper bound (<code>? extends T</code>); returns the signature of the
* type <code>T</code> of a lower bound (<code>? super T</code>) or <code>signature</code> itself
* if it is not a bound signature.
*
* @param signature the signature
* @return the lower bound signature of <code>signature</code>
*/
public static char[] getLowerBound(char[] signature) {
if (signature.length < 1) return signature;
if (signature.length == 1 && signature[0] == Signature.C_STAR) return signature;
int superIndex = indexOf(signature, Signature.C_EXTENDS);
if (superIndex == 0) return NULL_TYPE_SIGNATURE_ARRAY;
if (superIndex != -1) {
char afterSuper = signature[superIndex + 1];
if (afterSuper == Signature.C_STAR || afterSuper == Signature.C_EXTENDS)
// impossible captured type
return NULL_TYPE_SIGNATURE_ARRAY;
}
char[][] typeArguments = Signature.getTypeArguments(signature);
for (int i = 0; i < typeArguments.length; i++)
if (Arrays.equals(typeArguments[i], NULL_TYPE_SIGNATURE_ARRAY))
return NULL_TYPE_SIGNATURE_ARRAY;
if (signature[0] == Signature.C_SUPER) {
char[] type = new char[signature.length - 1];
System.arraycopy(signature, 1, type, 0, signature.length - 1);
return type;
}
return signature;
}
示例7: computeContextInformation
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
@Override
protected IContextInformation computeContextInformation() {
char[] signature = fProposal.getSignature();
char[][] typeParameters = Signature.getTypeArguments(signature);
if (typeParameters.length == 0) return super.computeContextInformation();
ProposalContextInformation contextInformation = new ProposalContextInformation(fProposal);
if (fContextInformationPosition != 0 && fProposal.getCompletion().length == 0)
contextInformation.setContextInformationPosition(fContextInformationPosition);
return contextInformation;
}
示例8: collectTypeArguments
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
static void collectTypeArguments(String signature, Set<String> types){
String[] typeArguments = Signature.getTypeArguments(signature);
for (String arg : typeArguments) {
String[] newArguments = Signature.getTypeArguments(arg);
String simpleName = Signature.getTypeErasure(arg);
types.add(simpleName);
if(newArguments.length == 0) {
types.add(arg);
} else {
collectTypeArguments(arg, types);
}
}
}
示例9: appendTypeSignatureLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags) {
int sigKind= Signature.getTypeSignatureKind(typeSig);
switch (sigKind) {
case Signature.BASE_TYPE_SIGNATURE:
fBuilder.append(Signature.toString(typeSig));
break;
case Signature.ARRAY_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags);
for (int dim= Signature.getArrayCount(typeSig); dim > 0; dim--) {
fBuilder.append('[').append(']');
}
break;
case Signature.CLASS_TYPE_SIGNATURE:
String baseType= getSimpleTypeName(enclosingElement, typeSig);
fBuilder.append(baseType);
String[] typeArguments= Signature.getTypeArguments(typeSig);
appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags);
break;
case Signature.TYPE_VARIABLE_SIGNATURE:
fBuilder.append(getSimpleTypeName(enclosingElement, typeSig));
break;
case Signature.WILDCARD_TYPE_SIGNATURE:
char ch= typeSig.charAt(0);
if (ch == Signature.C_STAR) { //workaround for bug 85713
fBuilder.append('?');
} else {
if (ch == Signature.C_EXTENDS) {
fBuilder.append("? extends "); //$NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
} else if (ch == Signature.C_SUPER) {
fBuilder.append("? super "); //$NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
}
}
break;
case Signature.CAPTURE_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
break;
case Signature.INTERSECTION_TYPE_SIGNATURE:
String[] typeBounds= Signature.getIntersectionTypeBounds(typeSig);
appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags);
break;
default:
// unknown
}
}
示例10: appendTypeSignatureLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
protected void appendTypeSignatureLabel(
IJavaElement enclosingElement, String typeSig, long flags, StringBuilder builder) {
int sigKind = Signature.getTypeSignatureKind(typeSig);
switch (sigKind) {
case Signature.BASE_TYPE_SIGNATURE:
builder.append(Signature.toString(typeSig));
break;
case Signature.ARRAY_TYPE_SIGNATURE:
appendTypeSignatureLabel(
enclosingElement, Signature.getElementType(typeSig), flags, builder);
for (int dim = Signature.getArrayCount(typeSig); dim > 0; dim--) {
builder.append('[').append(']');
}
break;
case Signature.CLASS_TYPE_SIGNATURE:
String baseType = getSimpleTypeName(enclosingElement, typeSig);
builder.append(baseType);
String[] typeArguments = Signature.getTypeArguments(typeSig);
appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags, builder);
break;
case Signature.TYPE_VARIABLE_SIGNATURE:
builder.append(getSimpleTypeName(enclosingElement, typeSig));
break;
case Signature.WILDCARD_TYPE_SIGNATURE:
char ch = typeSig.charAt(0);
if (ch == Signature.C_STAR) { // workaround for bug 85713
builder.append('?');
} else {
if (ch == Signature.C_EXTENDS) {
builder.append("? extends "); // $NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder);
} else if (ch == Signature.C_SUPER) {
builder.append("? super "); // $NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder);
}
}
break;
case Signature.CAPTURE_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags, builder);
break;
case Signature.INTERSECTION_TYPE_SIGNATURE:
String[] typeBounds = Signature.getIntersectionTypeBounds(typeSig);
appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags, builder);
break;
default:
// unknown
}
}
示例11: appendTypeSignatureLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
protected void appendTypeSignatureLabel(
IJavaElement enclosingElement, String typeSig, long flags) {
int sigKind = Signature.getTypeSignatureKind(typeSig);
switch (sigKind) {
case Signature.BASE_TYPE_SIGNATURE:
fBuffer.append(Signature.toString(typeSig));
break;
case Signature.ARRAY_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags);
for (int dim = Signature.getArrayCount(typeSig); dim > 0; dim--) {
fBuffer.append('[').append(']');
}
break;
case Signature.CLASS_TYPE_SIGNATURE:
String baseType = getSimpleTypeName(enclosingElement, typeSig);
fBuffer.append(baseType);
String[] typeArguments = Signature.getTypeArguments(typeSig);
appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags);
break;
case Signature.TYPE_VARIABLE_SIGNATURE:
fBuffer.append(getSimpleTypeName(enclosingElement, typeSig));
break;
case Signature.WILDCARD_TYPE_SIGNATURE:
char ch = typeSig.charAt(0);
if (ch == Signature.C_STAR) { // workaround for bug 85713
fBuffer.append('?');
} else {
if (ch == Signature.C_EXTENDS) {
fBuffer.append("? extends "); // $NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
} else if (ch == Signature.C_SUPER) {
fBuffer.append("? super "); // $NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
}
}
break;
case Signature.CAPTURE_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
break;
case Signature.INTERSECTION_TYPE_SIGNATURE:
String[] typeBounds = Signature.getIntersectionTypeBounds(typeSig);
appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags);
break;
default:
// unknown
}
}
示例12: appendTypeSignatureLabel
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
protected void appendTypeSignatureLabel(IJavaElement enclosingElement, String typeSig, long flags) {
int sigKind= Signature.getTypeSignatureKind(typeSig);
switch (sigKind) {
case Signature.BASE_TYPE_SIGNATURE:
fBuffer.append(Signature.toString(typeSig));
break;
case Signature.ARRAY_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, Signature.getElementType(typeSig), flags);
for (int dim= Signature.getArrayCount(typeSig); dim > 0; dim--) {
fBuffer.append('[').append(']');
}
break;
case Signature.CLASS_TYPE_SIGNATURE:
String baseType= getSimpleTypeName(enclosingElement, typeSig);
fBuffer.append(baseType);
String[] typeArguments= Signature.getTypeArguments(typeSig);
appendTypeArgumentSignaturesLabel(enclosingElement, typeArguments, flags);
break;
case Signature.TYPE_VARIABLE_SIGNATURE:
fBuffer.append(getSimpleTypeName(enclosingElement, typeSig));
break;
case Signature.WILDCARD_TYPE_SIGNATURE:
char ch= typeSig.charAt(0);
if (ch == Signature.C_STAR) { //workaround for bug 85713
fBuffer.append('?');
} else {
if (ch == Signature.C_EXTENDS) {
fBuffer.append("? extends "); //$NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
} else if (ch == Signature.C_SUPER) {
fBuffer.append("? super "); //$NON-NLS-1$
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
}
}
break;
case Signature.CAPTURE_TYPE_SIGNATURE:
appendTypeSignatureLabel(enclosingElement, typeSig.substring(1), flags);
break;
case Signature.INTERSECTION_TYPE_SIGNATURE:
String[] typeBounds= Signature.getIntersectionTypeBounds(typeSig);
appendTypeBoundsSignaturesLabel(enclosingElement, typeBounds, flags);
break;
default:
// unknown
}
}
示例13: findMatchingTypeArgument
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Finds and returns the type argument with index <code>index</code> in the given type super
* type signature. If <code>signature</code> is a generic signature, the type parameter at
* <code>index</code> is extracted. If the type parameter is an upper bound (<code>
* ? super SomeType</code>), the type signature of <code>java.lang.Object</code> is returned.
*
* <p>Also, if <code>signature</code> has no type parameters (i.e. is a reference to the raw
* type), the type signature of <code>java.lang.Object</code> is returned.
*
* @param signature the super type signature from a type's <code>extends</code> or <code>
* implements</code> clause
* @param index the index of the type parameter to extract from <code>signature</code>
* @param context the type context inside which unqualified types should be resolved
* @return the type argument signature of the type parameter at <code>index</code> in <code>
* signature</code>
* @throws IndexOutOfBoundsException if the index is not valid
*/
private String findMatchingTypeArgument(String signature, int index, IType context)
throws IndexOutOfBoundsException {
String[] typeArguments = Signature.getTypeArguments(signature);
if (typeArguments.length > 0 && typeArguments.length <= index)
throw new IndexOutOfBoundsException();
if (typeArguments.length == 0) {
// raw binding - bound to Object
return OBJECT_SIGNATURE;
} else {
String bound = SignatureUtil.getUpperBound(typeArguments[index]);
return SignatureUtil.qualifySignature(bound, context);
}
}
示例14: findMatchingTypeArgumentIndex
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Finds and returns the index of the type argument named <code>argument</code> in the given super
* type signature.
*
* <p>If <code>signature</code> does not contain a corresponding type argument, or if <code>
* signature</code> has no type parameters (i.e. is a reference to a non-parameterized type or a
* raw type), -1 is returned.
*
* @param signature the super type signature from a type's <code>extends</code> or <code>
* implements</code> clause
* @param argument the name of the type argument to find
* @return the index of the given type argument, or -1 if there is none
*/
private int findMatchingTypeArgumentIndex(String signature, String argument) {
String[] typeArguments = Signature.getTypeArguments(signature);
for (int i = 0; i < typeArguments.length; i++) {
if (Signature.getSignatureSimpleName(typeArguments[i]).equals(argument)) return i;
}
return -1;
}
示例15: getAllTypeArguments
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Get all type arguments from an array of signatures.
*
* <p>Example: For following type X<Y<Z>,V<W>,U>.A<B> signatures is: [ ['L','X','<'
* ,'L','Y','<','L','Z',';'>',';','L','V','<','L','W',';'>',';','L' ,'U',';',>',';'],
* ['L','A','<','L','B',';','>',';'] ]
*
* @param typeSignatures Array of signatures (one per each type levels)
* @return char[][][] Array of type arguments for each signature
* @throws IllegalArgumentException If one of provided signature is malformed
* @see #splitTypeLevelsSignature(String) Then, this method returns: [ [
* ['L','Y','<','L','Z',';'>',';'], ['L','V','<','L','W',';'>',';'], ['L','U',';'] ], [
* ['L','B',';'] ] ]
*/
public static final char[][][] getAllTypeArguments(char[][] typeSignatures) {
if (typeSignatures == null) return null;
int length = typeSignatures.length;
char[][][] typeArguments = new char[length][][];
for (int i = 0; i < length; i++) {
typeArguments[i] = Signature.getTypeArguments(typeSignatures[i]);
}
return typeArguments;
}