本文整理匯總了Java中org.eclipse.jdt.core.dom.Type.isPrimitiveType方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.isPrimitiveType方法的具體用法?Java Type.isPrimitiveType怎麽用?Java Type.isPrimitiveType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.Type
的用法示例。
在下文中一共展示了Type.isPrimitiveType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameters
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private List<IType> getParameters(List list) {
List<IType> params = new ArrayList<IType>();
for (Object elem : list) {
if (elem instanceof SingleVariableDeclaration) {
SingleVariableDeclaration param = (SingleVariableDeclaration) elem;
Type type = param.getType();
if (type != null && type.resolveBinding() != null && type.resolveBinding().getJavaElement() instanceof IType) {
params.add((IType) type.resolveBinding().getJavaElement());
} else {
if (type.resolveBinding() != null && type.isPrimitiveType()) {
params.add(new PrimitiveTypeHack(type.resolveBinding().getName()));
}
}
}
}
return params;
}
示例2: isMainMethod
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
/**
* Returns true iff 'methodDeclaration' represents a void static method named 'main' that takes a
* single String[] parameter.
*/
private static boolean isMainMethod(MethodDeclaration methodDeclaration) {
// Is it static?
if ((methodDeclaration.getModifiers() & Modifier.STATIC) == 0) {
return false;
}
// Does it return void?
Type returnType = methodDeclaration.getReturnType2();
if (!returnType.isPrimitiveType()) {
return false;
}
if (((PrimitiveType) returnType).getPrimitiveTypeCode() != PrimitiveType.VOID) {
return false;
}
// Is it called 'main'?
if (!"main".equals(methodDeclaration.getName().getIdentifier())) {
return false;
}
// Does it have a single parameter?
if (methodDeclaration.parameters().size() != 1) {
return false;
}
// Is the parameter's type String[]?
SingleVariableDeclaration pt =
getOnlyElement((List<SingleVariableDeclaration>) methodDeclaration.parameters());
IVariableBinding vb = pt.resolveBinding();
if (vb == null) {
return false;
}
ITypeBinding tb = vb.getType();
return tb != null && "java.lang.String[]".equals(tb.getQualifiedName());
}
示例3: newDefaultExpression
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
/**
* Returns an expression that is assignable to the given type. <code>null</code> is
* returned if the type is the 'void' type.
*
* @param ast The AST to create the expression for
* @param type The type of the returned expression
* @param extraDimensions Extra dimensions to the type
* @return the Null-literal for reference types, a boolean-literal for a boolean type, a number
* literal for primitive types or <code>null</code> if the type is void.
*/
public static Expression newDefaultExpression(AST ast, Type type, int extraDimensions) {
if (extraDimensions == 0 && type.isPrimitiveType()) {
PrimitiveType primitiveType= (PrimitiveType) type;
if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.BOOLEAN) {
return ast.newBooleanLiteral(false);
} else if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID) {
return null;
} else {
return ast.newNumberLiteral("0"); //$NON-NLS-1$
}
}
return ast.newNullLiteral();
}
示例4: testTypeEquals
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
private boolean testTypeEquals(final Class<?> expected, Type actual)
{
if(actual.isSimpleType()) {
SimpleType simpleDeclaration = (SimpleType)actual;
return testNameEquals(expected, simpleDeclaration.getName());
} else if (actual.isPrimitiveType()) {
PrimitiveType primitive = (PrimitiveType)actual;
return testPrimitiveTypeEquals(expected, primitive.getPrimitiveTypeCode());
} else { //unbekannter Typ
System.err.println("warning: not simple type, feature not implemented. type is: " + actual.getClass());
throw new UnsupportedOperationException();
}
}
示例5: newDefaultExpression
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
/**
* Returns an expression that is assignable to the given type. <code>null</code> is returned if
* the type is the 'void' type.
*
* @param ast The AST to create the expression for
* @param type The type of the returned expression
* @param extraDimensions Extra dimensions to the type
* @return the Null-literal for reference types, a boolean-literal for a boolean type, a number
* literal for primitive types or <code>null</code> if the type is void.
*/
public static Expression newDefaultExpression(AST ast, Type type, int extraDimensions) {
if (extraDimensions == 0 && type.isPrimitiveType()) {
PrimitiveType primitiveType = (PrimitiveType) type;
if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.BOOLEAN) {
return ast.newBooleanLiteral(false);
} else if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID) {
return null;
} else {
return ast.newNumberLiteral("0"); // $NON-NLS-1$
}
}
return ast.newNullLiteral();
}
示例6: isBasicType
import org.eclipse.jdt.core.dom.Type; //導入方法依賴的package包/類
public static boolean isBasicType(Type type, boolean isVoidAllowed) {
if (type.isPrimitiveType()) {
PrimitiveType.Code code = ((PrimitiveType) type).getPrimitiveTypeCode();
return (code == PrimitiveType.BOOLEAN || code == PrimitiveType.DOUBLE || code == PrimitiveType.INT
|| (code == PrimitiveType.VOID && isVoidAllowed));
}
if (type.resolveBinding().getQualifiedName().equals(String.class.getCanonicalName())) {
return true;
}
return false;
}