com.intellij.psi.PsiMethod#getReturnType ( )源码实例Demo

下面列出了com.intellij.psi.PsiMethod#getReturnType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: easy_javadoc   文件: ReturnVariableGenerator.java
@Override
public String generate(PsiElement element) {
    if (!(element instanceof PsiMethod)) {
        return "";
    }
    PsiMethod psiMethod = (PsiMethod) element;
    String returnName = psiMethod.getReturnType() == null ? "" : psiMethod.getReturnType().getPresentableText();

    if (Consts.BASE_TYPE_SET.contains(returnName)) {
        return returnName;
    } else if ("void".equalsIgnoreCase(returnName)) {
        return "";
    } else {
        return String.format("{@link %s }", returnName);
    }
}
 
private boolean isPsiMethodCamelLanguage(PsiMethod method) {
    PsiType type = method.getReturnType();
    if (type != null && type instanceof PsiClassReferenceType) {
        PsiClassReferenceType clazz = (PsiClassReferenceType) type;
        PsiClass resolved = clazz.resolve();
        if (resolved != null) {
            boolean language = getCamelIdeaUtils().isCamelExpressionOrLanguage(resolved);
            // try parent using some weird/nasty stub stuff which is how complex IDEA AST
            // is when its parsing the Camel route builder
            if (!language) {
                PsiElement elem = resolved.getParent();
                if (elem instanceof PsiTypeParameterList) {
                    elem = elem.getParent();
                }
                if (elem instanceof PsiClass) {
                    language = getCamelIdeaUtils().isCamelExpressionOrLanguage((PsiClass) elem);
                }
            }
            return language;
        }
    }

    return false;
}
 
源代码3 项目: aircon   文件: InvalidDefaultValueResIdDetector.java
private PsiType getConfigType(final PsiAnnotation configAnnotation) {
	final PsiClass configAnnotationClass = ElementUtils.getAnnotationDeclarationClass(configAnnotation);
	if (configAnnotationClass != null) {
		for (PsiMethod method : configAnnotationClass.getMethods()) {
			if (method.getName()
			          .equals(ATTRIBUTE_DEFAULT_VALUE)) {
				return method.getReturnType();
			}
		}
	}

	return null;
}
 
源代码4 项目: intellij-quarkus   文件: PsiTypeUtils.java
public static String getResolvedResultTypeName(PsiMethod method) {
    //return method.getReturnType().getCanonicalText();
    PsiType type = method.getReturnType();
    while (type instanceof PsiArrayType) {
        type = ((PsiArrayType)type).getComponentType();
    }
    return type.getCanonicalText();
}
 
@Override
protected boolean validate(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull ProblemBuilder builder) {
  boolean result = true;
  if (psiMethod.getParameterList().getParametersCount() > 0) {
    builder.addError("@Delegate is legal only on no-argument methods.");
    result = false;
  }

  final PsiType returnType = psiMethod.getReturnType();
  result &= null != returnType && handler.validate(psiMethod, returnType, psiAnnotation, builder);

  return result;
}
 
@Override
protected void processIntern(@NotNull PsiMethod psiMethod, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
  final PsiType returnType = psiMethod.getReturnType();
  if (null != returnType) {
    handler.generateElements(psiMethod, returnType, psiAnnotation, target);
  }
}
 
/**
 * Return the appropriate return class for a given method element.
 *
 * @param psiMethod the method to get the return class from.
 * @param expandType set this to true if return types annotated with @Provides(type=?)
 * should be expanded to the appropriate collection type.
 * @return the appropriate return class for the provided method element.
 */
public static PsiClass getReturnClassFromMethod(PsiMethod psiMethod, boolean expandType) {
  if (psiMethod.isConstructor()) {
    return psiMethod.getContainingClass();
  }

  PsiClassType returnType = ((PsiClassType) psiMethod.getReturnType());
  if (returnType != null) {
    // Check if has @Provides annotation and specified type
    if (expandType) {
      PsiAnnotationMemberValue attribValue = findTypeAttributeOfProvidesAnnotation(psiMethod);
      if (attribValue != null) {
        if (attribValue.textMatches(SET_TYPE)) {
          String typeName = "java.util.Set<" + returnType.getCanonicalText() + ">";
          returnType =
              ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject())
                  .createTypeFromText(typeName, psiMethod));
        } else if (attribValue.textMatches(MAP_TYPE)) {
          // TODO(radford): Supporting map will require fetching the key type and also validating
          // the qualifier for the provided key.
          //
          // String typeName = "java.util.Map<String, " + returnType.getCanonicalText() + ">";
          // returnType = ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject())
          //    .createTypeFromText(typeName, psiMethod));
        }
      }
    }

    return returnType.resolve();
  }
  return null;
}