break; } else if (parameters.size() == 1 && (parameters.get(0).getType().equalsToText(SdkConstants.CLASS_BUNDLE)) || parameters.get(0).getType().equalsToText("Bundle")) { hasBundleConstructor = true;
@Override public boolean equalsToText(@NotNull String text) { if (myBound == null) return "?".equals(text); if (myIsExtending) { return text.startsWith(EXTENDS_PREFIX) && myBound.equalsToText(text.substring(EXTENDS_PREFIX.length())); } else { return text.startsWith(SUPER_PREFIX) && myBound.equalsToText(text.substring(SUPER_PREFIX.length())); } } @NotNull
@Override public boolean equalsToText(@NotNull String text) { return text.endsWith("[]") && myComponentType.equalsToText(text.substring(0, text.length() - 2)); }
@Contract("null -> false") public static boolean isAssignableFromPrimitiveWrapper(final PsiType type) { if (type == null) return false; return isPrimitiveWrapper(type) || type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) || type.equalsToText(CommonClassNames.JAVA_LANG_NUMBER); }
private static void addFormatParameter(PsiExpression expression, StringBuilder formatString, List<PsiExpression> formatParameters, boolean printfFormat) { final PsiType type = expression.getType(); if (!printfFormat) { formatString.append("{").append(formatParameters.size()).append("}"); } else if (type != null && (type.equalsToText("long") || type.equalsToText("int") || type.equalsToText("java.lang.Long") || type.equalsToText("java.lang.Integer"))) { formatString.append("%d"); } else { formatString.append("%s"); } formatParameters.add(getBoxedArgument(expression)); }
@Override public boolean equalsToText(@NotNull String text) { return text.endsWith("...") && getComponentType().equalsToText(text.substring(0, text.length() - 3)) || super.equalsToText(text); }
public boolean equals(Object o) { if (!(o instanceof PsiWildcardType)) return false; PsiWildcardType that = (PsiWildcardType)o; if (myBound == null && that.myBound != null) { return that.isExtends() && that.myBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT); } else if (myBound != null && that.myBound == null) { return isExtends() && myBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT); } return myIsExtending == that.myIsExtending && Comparing.equal(myBound, that.myBound); }
/** * @return 1..MAX_NUMERIC_TYPE if type is primitive numeric type, * BOOL_TYPE for boolean, * STRING_TYPE for String, * Integer.MAX_VALUE for others */ public static int getTypeRank(@NotNull PsiType type) { PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(type); if (unboxedType != null) { type = unboxedType; } int rank = TYPE_TO_RANK_MAP.get(type); if (rank != 0) return rank; if (type.equalsToText(JAVA_LANG_STRING)) return STRING_RANK; return Integer.MAX_VALUE; }
/** * Check if the given expression is within a catch block of * {@code PLAY_SERVICES_NOT_AVAILABLE_EXCEPTION} * * @param expression PsiExpression that can be within a catch block * @return true iff the expression is within the catch block */ private static boolean inCatchPlayServicesNotAvailableException(PsiExpression expression) { PsiCatchSection surroundingCatchSection = PsiTreeUtil.getParentOfType(expression, PsiCatchSection.class, true); if (surroundingCatchSection != null && surroundingCatchSection.getCatchType() != null) { PsiType catchType = surroundingCatchSection.getCatchType(); // Handle multi-catch statements such as (IOException | AnotherException e) if (catchType instanceof PsiDisjunctionType) { PsiDisjunctionType disjunctionType = (PsiDisjunctionType) catchType; if (disjunctionType.getDisjunctions() .stream() .anyMatch(t -> t.equalsToText(PLAY_SERVICES_NOT_AVAILABLE_EXCEPTION))) { return true; } } else if (catchType.equalsToText(PLAY_SERVICES_NOT_AVAILABLE_EXCEPTION)) { return true; } } return false; }
@Override public void visitPolyadicExpression(PsiPolyadicExpression expression) { for (PsiExpression operand : expression.getOperands()) { operand.accept(this); if (!myIsConstant) return; final PsiType type = operand.getType(); if (type != null && !(type instanceof PsiPrimitiveType) && !type.equalsToText(JAVA_LANG_STRING)) { myIsConstant = false; return; } } }
@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; }
@Override public void visitTypeCastExpression(PsiTypeCastExpression expression) { PsiExpression operand = expression.getOperand(); if (operand == null){ myIsConstant = false; return; } operand.accept(this); if (!myIsConstant) return; PsiTypeElement element = expression.getCastType(); if (element == null){ myIsConstant = false; return; } PsiType type = element.getType(); if (type instanceof PsiPrimitiveType) return; if (type.equalsToText(JAVA_LANG_STRING)) return; myIsConstant = false; }
/** * JLS 15.28 */ public static boolean isCompileTimeConstant(@NotNull final PsiField field) { return field.hasModifierProperty(PsiModifier.FINAL) && (TypeConversionUtil.isPrimitiveAndNotNull(field.getType()) || field.getType().equalsToText(JAVA_LANG_STRING)) && field.hasInitializer() && isConstantExpression(field.getInitializer()); }
public static Object computeCastTo(final Object operand, final PsiType castType) { if (operand == null || castType == null) return null; Object value; if (operand instanceof String && castType.equalsToText(JAVA_LANG_STRING)) { value = operand; } else if (operand instanceof Boolean && PsiType.BOOLEAN.equals(castType)) { value = operand; } else { final PsiType primitiveType = wrapperToPrimitive(operand); if (primitiveType == null) return null; // identity cast, including (boolean)boolValue if (castType.equals(primitiveType)) return operand; final int rankFrom = getTypeRank(primitiveType); if (rankFrom > caster.length) return null; final int rankTo = getTypeRank(castType); if (rankTo > caster.length) return null; value = caster[rankFrom - 1][rankTo - 1].cast(operand); } return value; }
} else if (expression instanceof PsiPolyadicExpression) { final PsiType type = expression.getType(); if (type != null && type.equalsToText(JAVA_LANG_STRING)) { final PsiPolyadicExpression binaryExpression = (PsiPolyadicExpression) expression; PsiExpression[] operands = binaryExpression.getOperands(); PsiType left = operands[0].getType(); boolean stringStarted = left != null && left.equalsToText(JAVA_LANG_STRING); if (stringStarted) { buildFormatString(operands[0], formatString, formatParameters, printfFormat); PsiType optype = op.getType(); PsiType r = TypeConversionUtil.calcTypeForBinaryExpression(left, optype, binaryExpression.getOperationTokenType(), true); if (r != null && r.equalsToText(JAVA_LANG_STRING) && !stringStarted) { stringStarted = true; PsiElement element = binaryExpression.getTokenBeforeOperand(op); if (optype != null && (optype.equalsToText(JAVA_LANG_STRING) || optype == PsiType.CHAR)) { buildFormatString(op, formatString, formatParameters, printfFormat);
public static boolean isMainMethod(final PsiMethod method) { if (method == null || method.getContainingClass() == null) return false; if (PsiType.VOID != method.getReturnType()) return false; if (!method.hasModifierProperty(PsiModifier.STATIC)) return false; if (!method.hasModifierProperty(PsiModifier.PUBLIC)) return false; final PsiParameter[] parameters = method.getParameterList().getParameters(); if (parameters.length != 1) return false; final PsiType type = parameters[0].getType(); if (!(type instanceof PsiArrayType)) return false; final PsiType componentType = ((PsiArrayType)type).getComponentType(); return componentType.equalsToText(CommonClassNames.JAVA_LANG_STRING); }
if (rType.equalsToText(JAVA_LANG_STRING)) { return rType; if (lType.equalsToText(JAVA_LANG_STRING)) { return lType;
@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 &&
public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof PsiClassType)) { return obj instanceof PsiCapturedWildcardType && ((PsiCapturedWildcardType)obj).getLowerBound().equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && equalsToText(CommonClassNames.JAVA_LANG_OBJECT); } PsiClassType otherClassType = (PsiClassType)obj; String className = getClassName(); String otherClassName = otherClassType.getClassName(); if (!Comparing.equal(className, otherClassName)) return false; if (getParameterCount() != otherClassType.getParameterCount()) return false; final ClassResolveResult result = resolveGenerics(); final ClassResolveResult otherResult = otherClassType.resolveGenerics(); if (result == otherResult) return true; final PsiClass aClass = result.getElement(); final PsiClass otherClass = otherResult.getElement(); if (aClass == null || otherClass == null) { return aClass == otherClass; } return aClass.getManager().areElementsEquivalent(aClass, otherClass) && (PsiUtil.isRawSubstitutor(aClass, result.getSubstitutor()) || PsiUtil.equalOnEquivalentClasses(this, aClass, otherClassType, otherClass)); }