本文整理汇总了Java中javax.lang.model.type.PrimitiveType类的典型用法代码示例。如果您正苦于以下问题:Java PrimitiveType类的具体用法?Java PrimitiveType怎么用?Java PrimitiveType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrimitiveType类属于javax.lang.model.type包,在下文中一共展示了PrimitiveType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defineNewHandler
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
/**
* Defines a new method as event handler, and marks it with @FXML annotation.
*
* @param h handler definition
*/
private void defineNewHandler(CharSequence handlerName, TypeElement eventType) {
TreeMaker mk = wcopy.getTreeMaker();
// @FXML private void {handlerName}({eventType} event);
MethodTree handler = mk.Method(
mk.Modifiers(Collections.singleton(Modifier.PRIVATE),
Collections.singletonList(fxmlAnnotationTree)
),
handlerName,
mk.PrimitiveType(TypeKind.VOID),
Collections.<TypeParameterTree>emptyList(),
Collections.singletonList(
mk.Variable(
mk.Modifiers(Collections.<Modifier>emptySet()),
"event", mk.Type(eventType.asType()), null)
),
Collections.<ExpressionTree>emptyList(),
mk.Block(Collections.<StatementTree>emptyList(), false),
null);
// add to class
controllerClass = genUtils().insertClassMember(controllerClass, handler);
addMethod(handlerName.toString(), eventType.asType());
}
示例2: visitIdentifier
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
@Override
public Tree visitIdentifier(IdentifierTree that, Trees trees) {
TypeMirror type = trees.getTypeMirror(this.getCurrentPath());
if (type == null /* will work even with error types || type.getKind() == TypeKind.ERROR */) {
return super.visitIdentifier(that, trees);
}
if (type.getKind().isPrimitive()) {
this.varToType.put(that.getName(), workingCopy.getTypes().boxedClass((PrimitiveType) type).toString());
} else {
this.varToType.put(that.getName(), type.toString());
}
TreePath currentTreePath = this.getCurrentPath();
Element el = trees.getElement(currentTreePath);
if (el != null && isExternalNEF(el, that)) {
checkIfRefactorableMutation(currentTreePath, that);
}
return super.visitIdentifier(that, trees);
}
示例3: makeToString
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
/**
* Turns the argPath leaf expression to Wrapper.toString(arg) for primitives, or to String.valueOf(arg) for
* object types. String.valueOf is null-safe.
*/
private ExpressionTree makeToString(TreePath argPath) {
ExpressionTree arg = (ExpressionTree)argPath.getLeaf();
TypeMirror tm = wc.getTrees().getTypeMirror(argPath);
if (isPrimitiveType(tm)) {
// call WrapperType.toString(arg)
arg = mk.MethodInvocation(
Collections.<ExpressionTree>emptyList(),
mk.MemberSelect(
mk.QualIdent(wc.getTypes().boxedClass((PrimitiveType)tm)),
"toString" // NOI18N
), Collections.singletonList(arg));
} else {
arg = mk.MethodInvocation(
Collections.<ExpressionTree>emptyList(),
mk.MemberSelect(
mk.QualIdent(stringType.asElement()),
"valueOf" // NOI18N
), Collections.singletonList(arg)
);
}
return arg;
}
示例4: visitEnhancedForLoop
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitEnhancedForLoop(EnhancedForLoopTree node, Object p) {
TypeMirror varType = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getVariable()));
if (!Utilities.isValidType(varType)) {
return null;
} else {
TypeMirror arrayType = info.getTypes().getArrayType(varType);
TypeElement iterableEl = info.getElements().getTypeElement("java.lang.Iterable"); // NOI18N
if (iterableEl == null || iterableEl.getKind() != ElementKind.INTERFACE) {
return null;
}
TypeMirror iterableForVar = isPrimitiveType(varType.getKind()) ?
info.getTypes().getDeclaredType(iterableEl,
info.getTypes().getWildcardType(
info.getTypes().boxedClass((PrimitiveType)varType).asType(), null))
:
info.getTypes().getDeclaredType(iterableEl,
info.getTypes().getWildcardType(varType, null)
);
List<TypeMirror> result = new ArrayList<TypeMirror>(2);
result.add(arrayType);
result.add(iterableForVar);
return result;
}
}
示例5: getValueType
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
public TypeName getValueType(Element value) {
TypeMirror type = getType(value);
// Box if primitive
if(type.getKind() != null && type.getKind().isPrimitive()) {
type = types.boxedClass((PrimitiveType) type).asType();
}
// Get generic type if value container
if(isValueContainer(type)) {
DeclaredType declaredType = (DeclaredType) type;
TypeMirror genericParameter = declaredType.getTypeArguments().get(0);
return TypeName.get(genericParameter);
}
return TypeName.get(type);
}
示例6: getTypeMoniker
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
public static TypeMoniker getTypeMoniker(TypeMirror typeMirror) {
if (typeMirror == null)
throw new NullPointerException();
if (typeMirror.getKind().isPrimitive())
return new PrimitiveTypeMoniker((PrimitiveType) typeMirror);
else if (typeMirror.getKind().equals(TypeKind.ARRAY))
return new ArrayTypeMoniker((ArrayType) typeMirror);
else if (typeMirror.getKind().equals(TypeKind.DECLARED))
return new DeclaredTypeMoniker((DeclaredType) typeMirror);
return getTypeMoniker(typeMirror.toString());
}
示例7: isValidQuery
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
public boolean isValidQuery(AccessGraph ap, Unit stmt) {
SootMethod m = bwicfg.getMethodOf(stmt);
if (!ap.isStatic() && !m.getActiveBody().getLocals().contains(ap.getBase())) {
return false;
}
if (ap.getBase() instanceof PrimitiveType) {
return false;
}
if (!ap.isStatic() && !m.isStatic()) {
Local thisLocal = m.getActiveBody().getThisLocal();
if (ap.baseMatches(thisLocal)) {
if (!ForwardFlowFunctions.hasCompatibleTypesForCall(ap, m.getDeclaringClass())) {
return false;
}
}
}
return true;
}
示例8: validateInput
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
public void validateInput(AccessGraph ap, Unit stmt) {
SootMethod m = bwicfg.getMethodOf(stmt);
if (!ap.isStatic() && !m.getActiveBody().getLocals().contains(ap.getBase())) {
throw new IllegalArgumentException("Base value of access path " + ap
+ " is not a local of the Method at which the Query was asked!");
}
if (stmt == null)
throw new IllegalArgumentException("Statment must not be null");
if (ap.getBase() instanceof PrimitiveType) {
throw new IllegalArgumentException("The queried variable is not of pointer type");
}
if (!ap.isStatic() && !m.isStatic()) {
Local thisLocal = m.getActiveBody().getThisLocal();
if (ap.baseMatches(thisLocal)) {
if (!ForwardFlowFunctions.hasCompatibleTypesForCall(ap, m.getDeclaringClass())) {
throw new IllegalArgumentException("The type is incompatible");
}
}
}
}
示例9: getWrapperTypeStrategy
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private Strategy getWrapperTypeStrategy(DeclaredType type) {
final CharSequence name = Util.getQualifiedName(type);
if (name != null) {
switch (name.toString()) {
case "java.lang.Boolean":
case "java.lang.Byte":
case "java.lang.Short":
case "java.lang.Integer":
case "java.lang.Long":
case "java.lang.Character":
case "java.lang.Float":
case "java.lang.Double":
// Handle Integer, Long, Character etc. before falling back to Serializable path
final PrimitiveType primitiveVariety = types.unboxedType(type);
if (primitiveVariety != null) {
return Strategy.create((b, n, t) -> writePrimitive(b, n, primitiveVariety), type);
}
break;
case "java.lang.Void":
return VOID_STRATEGY;
}
}
return null;
}
示例10: getArrayStrategy
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private Strategy getArrayStrategy(ArrayType arrayType) throws CodegenException {
final TypeMirror component = arrayType.getComponentType();
final TypeKind componentKind = component.getKind();
switch (componentKind) {
case BOOLEAN:
case INT:
case SHORT:
case BYTE:
case CHAR:
case LONG:
case DOUBLE:
case FLOAT:
return getPrimitiveArrayStrategy((PrimitiveType) component);
default:
final Strategy strategy = getStrategy(component);
if (strategy != null) {
return isSerialStrategy(strategy) ? getSerializableStrategy() : getSpecialArrayStrategy(strategy, component);
}
}
throw new CodegenException("Unsupported array component type: " + component + ".\n" + getHelpText());
}
示例11: writePrimitive
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private void writePrimitive(CodeBlock.Builder builder, Object name, PrimitiveType type) {
switch (type.getKind()) {
case LONG:
builder.addStatement("$N.writeLong($L)", parcelName, name);
break;
case DOUBLE:
builder.addStatement("$L.writeDouble($L)", parcelName, name);
break;
case FLOAT:
builder.addStatement("$L.writeFloat($L)", parcelName, name);
break;
case BOOLEAN:
builder.addStatement("$L.writeInt($L ? 1 : 0)", parcelName, name);
break;
default:
builder.addStatement("$L.writeInt($L)", parcelName, name);
break;
}
}
示例12: getWrapperTypeStrategy
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private Strategy getWrapperTypeStrategy(DeclaredType type) {
final CharSequence name = getQualifiedName(type);
if (name != null) {
switch (name.toString()) {
case "java.lang.Boolean":
case "java.lang.Byte":
case "java.lang.Short":
case "java.lang.Integer":
case "java.lang.Long":
case "java.lang.Character":
case "java.lang.Float":
case "java.lang.Double":
// Handle Integer, Long, Character etc. before falling back to Serializable path
final PrimitiveType primitiveVariety = types.unboxedType(type);
if (primitiveVariety != null) {
return newStrategy($ -> readPrimitive(primitiveVariety), primitiveVariety);
}
break;
case "java.lang.Void":
return VOID_STRATEGY;
}
}
return null;
}
示例13: getArrayStrategy
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private Strategy getArrayStrategy(ArrayType arrayType) throws CodegenException {
final TypeMirror component = arrayType.getComponentType();
final TypeKind componentKind = component.getKind();
switch (componentKind) {
case BOOLEAN:
case INT:
case SHORT:
case BYTE:
case CHAR:
case LONG:
case DOUBLE:
case FLOAT:
return getPrimitiveArrayStrategy((PrimitiveType) component);
default:
final Strategy strategy = getStrategy(component);
if (strategy != null) {
return isSerialStrategy(strategy)
? getSerializableStrategy(types.getArrayType(component))
: getSpecialArrayStrategy(strategy, component);
}
}
throw new CodegenException("Unsupported array component type: " + component + ".\n" + getHelpText());
}
示例14: readPrimitive
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
private CodeBlock readPrimitive(PrimitiveType type) {
switch (type.getKind()) {
case LONG:
return literal("$N.readLong()", parcelName);
case DOUBLE:
return literal("$N.readDouble()", parcelName);
case FLOAT:
return literal("$N.readFloat()", parcelName);
case BOOLEAN:
return literal("$N.readInt() == 1", parcelName);
case INT:
return literal("$N.readInt()", parcelName);
default:
return literal("($T) $N.readInt()", type, parcelName);
}
}
示例15: createAnalysis
import javax.lang.model.type.PrimitiveType; //导入依赖的package包/类
@Override
public DefaultAnalysis createAnalysis(InvocationContext<TypeMirror> context)
throws UnknownTypeException {
// boxed primitives have different names (at least for int)
CharSequence typeName;
final TypeMirror refinedMirror = context.field.refinedMirror();
if (refinedMirror instanceof DeclaredType) {
// we are boxed
typeName = this.type == Type.UNBOXED
? toCapitalCase(types().unboxedType(refinedMirror).getKind().name())
: ((DeclaredType) refinedMirror).asElement().getSimpleName();
} else {
// we are unboxed
typeName = this.type == Type.BOXED
? types().boxedClass((PrimitiveType) refinedMirror).getSimpleName()
: toCapitalCase(refinedMirror.getKind().name());
}
String methodName = (suffix != null) ? (typeName.toString() + suffix) : typeName.toString();
return DefaultAnalysis.of(this, methodName, context);
}