本文整理汇总了Java中org.eclipse.jdt.core.Signature.getElementType方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.getElementType方法的具体用法?Java Signature.getElementType怎么用?Java Signature.getElementType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.Signature
的用法示例。
在下文中一共展示了Signature.getElementType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sameParameter
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope)
throws JavaModelException {
if (type.getDimensions() != Signature.getArrayCount(candidate)) return false;
// Normalizes types
if (type.isArray()) type = type.getElementType();
candidate = Signature.getElementType(candidate);
if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE)
!= type.isPrimitive()) {
return false;
}
if (type.isPrimitive() || type.isTypeVariable()) {
return type.getName().equals(Signature.toString(candidate));
} else {
// normalize (quick hack until binding.getJavaElement works)
candidate = Signature.getTypeErasure(candidate);
type = type.getErasure();
if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) {
return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type));
} else {
String[][] qualifiedCandidates = scope.resolveType(Signature.toString(candidate));
if (qualifiedCandidates == null || qualifiedCandidates.length == 0) return false;
String packageName =
type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); // $NON-NLS-1$
String typeName = getTypeQualifiedName(type);
for (int i = 0; i < qualifiedCandidates.length; i++) {
String[] qualifiedCandidate = qualifiedCandidates[i];
if (qualifiedCandidate[0].equals(packageName) && qualifiedCandidate[1].equals(typeName))
return true;
}
}
}
return false;
}
示例2: qualifySignature
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Returns the qualified signature corresponding to <code>signature</code>.
*
* @param signature the signature to qualify
* @param context the type inside which an unqualified type will be resolved to find the
* qualifier, or <code>null</code> if no context is available
* @return the qualified signature
*/
public static String qualifySignature(final String signature, final IType context) {
if (context == null) return signature;
String qualifier = Signature.getSignatureQualifier(signature);
if (qualifier.length() > 0) return signature;
String elementType = Signature.getElementType(signature);
String erasure = Signature.getTypeErasure(elementType);
String simpleName = Signature.getSignatureSimpleName(erasure);
String genericSimpleName = Signature.getSignatureSimpleName(elementType);
int dim = Signature.getArrayCount(signature);
try {
String[][] strings = context.resolveType(simpleName);
if (strings != null && strings.length > 0) qualifier = strings[0][0];
} catch (JavaModelException e) {
// ignore - not found
}
if (qualifier.length() == 0) return signature;
String qualifiedType = Signature.toQualifiedName(new String[] {qualifier, genericSimpleName});
String qualifiedSignature = Signature.createTypeSignature(qualifiedType, true);
String newSignature = Signature.createArraySignature(qualifiedSignature, dim);
return newSignature;
}
示例3: getBaseType
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Removes any type parameters and any array nesting in a type signature.
*/
private static String getBaseType(String typeSignature) {
// Strip off any type parameters
typeSignature = Signature.getTypeErasure(typeSignature);
// Strip off any array nesting
typeSignature = Signature.getElementType(typeSignature);
return typeSignature;
}
示例4: resolveTypeSignature
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Returns the resolved type signature for the given signature in the given
* method, or <code>null</code> if unable to resolve.
*
* @param method method containing the type signature
* @param typeSignature the type signature to resolve
* @return the resolved type signature
* @throws JavaModelException
*/
private static String resolveTypeSignature(IMethod method, String typeSignature) throws JavaModelException {
int count = Signature.getArrayCount(typeSignature);
String elementTypeSignature = Signature.getElementType(typeSignature);
if (elementTypeSignature.length() == 1) {
// no need to resolve primitive types
return typeSignature;
}
String elementTypeName = Signature.toString(elementTypeSignature);
IType type = method.getDeclaringType();
String[][] resolvedElementTypeNames = type.resolveType(elementTypeName);
if (resolvedElementTypeNames == null || resolvedElementTypeNames.length != 1) {
// check if type parameter
ITypeParameter typeParameter = method.getTypeParameter(elementTypeName);
if (!typeParameter.exists()) {
typeParameter = type.getTypeParameter(elementTypeName);
}
if (typeParameter.exists()) {
String[] bounds = typeParameter.getBounds();
if (bounds.length == 0) {
return "Ljava/lang/Object;"; //$NON-NLS-1$
}
String bound = Signature.createTypeSignature(bounds[0], false);
return Signature.createArraySignature(resolveTypeSignature(method, bound), count);
}
// the type name cannot be resolved
return null;
}
String[] types = resolvedElementTypeNames[0];
types[1] = types[1].replace('.', '$');
String resolvedElementTypeName = Signature.toQualifiedName(types);
String resolvedElementTypeSignature = "";
if(types[0].equals("")) {
resolvedElementTypeName = resolvedElementTypeName.substring(1);
resolvedElementTypeSignature = Signature.createTypeSignature(resolvedElementTypeName, true);
}
else {
resolvedElementTypeSignature = Signature.createTypeSignature(resolvedElementTypeName, true).replace('.', '/');
}
return Signature.createArraySignature(resolvedElementTypeSignature, count);
}
示例5: sameParameter
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope) throws JavaModelException {
if (type.getDimensions() != Signature.getArrayCount(candidate)) {
return false;
}
// Normalizes types
if (type.isArray()) {
type= type.getElementType();
}
candidate= Signature.getElementType(candidate);
if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE) != type.isPrimitive()) {
return false;
}
if (type.isPrimitive() || type.isTypeVariable()) {
return type.getName().equals(Signature.toString(candidate));
} else {
// normalize (quick hack until binding.getJavaElement works)
candidate= Signature.getTypeErasure(candidate);
type= type.getErasure();
if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) {
return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type));
} else {
String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate));
if (qualifiedCandidates == null || qualifiedCandidates.length == 0) {
return false;
}
String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$
String typeName= getTypeQualifiedName(type);
for (int i= 0; i < qualifiedCandidates.length; i++) {
String[] qualifiedCandidate= qualifiedCandidates[i];
if ( qualifiedCandidate[0].equals(packageName) &&
qualifiedCandidate[1].equals(typeName)) {
return true;
}
}
}
}
return false;
}
示例6: isPrimitive
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
public static boolean isPrimitive(String signature) {
String elementType = Signature.getElementType(signature); // getSignatureSimpleName
return PRIMITIVE_TYPES.contains(elementType);
}
示例7: stripSignatureToFQN
import org.eclipse.jdt.core.Signature; //导入方法依赖的package包/类
/**
* Returns the fully qualified type name of the given signature, with any type parameters and
* arrays erased.
*
* @param signature the signature
* @return the fully qualified type name of the signature
* @throws IllegalArgumentException if the signature is syntactically incorrect
*/
public static String stripSignatureToFQN(String signature) throws IllegalArgumentException {
signature = Signature.getTypeErasure(signature);
signature = Signature.getElementType(signature);
return Signature.toString(signature);
}