本文整理汇总了Java中javax.lang.model.type.TypeKind.VOID属性的典型用法代码示例。如果您正苦于以下问题:Java TypeKind.VOID属性的具体用法?Java TypeKind.VOID怎么用?Java TypeKind.VOID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.lang.model.type.TypeKind
的用法示例。
在下文中一共展示了TypeKind.VOID属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeUnary
private static List<? extends TypeMirror> computeUnary(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
UnaryTree tree = (UnaryTree) parent.getLeaf();
if (tree.getExpression() == error) {
List<? extends TypeMirror> parentTypes = resolveType(types, info, parent.getParentPath(), tree, offset, null, null);
if (parentTypes != null) {
//may contain only "void", ignore:
if (parentTypes.size() != 1) {
return parentTypes;
}
if (parentTypes.get(0).getKind() != TypeKind.VOID) {
return parentTypes;
}
}
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT));
}
return null;
}
示例2: hint
@TriggerPattern("$method($params$);")
public static ErrorDescription hint(HintContext ctx) {
Element invoked = ctx.getInfo().getTrees().getElement(new TreePath(ctx.getPath(), ((ExpressionStatementTree) ctx.getPath().getLeaf()).getExpression()));
if (invoked == null || invoked.getKind() != ElementKind.METHOD || ((ExecutableElement) invoked).getReturnType().getKind() == TypeKind.VOID) return null;
boolean found = false;
for (AnnotationMirror am : invoked.getAnnotationMirrors()) {
String simpleName = am.getAnnotationType().asElement().getSimpleName().toString();
if ("CheckReturnValue".equals(simpleName)) {
found = true;
break;
}
}
if (!found && !checkReturnValueForJDKMethods((ExecutableElement) invoked)) return null;
String displayName = NbBundle.getMessage(CheckReturnValueHint.class, "ERR_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint");
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), displayName);
}
示例3: getPrimitiveTypeKind
public TypeKind getPrimitiveTypeKind() {
switch (this) {
case BOOLEAN:
return TypeKind.BOOLEAN;
case BYTE:
return TypeKind.BYTE;
case SHORT:
return TypeKind.SHORT;
case INT:
return TypeKind.INT;
case LONG:
return TypeKind.LONG;
case CHAR:
return TypeKind.CHAR;
case FLOAT:
return TypeKind.FLOAT;
case DOUBLE:
return TypeKind.DOUBLE;
case VOID:
return TypeKind.VOID;
default:
throw new AssertionError("unknown primitive type " + this);
}
}
示例4: isPropertyMethod
private boolean isPropertyMethod(ExecutableElement method) {
if (!configuration.javafx) {
return false;
}
if (!utils.getSimpleName(method).endsWith("Property")) {
return false;
}
if (!memberIsVisible(method)) {
return false;
}
if (GETTERSETTERPATTERN.matcher(utils.getSimpleName(method)).matches()) {
return false;
}
if (!method.getTypeParameters().isEmpty()) {
return false;
}
return method.getParameters().isEmpty()
&& method.getReturnType().getKind() != TypeKind.VOID;
}
示例5: expression2Return
@Hint(displayName="#DN_expression2Return", description="#DESC_expression2Return", category="suggestions", hintKind=Hint.Kind.ACTION,
minSourceVersion = "8")
@Messages({
"DN_expression2Return=Convert Lambda Body to Use a Block",
"DESC_expression2Return=Converts lambda bodies to use blocks rather than expressions",
"ERR_expression2Return=",
"FIX_expression2Return=Use block as the lambda's body"
})
@TriggerPattern("($args$) -> $lambdaExpression")
public static ErrorDescription expression2Return(HintContext ctx) {
if (((LambdaExpressionTree) ctx.getPath().getLeaf()).getBodyKind() != BodyKind.EXPRESSION) {
return null;
}
TypeMirror lambdaExpressionType = ctx.getInfo().getTrees().getTypeMirror(ctx.getVariables().get("$lambdaExpression"));
String target = lambdaExpressionType == null || lambdaExpressionType.getKind() != TypeKind.VOID
? "($args$) -> { return $lambdaExpression; }"
: "($args$) -> { $lambdaExpression; }";
return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), Bundle.ERR_expression2Return(), JavaFixUtilities.rewriteFix(ctx, Bundle.FIX_expression2Return(), ctx.getPath(), target));
}
示例6: visitReturn
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitReturn(ReturnTree tree, Void ignore) {
if (foundReturn) {
env.messages.warning(REFERENCE, tree, "dc.exists.return");
}
Element e = env.trees.getElement(env.currPath);
if (e.getKind() != ElementKind.METHOD
|| ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID)
env.messages.error(REFERENCE, tree, "dc.invalid.return");
foundReturn = true;
warnIfEmpty(tree, tree.getDescription());
return super.visitReturn(tree, ignore);
}
示例7: isDiscoveredAttribute
private static boolean isDiscoveredAttribute(ExecutableElement attributeMethodCandidate, boolean isDefaultAsDefault) {
return attributeMethodCandidate.getParameters().isEmpty()
&& attributeMethodCandidate.getReturnType().getKind() != TypeKind.VOID
&& (isAbstract(attributeMethodCandidate)
|| hasGenerateAnnotation(attributeMethodCandidate)
|| isDefaultAsDefault);
}
示例8: encodeAsString
public static String encodeAsString(TypeDesc td) {
if (td.typeKind.isPrimitive() || td.typeKind == TypeKind.VOID)
return StringUtils.toLowerCase(td.typeKind.toString());
if (td.typeKind == TypeKind.ARRAY)
return encodeAsString(((ArrayTypeDesc) td).compTypeDesc) + "[]";
if (td.typeKind == TypeKind.TYPEVAR)
return "#" + ((TypeVarTypeDesc) td).identifier;
if (td.typeKind == TypeKind.DECLARED)
return ((ReferenceTypeDesc) td).javaType.toString();
throw new AssertionError("Unhandled type: " + td.typeKind);
}
示例9: buildEventHandlerActionMethod
@Nonnull
private static MethodSpec.Builder buildEventHandlerActionMethod( @Nonnull final EventHandlerDescriptor eventHandler )
{
final MethodSpec.Builder method =
MethodSpec.methodBuilder( eventHandler.getMethod().getSimpleName().toString() ).
returns( TypeName.get( eventHandler.getMethodType().getReturnType() ) );
ProcessorUtil.copyTypeParameters( eventHandler.getMethodType(), method );
ProcessorUtil.copyAccessModifiers( eventHandler.getMethod(), method );
ProcessorUtil.copyDocumentedAnnotations( eventHandler.getMethod(), method );
final AnnotationSpec.Builder annotation =
AnnotationSpec.builder( ACTION_CLASSNAME ).
addMember( "reportParameters", "false" );
method.addAnnotation( annotation.build() );
final int paramCount = eventHandler.getMethod().getParameters().size();
for ( int i = 0; i < paramCount; i++ )
{
final TypeMirror paramType = eventHandler.getMethodType().getParameterTypes().get( i );
final ParameterSpec.Builder parameter =
ParameterSpec.builder( TypeName.get( paramType ), "arg" + i, Modifier.FINAL );
ProcessorUtil.copyDocumentedAnnotations( eventHandler.getMethod().getParameters().get( i ), parameter );
method.addParameter( parameter.build() );
}
final String params =
0 == paramCount ?
"" :
IntStream.range( 0, paramCount ).mapToObj( i -> "arg" + i ).collect( Collectors.joining( "," ) );
final boolean isVoid = eventHandler.getMethodType().getReturnType().getKind() == TypeKind.VOID;
method.addStatement( ( isVoid ? "" : "return " ) + "super.$N(" + params + ")",
eventHandler.getMethod().getSimpleName() );
return method;
}
示例10: isMainMethod
private static boolean isMainMethod(ExecutableElement m) {
return m.getModifiers().contains(Modifier.STATIC) &&
m.getSimpleName().contentEquals("main") &&
(m.getReturnType().getKind() == TypeKind.VOID) &&
(m.getParameters().size() == 1) &&
(m.getParameters().get(0).asType().toString().equals("java.lang.String[]"));
}
示例11: generateAbstractMethodImpl
/**
* Generates a simple implementation of an abstract method declared
* in a supertype.
*
* @param abstractMethod the method whose implementation is to be generated
*/
private static MethodTree generateAbstractMethodImpl(
ExecutableElement abstractMethod,
WorkingCopy workingCopy) {
final TreeMaker maker = workingCopy.getTreeMaker();
TypeMirror returnType = abstractMethod.getReturnType();
List<? extends StatementTree> content;
if (returnType.getKind() == TypeKind.VOID) {
content = Collections.<StatementTree>emptyList();
} else {
content = Collections.singletonList(
maker.Return(getDefaultValue(maker, returnType)));
}
BlockTree body = maker.Block(content, false);
return maker.Method(
maker.Modifiers(Collections.singleton(PUBLIC)),
abstractMethod.getSimpleName(),
maker.Type(returnType),
makeTypeParamsCopy(abstractMethod.getTypeParameters(), maker),
makeParamsCopy(abstractMethod.getParameters(), maker),
makeDeclaredTypesCopy((List<? extends DeclaredType>)
abstractMethod.getThrownTypes(),
maker),
body,
null);
}
示例12: complete
@Override
public List<? extends CompletionItem> complete() {
// attempt to find methods in the controller
TypeElement el = controller.resolve(ctx.getCompilationInfo());
TypeElement eventType = event.getEventType().resolve(ctx.getCompilationInfo());
if (el == null || eventType == null) {
return null;
}
List<ExecutableElement> allMethods = ElementFilter.methodsIn(ctx.getCompilationInfo().getElements().getAllMembers(el));
List<CompletionItem> items = new ArrayList<CompletionItem>();
for (ExecutableElement em : allMethods) {
if (!FxClassUtils.isFxmlAccessible(em)) {
continue;
}
if (em.getParameters().size() > 1 || em.getReturnType().getKind() != TypeKind.VOID) {
continue;
}
if (!em.getParameters().isEmpty()) {
VariableElement v = em.getParameters().get(0);
if (!ctx.getCompilationInfo().getTypes().isAssignable(v.asType(), eventType.asType())) {
continue;
}
} else if (!FxClassUtils.isFxmlAnnotated(em)) {
// require FXML annotation, there are many void no-arg methods.
continue;
}
items.add(new ValueItem(ctx, em.getSimpleName().toString(), "#", ICON_RESOURCE));
}
return items;
}
示例13: createMethod
@NonNull
protected MethodSpec.Builder createMethod(final Symbol.MethodSymbol ms) throws Exception {
final String methodName = ms.getSimpleName().toString();
final MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName);
builder.addModifiers(Modifier.FINAL, Modifier.PUBLIC);
// extract annotations of return type / method. copy all, except @Yield & @AfterCall
mimicMethodAnnotations(builder, ms);
// extract our own annotations
final Attribute.Compound yield = findYieldMethodAnnotation(ms);
final Attribute.Compound after = findAfterMethodAnnotation(ms);
// extract return type
final Type returnType = ms.getReturnType();
final boolean hasReturn = returnType.getKind() != TypeKind.VOID;
builder.returns(TypeName.get(returnType));
// extract parameters
final StringBuilder arguments = mimicParameters(builder, ms);
// extract throws
mimicThrows(builder, ms);
builder.beginControlFlow("if (!$L( $S$L ))", PREDICATE, methodName,
(arguments.length() == 0 ? "" : ", ") + arguments);
// generate default return value
if (hasReturn || null != yield) {
if (null != yield) builder.addComment("" + yield);
createYieldPart(builder, returnType, yield);
} else {
builder.addStatement("return");
}
builder.endControlFlow();
// generate return
if (null == after) {
builder.addStatement((hasReturn ? "return " : "") + "this.inner.$N($L)", methodName, arguments);
} else {
afterCalls.set(true);
if (hasReturn) {
builder.addStatement("return $L($S, this.inner.$N($L))", AFTERCALL, methodName, methodName, arguments);
} else {
builder.addStatement("this.inner.$N($L)", methodName, arguments);
builder.addStatement("$L($S, null)", AFTERCALL, methodName);
}
}
return builder;
}
示例14: needsErasure
private static boolean needsErasure(TypeMirror typeMirror) {
return typeMirror.getKind() != TypeKind.NONE && typeMirror.getKind() != TypeKind.VOID && !typeMirror.getKind().isPrimitive() && typeMirror.getKind() != TypeKind.OTHER &&
typeMirror.getKind() != TypeKind.NULL;
}
示例15: analyseMethodForProperties
/** Analyses one method for property charcteristics */
Property analyseMethodForProperties( Parameters p, ExecutableElement method ) {
// Skip static methods as Introspector does.
if( method.getModifiers().contains(STATIC) ) {
return null;
}
String name = nameAsString(method);
VariableElement[] params = method.getParameters().toArray(new VariableElement[0]);
TypeMirror returnType = method.getReturnType();
Property pp = null;
try {
if ( params.length == 0 ) {
if (name.startsWith( GET_PREFIX )) {
// SimpleGetter
pp = new Property( p.ci, method, null );
}
else if ( returnType.getKind() == TypeKind.BOOLEAN && name.startsWith( IS_PREFIX )) {
// Boolean getter
pp = new Property( p.ci, method, null );
}
}
else if ( params.length == 1 ) {
if ( params[0].asType().getKind() == TypeKind.INT) {
if(name.startsWith( GET_PREFIX )) {
pp = new IdxProperty( p.ci, null, null, method, null );
} else if ( returnType.getKind() == TypeKind.BOOLEAN && name.startsWith( IS_PREFIX )) {
pp = new IdxProperty( p.ci, null, null, method, null );
} else if (returnType.getKind() == TypeKind.VOID && name.startsWith(SET_PREFIX)) {
pp = new Property(p.ci, null, method);
// PENDING vetoable => constrained
}
}
else if ( returnType.getKind() == TypeKind.VOID && name.startsWith( SET_PREFIX )) {
pp = new Property( p.ci, null, method );
// PENDING vetoable => constrained
}
}
else if ( params.length == 2 ) {
if ( params[0].asType().getKind() == TypeKind.INT && name.startsWith( SET_PREFIX )) {
pp = new IdxProperty( p.ci, null, null, null, method );
// PENDING vetoable => constrained
}
}
}
catch (IntrospectionException ex) {
// PropertyPattern constructor found some differencies from design patterns.
LOG.log(Level.INFO, ex.getMessage(), ex);
pp = null;
}
return pp;
}