本文整理匯總了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);
}