public static boolean isAvailable( @Nullable PsiParameter myParameter, @Nullable PsiType type, @Nullable PsiClass targetClass) { return myParameter != null && myParameter.isValid() && myParameter.getManager().isInProject(myParameter) && myParameter.getDeclarationScope() instanceof PsiMethod && ((PsiMethod) myParameter.getDeclarationScope()).getBody() != null && type != null && type.isValid() && targetClass != null && !targetClass.isInterface() && getParameterAssignedToField(myParameter) == null; }
public static int getParameterIndex( @NotNull PsiParameter parameter, @NotNull PsiParameterList parameterList) { PsiParameter[] parameters = parameterList.getParameters(); for (int i = 0; i < parameters.length; i++) { PsiParameter paramInList = parameters[i]; if (parameter.equals(paramInList)) return i; } String name = parameter.getName(); PsiParameter suspect = null; int i; for (i = parameters.length - 1; i >= 0; i--) { PsiParameter paramInList = parameters[i]; if (name.equals(paramInList.getName())) { suspect = paramInList; break; } } String message = parameter + ":" + parameter.getClass() + " not found among parameters: " + Arrays.asList(parameters) + "." + " parameterList' parent: " + parameterList.getParent() + ";" + " parameter.getParent()==paramList: " + (parameter.getParent() == parameterList) + "; " + parameterList.getClass() + ";" + " parameter.isValid()=" + parameter.isValid() + ";" + " parameterList.isValid()= " + parameterList.isValid() + ";" + " parameterList stub: " + (parameterList instanceof StubBasedPsiElement ? ((StubBasedPsiElement) parameterList).getStub() : "---") + "; " + " parameter stub: " + (parameter instanceof StubBasedPsiElement ? ((StubBasedPsiElement) parameter).getStub() : "---") + ";" + " suspect: " + suspect + " (index=" + i + "); " + (suspect == null ? null : suspect.getClass()) + " suspect stub: " + (suspect instanceof StubBasedPsiElement ? ((StubBasedPsiElement) suspect).getStub() : suspect == null ? "-null-" : "---" + suspect.getClass()) + ";" + " parameter.equals(suspect) = " + parameter.equals(suspect) + "; " + " parameter.getNode() == suspect.getNode(): " + (parameter.getNode() == (suspect == null ? null : suspect.getNode())) + "; " + "."; LOG.error(message); return i; }