@Override protected void selectActionPerformed(AnActionEvent event, PsiElement element, String packageName) { if (!Utils.isAndroidClass(packageName)) { NotificationUtils.infoNotification("Must be Android class or Method"); return; } String linkUrl = BASE_URL; if (element instanceof PsiMethod) { PsiMethod psiMethod = (PsiMethod) element; PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); StringBuilder paramsBuilder = new StringBuilder("#" + psiMethod.getName()); paramsBuilder.append("("); for (int i = 0; i < parameters.length; i++) { PsiParameter parameter = parameters[i]; paramsBuilder.append(parameter.getType().getCanonicalText()); if (i < parameters.length - 1) { paramsBuilder.append(",%20"); } } paramsBuilder.append(")"); linkUrl += getRealPackage(psiMethod.getContainingClass()) + paramsBuilder.toString(); } else if (element instanceof PsiClass) { PsiClass psiClass = (PsiClass) element; linkUrl += getRealPackage(psiClass); } LOG.info("linkUrl= " + linkUrl); Utils.openUrl(linkUrl); }
fieldEntity = new FieldEntity(); fieldEntity.setType(type.getPresentableText()); return fieldEntity; } else if (type instanceof PsiArrayType) {
@Override public PsiType visitArrayType(PsiArrayType arrayType) { final PsiType componentType = arrayType.getComponentType(); final PsiType newComponentType = componentType.accept(this); if (newComponentType == componentType) return arrayType; return newComponentType != null ? newComponentType.createArrayType() : null; } });
public static boolean isFromExternalTypeLanguage(@NotNull PsiType type) { String internalCanonicalText = type.getInternalCanonicalText(); return internalCanonicalText != null && internalCanonicalText.equals(type.getCanonicalText()); }
@Override @NotNull public PsiType[] getSuperTypes() { final PsiType[] superTypes = myComponentType.getSuperTypes(); final PsiType[] result = createArray(superTypes.length); for (int i = 0; i < superTypes.length; i++) { result[i] = superTypes[i].createArrayType(); } return result; }
type = type.getDeepComponentType(); if (type == PsiType.INT) { if (!values.isEmpty()) { type = type.getDeepComponentType(); if (type instanceof PsiPrimitiveType) { if (PsiType.BYTE.equals(type)) { String className = type.getCanonicalText(); if (TYPE_STRING.equals(className)) {
public static String getDefaultValueOfType(PsiType type) { if (type instanceof PsiArrayType) { int count = type.getArrayDimensions() - 1; PsiType componentType = type.getDeepComponentType(); buffer.append(PsiKeyword.NEW); buffer.append(" "); buffer.append(componentType.getCanonicalText()); buffer.append("[0]"); for (int i = 0; i < count; i++) {
@Nullable public static PsiField getFieldOfGetter(PsiMethod method) { PsiField field = getSimplyReturnedField(method, getGetterReturnExpression(method)); if (field != null) { final PsiType returnType = method.getReturnType(); if (returnType != null && field.getType().equalsToText(returnType.getCanonicalText())) { return field; } } return null; }
private static boolean acceptsMethod(PsiElementFactory elementFactory, PsiMethod method, int paramCount, String... paramTypes) { PsiParameterList parameterList = method.getParameterList(); if (paramCount >= 0 && paramCount != parameterList.getParametersCount()) return false; if (paramTypes.length == 0) return true; if (parameterList.getParametersCount() < paramTypes.length) return false; PsiParameter[] psiParameters = parameterList.getParameters(); for (int i = 0; i < paramTypes.length; i++) { String paramType = paramTypes[i]; PsiParameter parameter = psiParameters[i]; PsiType psiType = parameter.getType(); if (acceptsName(paramType, psiType.getCanonicalText())) continue; try { if (psiType.isAssignableFrom(elementFactory.createTypeFromText(paramType, parameter))) continue; } catch (IncorrectOperationException ignored) { } return false; } return true; }
try { if (!PsiUtil.isStatement(JavaPsiFacade.getElementFactory(body.getProject()).createStatementFromText(body.getText(), body))) { return "Bad return type in lambda expression: " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) + " cannot be converted to void"; if (expressionType != null && !functionalInterfaceReturnType.isAssignableFrom(expressionType)) { return "Bad return type in lambda expression: " + expressionType.getPresentableText() + " cannot be converted to " + functionalInterfaceReturnType.getPresentableText();
type = ((PsiCapturedWildcardType)type).getWildcard(); PsiType transformed = type.accept(new PsiTypeVisitor<PsiType>() { @Override public PsiType visitArrayType(PsiArrayType arrayType) { PsiType componentType = transformed != null ? transformed.getDeepComponentType() : null; if (componentType instanceof PsiWildcardType) { componentType = ((PsiWildcardType)componentType).getExtendsBound(); int dims = transformed.getArrayDimensions(); for (int i = 0; i < dims; i++) componentType = componentType.createArrayType(); return componentType;
break; } else if (parameters.size() == 1 && (parameters.get(0).getType().equalsToText(SdkConstants.CLASS_BUNDLE)) || parameters.get(0).getType().equalsToText("Bundle")) { hasBundleConstructor = true;
/** * Returns {@code true} if {@code type} is a parameterized type and {@code false} otherwise. * * @param type the type to be evaluated * @return {@code true} if {@code type} is a parameterized type and {@code false} otherwise */ public static boolean isParameterizedType(PsiType type) { if (!(type instanceof PsiClassType)) { return false; } Boolean accepted = type.accept( new PsiTypeVisitor<Boolean>() { @Nullable @Override public Boolean visitClassType(PsiClassType classType) { return classType.getParameterCount() > 0; } }); return Boolean.TRUE.equals(accepted); } }
public static String formatType(@Nullable PsiType type, int options, @NotNull PsiSubstitutor substitutor) { type = substitutor.substitute(type); if ((options & SHOW_RAW_TYPE) != 0) { type = TypeConversionUtil.erasure(type); } else if ((options & SHOW_RAW_NON_TOP_TYPE) != 0) { if (!(PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter)) { final boolean preserveEllipsis = type instanceof PsiEllipsisType; type = TypeConversionUtil.erasure(type); if (preserveEllipsis && type instanceof PsiArrayType) { type = new PsiEllipsisType(((PsiArrayType)type).getComponentType()); } } } if (type == null) return "null"; return (options & SHOW_FQ_CLASS_NAMES) == 0 ? type.getPresentableText() : type.getInternalCanonicalText(); }
if (componentType1 instanceof PsiPrimitiveType && componentType2 instanceof PsiPrimitiveType && componentType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final GlobalSearchScope resolveScope = GlobalSearchScope.allScope(manager.getProject()); return PsiIntersectionType.createIntersection(componentType, cloneable, serializable); return componentType.createArrayType(); newConjuncts.add(getLeastUpperBound(type, type2, compared, manager)); return PsiIntersectionType.createIntersection(newConjuncts.toArray(PsiType.createArray(newConjuncts.size()))); PsiClass bClass = classResolveResult2.getElement(); if (aClass == null || bClass == null) { return PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject())); return PsiType.getJavaLangObject(manager, aClass.getResolveScope()); return PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(manager.getProject()));
@NonNull @Override public PsiType getType() { PsiType type = mManager.findType((TypeReference) mNativeNode); if (type != null && mNativeNode instanceof ArrayTypeReference && (((ArrayTypeReference)mNativeNode).bits & ASTNode.IsVarArgs) != 0) { return PsiEllipsisType.createEllipsis(type.getDeepComponentType(), type.getAnnotations()); } if (type == null) { type = PsiType.NULL; } return type; }
@Override public PsiType visitWildcardType(final PsiWildcardType wildcardType) { final PsiType bound = wildcardType.getBound(); PsiManager manager = wildcardType.getManager(); if (bound != null) { final PsiType acceptedBound = bound.accept(this); if (acceptedBound instanceof PsiWildcardType) { if (((PsiWildcardType)acceptedBound).isExtends() != wildcardType.isExtends()) return PsiWildcardType.createUnbounded(manager); return acceptedBound; } if (wildcardType.isExtends() && acceptedBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) return PsiWildcardType.createUnbounded(manager); if (acceptedBound.equals(bound)) return wildcardType; return wildcardType.isExtends() ? PsiWildcardType.createExtends(manager, acceptedBound) : PsiWildcardType.createSuper(manager, acceptedBound); } return wildcardType; }
PsiType substitutedBoundType = captureSubstitutor.substitute(boundType); if (substitutedBoundType != null && !(substitutedBoundType instanceof PsiWildcardType) && !substitutedBoundType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { if (originalBound instanceof PsiArrayType && substitutedBoundType instanceof PsiArrayType && !originalBound.isAssignableFrom(substitutedBoundType) && !substitutedBoundType.isAssignableFrom(originalBound)) { continue; !TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(TypeConversionUtil.erasure(originalBound)) && !TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(originalBound)) { //erasure is essential to avoid infinite recursion
/** * Converts the ellipsis type to an array type with the same component type. * * @return the array type instance. */ public PsiType toArrayType() { return getComponentType().createArrayType(getAnnotations()); }
possibleClasses.add(facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, searchScope)); if (type.getArrayDimensions() == bound.getArrayDimensions()) { final PsiType componentType = type.getComponentType(); final PsiType boundComponentType = ((PsiArrayType)bound).getComponentType(); else if (bound.getArrayDimensions() + 1 == type.getArrayDimensions() && bound.getDeepComponentType() instanceof PsiClassType) { return !possibleClasses.contains(((PsiClassType)bound.getDeepComponentType()).resolve()); else if (bound.getArrayDimensions() == type.getArrayDimensions() + 1 && type.getDeepComponentType() instanceof PsiClassType) { return !possibleClasses.contains(((PsiClassType)type.getDeepComponentType()).resolve());