本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.getDimensions方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.getDimensions方法的具體用法?Java ITypeBinding.getDimensions怎麽用?Java ITypeBinding.getDimensions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.getDimensions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDimensions
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static int getDimensions(VariableDeclaration declaration) {
int dim= declaration.getExtraDimensions();
if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
LambdaExpression lambda= (LambdaExpression) declaration.getParent();
IMethodBinding methodBinding= lambda.resolveMethodBinding();
if (methodBinding != null) {
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
int index= lambda.parameters().indexOf(declaration);
ITypeBinding typeBinding= parameterTypes[index];
return typeBinding.getDimensions();
}
} else {
Type type= getType(declaration);
if (type instanceof ArrayType) {
dim+= ((ArrayType) type).getDimensions();
}
}
return dim;
}
示例2: getVariableNameSuggestions
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, ITypeBinding expectedType, Expression assignedExpression, Collection<String> excluded) {
LinkedHashSet<String> res= new LinkedHashSet<>(); // avoid duplicates but keep order
if (assignedExpression != null) {
String nameFromExpression= getBaseNameFromExpression(project, assignedExpression, variableKind);
if (nameFromExpression != null) {
add(getVariableNameSuggestions(variableKind, project, nameFromExpression, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
}
String nameFromParent= getBaseNameFromLocationInParent(assignedExpression);
if (nameFromParent != null) {
add(getVariableNameSuggestions(variableKind, project, nameFromParent, 0, excluded, false), res); // pass 0 as dimension, base name already contains plural.
}
}
if (expectedType != null) {
expectedType= Bindings.normalizeTypeBinding(expectedType);
if (expectedType != null) {
int dim= 0;
if (expectedType.isArray()) {
dim= expectedType.getDimensions();
expectedType= expectedType.getElementType();
}
if (expectedType.isParameterizedType()) {
expectedType= expectedType.getTypeDeclaration();
}
String typeName= expectedType.getName();
if (typeName.length() > 0) {
add(getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, false), res);
}
}
}
if (res.isEmpty()) {
return getDefaultVariableNameSuggestions(variableKind, excluded);
}
return res.toArray(new String[res.size()]);
}
示例3: sameParameter
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的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;
}