@NotNull private static String psiTypeToString(@NotNull PsiTypeElement typeElement) { String name = removeGeneric(typeElement.getType().getPresentableText()); String typeElementString = removeGeneric(typeElement.toString()); int dot = typeElementString.indexOf("."); if (dot != -1) { String outerClasses = typeElementString.substring(typeElementString.indexOf(":") + 1, typeElementString.lastIndexOf(".")); return outerClasses.replaceAll("\\.", "\\$") + "$" + name; } return name; }
public static String checkTypeArguments(PsiTypeElement qualifier, PsiType psiType) { if (psiType instanceof PsiClassType) { final PsiJavaCodeReferenceElement referenceElement = qualifier.getInnermostComponentReferenceElement(); if (referenceElement != null) { PsiType[] typeParameters = referenceElement.getTypeParameters(); for (PsiType typeParameter : typeParameters) { if (typeParameter instanceof PsiWildcardType) { return "Unexpected wildcard"; } } } } return null; }
resolved = ((PsiClassType)type).resolve(); for (PsiElement child : typeElement.getChildren()) { if (child instanceof PsiParenthesizedExpression) { child = ((PsiParenthesizedExpression)child).getExpression(); PsiType childType = childTypeElement.getType(); if (!type.equals(childType)) { checkCatchTypeElement(statement, childTypeElement, childType);
private String findNextNotNull(PsiTypeElement psiType, String defaultName) { PsiElement nextSibling = psiType.getNextSibling(); while (nextSibling != null && StringUtils.isBlank(nextSibling.getText())) { nextSibling = nextSibling.getNextSibling(); } if (nextSibling == null) { return defaultName; } return nextSibling.getText().trim(); }
@Nullable private static VariableDeclarationImpl getVariableDeclaration(@NotNull PsiVariable element) { AdvancedExpressionFoldingSettings settings = AdvancedExpressionFoldingSettings.getInstance(); if (settings.getState().isVarExpressionsCollapse() && element.getName() != null && element.getTypeElement() != null && (element.getInitializer() != null || element.getParent() instanceof PsiForeachStatement) && element.getTextRange().getStartOffset() < element.getTypeElement().getTextRange().getEndOffset()) { boolean isFinal = calculateIfFinal(element); return new VariableDeclarationImpl(element, TextRange.create( element.getTextRange().getStartOffset(), element.getTypeElement().getTextRange().getEndOffset()), element.getModifierList() != null && isFinal); } return null; }
@NotNull public static List<PsiTypeElement> getParameterTypeElements(@NotNull PsiParameter parameter) { PsiTypeElement typeElement = parameter.getTypeElement(); return typeElement != null && typeElement.getType() instanceof PsiDisjunctionType ? PsiTreeUtil.getChildrenOfTypeAsList(typeElement, PsiTypeElement.class) : Collections.singletonList(typeElement); }
@Override public void visitInstanceOfExpression(final PsiInstanceOfExpression expression) { expression.getOperand().accept(this); myBuf.append(" ").append(PsiKeyword.INSTANCEOF).append(" "); final PsiTypeElement checkType = expression.getCheckType(); if (checkType != null) { myBuf.append(checkType.getText()); } }
@Override public void visitClassObjectAccessExpression(PsiClassObjectAccessExpression expression) { if (willScanBytecode) { return; } PsiTypeElement element = expression.getOperand(); PsiType type = element.getType(); if (type instanceof PsiClassType) { checkClassType(element, (PsiClassType) type, null); } }
@Override public void visitTypeCastExpression(final PsiTypeCastExpression expression) { final PsiTypeElement castType = expression.getCastType(); if (castType != null) { myBuf.append("(").append(castType.getText()).append(")"); } final PsiExpression operand = expression.getOperand(); if (operand != null) { operand.accept(this); } }
@NonNull @Override public PsiType[] getTypeArguments() { PsiType[] types = new PsiType[mTypeParameters.length]; for (int i = 0; i < types.length; i++) { types[i] = mTypeParameters[i].getType(); } if (types.length == 1 && types[0] instanceof PsiDiamondType) { return ((PsiDiamondType) types[0]).resolveInferredTypes().getTypes(); } return types; } }
private boolean isReturnFragment(PsiClass aClass, PsiMethod method) { return method.getReturnTypeElement() != null && aClass.getName() != null && aClass.getName().equals(method.getReturnTypeElement().getText()); }
@Override public void visitTypeCastExpression(PsiTypeCastExpression expression) { PsiTypeElement castTypeElement = expression.getCastType(); PsiExpression operand = expression.getOperand(); if (operand == null || castTypeElement == null) { return; } PsiType operandType = operand.getType(); PsiType castType = castTypeElement.getType(); if (castType.equals(operandType)) { return; } if (!(operandType instanceof PsiClassType)) { return; } if (!(castType instanceof PsiClassType)) { return; } PsiClassType classType = (PsiClassType)operandType; PsiClassType interfaceType = (PsiClassType)castType; checkCast(expression, classType, interfaceType); }
@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; }
PsiTypeElement typeElement = cast.getCastType(); if (typeElement != null) { PsiType type = typeElement.getType(); if (PsiType.FLOAT.equals(type)) { return number.floatValue();
@Override public void visitTryStatement(PsiTryStatement statement) { PsiResourceList resourceList = statement.getResourceList(); //noinspection VariableNotUsedInsideIf if (resourceList != null) { int api = 19; // minSdk for try with resources int minSdk = getMinSdk(mContext); if (api > minSdk && api > getTargetApi(statement)) { Location location = mContext.getLocation(resourceList); String message = String.format("Try-with-resources requires " + "API level %1$d (current min is %2$d)", api, Math.max(minSdk, getTargetApi(statement))); mContext.report(UNSUPPORTED, statement, location, message); } } if (willScanBytecode) { return; } for (PsiParameter parameter : statement.getCatchBlockParameters()) { PsiTypeElement typeElement = parameter.getTypeElement(); if (typeElement != null) { checkCatchTypeElement(statement, typeElement, typeElement.getType()); } } }
@Nullable public static PsiType getQualifierType(PsiMethodReferenceExpression expression) { PsiType qualifierType = null; final PsiTypeElement typeElement = expression.getQualifierType(); if (typeElement != null) { qualifierType = typeElement.getType(); } else { final PsiElement qualifier = expression.getQualifier(); if (qualifier instanceof PsiExpression) { qualifierType = ((PsiExpression)qualifier).getType(); } } if (qualifierType == null) { final QualifierResolveResult qualifierResolveResult = getQualifierResolveResult(expression); final PsiClass containingClass = qualifierResolveResult.getContainingClass(); if (containingClass == null) { return null; } qualifierType = JavaPsiFacade.getElementFactory(expression.getProject()).createType(containingClass); } return qualifierType; }
return; PsiType type = castTypeElement.getType(); String castType = null; if (type instanceof PsiClassType) {
String expectedClass = getExpectedType(name); if (expectedClass != null && cast.getCastType() != null) { String castType = cast.getCastType().getType().getCanonicalText(); if (castType.indexOf('.') == -1) { expectedClass = stripPackage(expectedClass);