Java Code Examples for com.intellij.psi.PsiMethod#getReturnType()

The following examples show how to use com.intellij.psi.PsiMethod#getReturnType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReturnVariableGenerator.java    From easy_javadoc with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: CamelDocumentationProvider.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: InvalidDefaultValueResIdDetector.java    From aircon with MIT License 5 votes vote down vote up
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;
}
 
Example 4
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
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();
}
 
Example 5
Source File: DelegateMethodProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 6
Source File: DelegateMethodProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
  }
}
 
Example 7
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}