@NonNls @Nullable public TypeConversionDescriptorBase findConversion(final PsiType from, final PsiType to, final PsiMember member, final PsiExpression context, final boolean isCovariantPosition, final TypeMigrationLabeler labeler) { final TypeConversionDescriptorBase conversion = findConversion(from, to, member, context, labeler); if(conversion != null) { return conversion; } if(isCovariantPosition) { if(to instanceof PsiEllipsisType) { if(TypeConversionUtil.isAssignable(((PsiEllipsisType) to).getComponentType(), from)) { return new TypeConversionDescriptorBase(); } } if(TypeConversionUtil.isAssignable(to, from)) { return new TypeConversionDescriptorBase(); } } return !isCovariantPosition && TypeConversionUtil.isAssignable(from, to) ? new TypeConversionDescriptorBase() : null; }
public void testTypeArrayVararg2Lvalue() throws Exception { doTestFirstParamType("meth", "Type", myJavaFacade.getElementFactory().createTypeFromText("Descendant", null).createArrayType(), new PsiEllipsisType(myJavaFacade.getElementFactory().createTypeFromText("Subject", null))); }
@Override public boolean isVarArgs() { return getType() instanceof PsiEllipsisType; }
public LightParameter(@NotNull String name, @NotNull PsiType type, PsiElement declarationScope, Language language) { this(name, type, declarationScope, language, type instanceof PsiEllipsisType); }
/** * Selects the corrected method by argument types * @param inputTypes the array of FQN of the parameter types or wildcards. * The special values are:<bl><li>"?" - means any type</li><li>".." - instructs pattern to accept the rest of the arguments</li></bl> * @return */ public PsiMethodPattern withParameters(@NonNls final String... inputTypes) { final String[] types = inputTypes.length == 0 ? ArrayUtil.EMPTY_STRING_ARRAY : inputTypes; return with(new PatternCondition<PsiMethod>("withParameters") { @Override public boolean accepts(@NotNull final PsiMethod psiMethod, final ProcessingContext context) { final PsiParameterList parameterList = psiMethod.getParameterList(); int dotsIndex = -1; while (++dotsIndex <types.length) { if (Comparing.equal("..", types[dotsIndex])) break; } if (dotsIndex == types.length && parameterList.getParametersCount() != dotsIndex || dotsIndex < types.length && parameterList.getParametersCount() < dotsIndex) { return false; } if (dotsIndex > 0) { final PsiParameter[] psiParameters = parameterList.getParameters(); for (int i = 0; i < dotsIndex; i++) { if (!Comparing.equal("?", types[i]) && !typeEquivalent(psiParameters[i].getType(), types[i])) { return false; } } } return true; } private boolean typeEquivalent(PsiType type, String expectedText) { final PsiType erasure = TypeConversionUtil.erasure(type); final String text; if (erasure instanceof PsiEllipsisType && expectedText.endsWith("[]")) { text = ((PsiEllipsisType)erasure).getComponentType().getCanonicalText() + "[]"; } else if (erasure instanceof PsiArrayType && expectedText.endsWith("...")) { text = ((PsiArrayType)erasure).getComponentType().getCanonicalText() +"..."; } else { text = erasure.getCanonicalText(); } return expectedText.equals(text); } }); }
protected MethodArgumentFix(PsiExpressionList list, int i, PsiType toType, ArgumentFixerActionFactory fixerActionFactory) { myArgList = list; myIndex = i; myArgumentFixerActionFactory = fixerActionFactory; myToType = toType instanceof PsiEllipsisType ? ((PsiEllipsisType) toType).toArrayType() : toType; }