@Override public void visitParenthesizedExpression(PsiParenthesizedExpression expression) { PsiElement parent = expression.getParent(); if (parent != null) { final MyParentVisitor visitor = new MyParentVisitor(expression, myForCompletion, myClassProvider, myVoidable, myUsedAfter); parent.accept(visitor); for (final ExpectedTypeInfo info : visitor.myResult) { myResult.add(createInfoImpl(info.getType(), info.getKind(), info.getDefaultType(), TailTypes.RPARENTH, info.getCalledMethod(), new NullableComputable<String>() { @Nullable @Override public String compute() { return ((ExpectedTypeInfoImpl)info).getExpectedName(); } })); } } }
private void visitMethodReturnType(final PsiMethod scopeMethod, PsiType type, boolean tailTypeSemicolon) { if (type != null) { NullableComputable<String> expectedName; if (PropertyUtil.isSimplePropertyAccessor(scopeMethod)) { expectedName = new NullableComputable<String>() { @Override public String compute() { return PropertyUtil.getPropertyName(scopeMethod); } }; } else { expectedName = ExpectedTypeInfoImpl.NULL; } myResult.add(createInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, tailTypeSemicolon ? TailType.SEMICOLON : TailType.NONE, null, expectedName)); } }
public ExpectedTypeInfoImpl(@NotNull PsiType type, @Type int kind, @NotNull PsiType defaultType, @NotNull TailType myTailType, PsiMethod calledMethod, @NotNull NullableComputable<String> expectedName) { this.type = type; this.kind = kind; this.myTailType = myTailType; this.defaultType = defaultType; myCalledMethod = calledMethod; this.expectedNameComputable = expectedName; expectedNameLazyValue = new VolatileNullableLazyValue<String>() { @Nullable @Override protected String compute() { return expectedNameComputable.compute(); } }; PsiUtil.ensureValidType(type); PsiUtil.ensureValidType(defaultType); }
@Nullable @Override public Project createProject(String name, final String path) { myProjectMode = true; unzip(name, path, false); return ApplicationManager.getApplication().runWriteAction(new NullableComputable<Project>() { @Nullable @Override public Project compute() { try { return ProjectManagerEx.getInstanceEx().convertAndLoadProject(path); } catch (IOException e) { LOG.error(e); return null; } } }); }
@Nullable public String getFullName(final @NotNull PropertiesFile propertiesFile) { return ApplicationManager.getApplication().runReadAction(new NullableComputable<String>() { public String compute() { final PsiDirectory directory = propertiesFile.getParent(); final String packageQualifiedName = PropertiesUtil.getPackageQualifiedName(directory); if (packageQualifiedName == null) { return null; } final StringBuilder qName = new StringBuilder(packageQualifiedName); if (qName.length() > 0) { qName.append("."); } qName.append(getBaseName(propertiesFile.getContainingFile())); return qName.toString(); } }); }
@Nullable private static PsiType getLeastUpperBoundByVar(@NotNull final GrVariable var) { return RecursionManager.doPreventingRecursion(var, false, new NullableComputable<PsiType>() { @Override public PsiType compute() { final Collection<PsiReference> all = ReferencesSearch.search(var, var.getUseScope()).findAll(); final GrExpression initializer = var.getInitializerGroovy(); if (initializer == null && all.isEmpty()) { return var.getDeclaredType(); } PsiType result = initializer != null ? initializer.getType() : null; final PsiManager manager = var.getManager(); for (PsiReference reference : all) { final PsiElement ref = reference.getElement(); if (ref instanceof GrReferenceExpression && PsiUtil.isLValue(((GrReferenceExpression)ref))) { result = TypesUtil.getLeastUpperBoundNullable(result, TypeInferenceHelper.getInitializerTypeFor(ref), manager); } } return result; } }); }
@Override public PsiType fun(GrMethodCall methodCall, PsiMethod method) { GrExpression[] allArguments = PsiUtil.getAllArguments(methodCall); GrClosableBlock closure = null; for (GrExpression argument : allArguments) { if (argument instanceof GrClosableBlock) { closure = (GrClosableBlock)argument; break; } } if (closure == null) return null; final GrClosableBlock finalClosure = closure; return ourGuard.doPreventingRecursion(methodCall, true, new NullableComputable<PsiType>() { @Override public PsiType compute() { PsiType returnType = finalClosure.getReturnType(); if (returnType == PsiType.VOID) return null; return returnType; } }); }
@Override @Nullable public String getExternalDocInfoForElement(final String docURL, final PsiElement element) throws Exception { String externalDoc = super.getExternalDocInfoForElement(docURL, element); if (externalDoc != null) { if (element instanceof PsiMethod) { final String className = ApplicationManager.getApplication().runReadAction( new NullableComputable<String>() { @Override @Nullable public String compute() { PsiClass aClass = ((PsiMethod)element).getContainingClass(); return aClass == null ? null : aClass.getQualifiedName(); } } ); Matcher matcher = ourMethodHeading.matcher(externalDoc); final StringBuilder buffer = new StringBuilder(); DocumentationManager.createHyperlink(buffer, className, className, false); //noinspection HardCodedStringLiteral return matcher.replaceFirst("<H3>" + buffer.toString() + "</H3>"); } } return externalDoc; }
private void visitMethodReturnType(final PsiMethod scopeMethod, PsiType type, boolean tailTypeSemicolon) { if (type != null) { ExpectedTypeInfoImpl info = createInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, tailTypeSemicolon ? TailType.SEMICOLON : TailType.NONE); if (PropertyUtil.isSimplePropertyAccessor(scopeMethod)) { info.expectedName = new NullableComputable<String>() { @Override public String compute() { return PropertyUtil.getPropertyName(scopeMethod); } }; } myResult = new ExpectedTypeInfo[]{info}; } else { myResult = ExpectedTypeInfo.EMPTY_ARRAY; } }
public String diagnoseNull() { try { PsiElement element = ApplicationManager.getApplication().runReadAction(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return restoreFromStubIndex((PsiFileWithStubSupport)getFile(), myIndex, myElementType, true); } }); return "No diagnostics, element=" + element + "@" + (element == null ? 0 : System.identityHashCode(element)); } catch (AssertionError e) { return e.getMessage() + "; current modCount=" + PsiManager.getInstance(getProject()).getModificationTracker().getModificationCount() + "; creation modCount=" + myCreationModCount; } }
@Nullable public static XmlContentDFA createContentDFA(@NotNull XmlTag parentTag) { final PsiFile file = parentTag.getContainingFile().getOriginalFile(); if (!(file instanceof XmlFile)) return null; XSModel xsModel = ApplicationManager.getApplication().runReadAction(new NullableComputable<XSModel>() { @Override public XSModel compute() { return getXSModel((XmlFile)file); } }); if (xsModel == null) { return null; } XSElementDeclaration decl = getElementDeclaration(parentTag, xsModel); if (decl == null) { return null; } return new XsContentDFA(decl, parentTag); }
public String diagnoseNull() { final PsiFile file = ApplicationManager.getApplication().runReadAction((Computable<PsiFile>)() -> getFile()); try { PsiElement element = ApplicationManager.getApplication().runReadAction( (NullableComputable<PsiElement>)() -> restoreFromStubIndex((PsiFileWithStubSupport)file, myIndex, myElementType, true)); return "No diagnostics, element=" + element + "@" + (element == null ? 0 : System.identityHashCode(element)); } catch (AssertionError e) { String msg = e.getMessage(); msg += file == null ? "\n no PSI file" : "\n current file stamp=" + (short)file.getModificationStamp(); final Document document = FileDocumentManager.getInstance().getCachedDocument(myVirtualFile); if (document != null) { msg += "\n committed=" + PsiDocumentManager.getInstance(myProject).isCommitted(document); msg += "\n saved=" + !FileDocumentManager.getInstance().isDocumentUnsaved(document); } return msg; } }
@Override public void visitParenthesizedExpression(PsiParenthesizedExpression expression) { PsiElement parent = expression.getParent(); if(parent != null) { final MyParentVisitor visitor = new MyParentVisitor(expression, myForCompletion, myClassProvider, myVoidable, myUsedAfter); parent.accept(visitor); for(final ExpectedTypeInfo info : visitor.myResult) { myResult.add(createInfoImpl(info.getType(), info.getKind(), info.getDefaultType(), TailTypes.RPARENTH, info.getCalledMethod(), new NullableComputable<String>() { @Nullable @Override public String compute() { return ((ExpectedTypeInfoImpl) info).getExpectedName(); } })); } } }
private void visitMethodReturnType(final PsiMethod scopeMethod, PsiType type, boolean tailTypeSemicolon) { if(type != null) { NullableComputable<String> expectedName; if(PropertyUtil.isSimplePropertyAccessor(scopeMethod)) { expectedName = new NullableComputable<String>() { @Override public String compute() { return PropertyUtil.getPropertyName(scopeMethod); } }; } else { expectedName = ExpectedTypeInfoImpl.NULL; } myResult.add(createInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, tailTypeSemicolon ? TailType.SEMICOLON : TailType.NONE, null, expectedName)); } }
@Nullable private static NullableComputable<String> getPropertyName(@NotNull final PsiVariable variable) { return new NullableComputable<String>() { @Override public String compute() { final String name = variable.getName(); if(name == null) { return null; } JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(variable.getProject()); VariableKind variableKind = codeStyleManager.getVariableKind(variable); return codeStyleManager.variableNameToPropertyName(name, variableKind); } }; }
@NotNull private static ExpectedTypeInfoImpl createInfoImpl(@NotNull PsiType type, int kind, PsiType defaultType, @NotNull TailType tailType, PsiMethod calledMethod, NullableComputable<String> expectedName) { return new ExpectedTypeInfoImpl(type, kind, defaultType, tailType, calledMethod, expectedName); }
@Nullable private static ExpectedTypeInfo getEqualsType(@Nullable PsiExpression anotherExpr) { PsiType anotherType = anotherExpr != null ? anotherExpr.getType() : null; if (anotherType == null) { return null; } NullableComputable<String> expectedName = ExpectedTypeInfoImpl.NULL; if (anotherExpr instanceof PsiReferenceExpression) { PsiElement refElement = ((PsiReferenceExpression)anotherExpr).resolve(); if (refElement instanceof PsiVariable) { expectedName = getPropertyName((PsiVariable)refElement); } } ExpectedTypeInfoImpl info; if (anotherType instanceof PsiPrimitiveType) { if (PsiType.BOOLEAN.equals(anotherType)) { info = createInfoImpl(anotherType, ExpectedTypeInfo.TYPE_STRICTLY, anotherType, TailType.NONE, null, expectedName); } else if (PsiType.NULL.equals(anotherType)) { PsiType objectType = PsiType.getJavaLangObject(anotherExpr.getManager(), anotherExpr.getResolveScope()); info = createInfoImpl(objectType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, objectType, TailType.NONE, null, expectedName); } else { info = createInfoImpl(PsiType.DOUBLE, ExpectedTypeInfo.TYPE_OR_SUBTYPE, anotherType, TailType.NONE, null, expectedName); } } else { info = createInfoImpl(anotherType, ExpectedTypeInfo.TYPE_STRICTLY, anotherType, TailType.NONE, null, expectedName); } return info; }
@Override public void visitConditionalExpression(@NotNull PsiConditionalExpression expr) { if (myExpr.equals(expr.getCondition())) { if (myForCompletion) { myExpr = expr; myExpr.getParent().accept(this); return; } myResult.add(createInfoImpl(PsiType.BOOLEAN, ExpectedTypeInfo.TYPE_STRICTLY, PsiType.BOOLEAN, TailType.NONE)); } else if (myExpr.equals(expr.getThenExpression())) { ExpectedTypeInfo[] types = getExpectedTypes(expr, myForCompletion); for (int i = 0; i < types.length; i++) { final ExpectedTypeInfo info = types[i]; types[i] = createInfoImpl(info.getType(), info.getKind(), info.getDefaultType(), TailType.COND_EXPR_COLON, info.getCalledMethod(), new NullableComputable<String>() { @Nullable @Override public String compute() { return ((ExpectedTypeInfoImpl)info).getExpectedName(); } }); } Collections.addAll(myResult, types); } else { if (!myExpr.equals(expr.getElseExpression())) { LOG.error(Arrays.asList(expr.getChildren()) + "; " + myExpr); } Collections.addAll(myResult, getExpectedTypes(expr, myForCompletion)); } }
private static void inferMethodCallArgumentTypes(@NotNull final PsiExpression argument, final boolean forCompletion, @NotNull final PsiExpression[] args, final int index, @NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor, @NotNull final Set<ExpectedTypeInfo> array) { LOG.assertTrue(substitutor.isValid()); PsiParameter[] parameters = method.getParameterList().getParameters(); if (!forCompletion && parameters.length != args.length) return; if (parameters.length <= index && !method.isVarArgs()) return; for (int j = 0; j < index; j++) { PsiType paramType = getParameterType(parameters[Math.min(parameters.length - 1, j)], substitutor); PsiType argType = args[j].getType(); if (argType != null && !paramType.isAssignableFrom(argType)) return; } PsiParameter parameter = parameters[Math.min(parameters.length - 1, index)]; PsiType parameterType = getParameterType(parameter, substitutor); TailType tailType = getMethodArgumentTailType(argument, index, method, substitutor, parameters); PsiType defaultType = getDefaultType(method, substitutor, parameterType, argument, args, index); NullableComputable<String> propertyName = getPropertyName(parameter); ExpectedTypeInfoImpl info = createInfoImpl(parameterType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, defaultType, tailType, method, propertyName); array.add(info); if (index == parameters.length - 1 && parameter.isVarArgs()) { //Then we may still want to call with array argument final PsiArrayType arrayType = parameterType.createArrayType(); ExpectedTypeInfoImpl info1 = createInfoImpl(arrayType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, arrayType, tailType, method, propertyName); array.add(info1); } }
@Nullable private static NullableComputable<String> getPropertyName(@NotNull final PsiVariable variable) { return new NullableComputable<String>() { @Override public String compute() { final String name = variable.getName(); if (name == null) return null; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(variable.getProject()); VariableKind variableKind = codeStyleManager.getVariableKind(variable); return codeStyleManager.variableNameToPropertyName(name, variableKind); } }; }
public static boolean isSuppressedInStatement(@NotNull final PsiElement place, @NotNull final String toolId, @NotNull final Class<? extends PsiElement> statementClass) { return ApplicationManager.getApplication().runReadAction(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return getStatementToolSuppressedIn(place, toolId, statementClass); } }) != null; }
protected static boolean processUsagesInText(@NotNull final PsiElement element, @NotNull Collection<String> stringToSearch, @NotNull GlobalSearchScope searchScope, @NotNull Processor<UsageInfo> processor) { final TextRange elementTextRange = ApplicationManager.getApplication().runReadAction(new NullableComputable<TextRange>() { @Override public TextRange compute() { if (!element.isValid() || element instanceof PsiCompiledElement) return null; return element.getTextRange(); } }); UsageInfoFactory factory = new UsageInfoFactory() { @Override public UsageInfo createUsageInfo(@NotNull PsiElement usage, int startOffset, int endOffset) { if (elementTextRange != null && usage.getContainingFile() == element.getContainingFile() && elementTextRange.contains(startOffset) && elementTextRange.contains(endOffset)) { return null; } PsiReference someReference = usage.findReferenceAt(startOffset); if (someReference != null) { PsiElement refElement = someReference.getElement(); for (PsiReference ref : PsiReferenceService.getService().getReferences(refElement, new PsiReferenceService.Hints(element, null))) { if (element.getManager().areElementsEquivalent(ref.resolve(), element)) { TextRange range = ref.getRangeInElement().shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset()); return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true); } } } return new UsageInfo(usage, startOffset, endOffset, true); } }; for (String s : stringToSearch) { if (!PsiSearchHelperImpl.processTextOccurrences(element, s, searchScope, processor, factory)) return false; } return true; }
@Override public TableCellRenderer getRenderer(final Item item) { return new WarningIconCellRenderer(new NullableComputable<String>() { public String compute() { return myWarnings.get(doGetItems().indexOf(item)); } }); }
@Override public PsiElement retrieve() { return ApplicationManager.getApplication().runReadAction(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return restoreFromStubIndex((PsiFileWithStubSupport)getFile(), myIndex, myElementType, false); } }); }
public String diagnoseNull() { final PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() { @Override public PsiFile compute() { return getFile(); } }); try { PsiElement element = ApplicationManager.getApplication().runReadAction(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return restoreFromStubIndex((PsiFileWithStubSupport)file, myIndex, myElementType, true); } }); return "No diagnostics, element=" + element + "@" + (element == null ? 0 : System.identityHashCode(element)); } catch (AssertionError e) { String msg = e.getMessage(); if (file == null) { msg += "\n no PSI file"; } else { msg += "\n current file stamp=" + (short)file.getModificationStamp(); } final Document document = FileDocumentManager.getInstance().getCachedDocument(myVirtualFile); if (document != null) { msg += "\n committed=" + PsiDocumentManager.getInstance(myProject).isCommitted(document); msg += "\n saved=" + !FileDocumentManager.getInstance().isDocumentUnsaved(document); } return msg; } }
@Override public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) { if (item.getObject() instanceof PsiElement) { return PsiProximityComparator.getProximity(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return item.getPsiElement(); } }, location.getCompletionParameters().getPosition(), location.getProcessingContext()); } return null; }
public boolean processUsagesInText(@NotNull final PsiElement element, @NotNull Processor<UsageInfo> processor, @NotNull GlobalSearchScope searchScope) { Collection<String> stringToSearch = ApplicationManager.getApplication().runReadAction(new NullableComputable<Collection<String>>() { @Override public Collection<String> compute() { return getStringsToSearch(element); } }); if (stringToSearch == null) return true; return FindUsagesHelper.processUsagesInText(element, stringToSearch, searchScope, processor); }
@Override public Result<PsiElement[]> compute() { PsiElement[] result = RecursionManager.doPreventingRecursion(myXincludeTag, true, new NullableComputable<PsiElement[]>() { @Override public PsiElement[] compute() { return computeInclusion(myXincludeTag); } }); return Result.create(result == null ? PsiElement.EMPTY_ARRAY : result, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); }
private Map<String, Computable<String>> buildArgumentMap(PsiMethodCallExpression expression, PsiMethod method) { Map<String, Computable<String>> result = new HashMap<String, Computable<String>>(); final PsiParameter[] parameters = method.getParameterList().getParameters(); final PsiExpression[] arguments = expression.getArgumentList().getExpressions(); for (int i = 0; i < arguments.length && i < parameters.length; i++) { final int finalI = i; result.put(parameters [i].getName(), new NullableComputable<String>() { public String compute() { return evaluate(arguments [finalI], Collections.<String, Computable<String>>emptyMap()); } }); } return result; }
@Nullable public static PsiClassType getCategoryType(@NotNull final PsiClass categoryAnnotationOwner) { return CachedValuesManager.getCachedValue(categoryAnnotationOwner, new CachedValueProvider<PsiClassType>() { @Override public Result<PsiClassType> compute() { return Result.create(inferCategoryType(categoryAnnotationOwner), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } @Nullable private PsiClassType inferCategoryType(final PsiClass aClass) { return RecursionManager.doPreventingRecursion(aClass, true, new NullableComputable<PsiClassType>() { @Nullable @Override public PsiClassType compute() { final PsiModifierList modifierList = aClass.getModifierList(); if (modifierList == null) return null; final PsiAnnotation annotation = modifierList.findAnnotation(GroovyCommonClassNames.GROOVY_LANG_CATEGORY); if (annotation == null) return null; PsiAnnotationMemberValue value = annotation.findAttributeValue("value"); if (!(value instanceof GrReferenceExpression)) return null; if ("class".equals(((GrReferenceExpression)value).getReferenceName())) value = ((GrReferenceExpression)value).getQualifier(); if (!(value instanceof GrReferenceExpression)) return null; final PsiElement resolved = ((GrReferenceExpression)value).resolve(); if (!(resolved instanceof PsiClass)) return null; String className = ((PsiClass)resolved).getQualifiedName(); if (className == null) className = ((PsiClass)resolved).getName(); if (className == null) return null; return JavaPsiFacade.getElementFactory(aClass.getProject()).createTypeByFQClassName(className, resolved.getResolveScope()); } }); } }); }
@NotNull private Pair<Boolean, GroovyResolveResult[]> resolveByShape(boolean allVariants, @Nullable GrExpression upToArgument) { if (allVariants) { return doResolveByShape(true, upToArgument); } LOG.assertTrue(upToArgument == null); return TypeInferenceHelper.getCurrentContext().getCachedValue(this, new NullableComputable<Pair<Boolean, GroovyResolveResult[]>>() { @Override public Pair<Boolean, GroovyResolveResult[]> compute() { return doResolveByShape(false, null); } }); }
@Override @Nullable public PsiType getTypeGroovy() { final GrExpression initializer = getInitializerGroovy(); GrTypeElement typeElement = getTypeElementGroovy(); PsiType declaredType = null; if (typeElement != null) { declaredType = typeElement.getType(); if (!(declaredType instanceof PsiClassType)) { return declaredType; } } if (initializer != null) { PsiType initializerType = ourGuard.doPreventingRecursion(this, true, new NullableComputable<PsiType>() { @Override public PsiType compute() { return initializer.getType(); } }); if (declaredType == null) return initializerType; if (initializerType instanceof PsiClassType && TypesUtil.isAssignable(declaredType, initializerType, this)) { final PsiClassType.ClassResolveResult initializerResult = ((PsiClassType)initializerType).resolveGenerics(); final PsiClass initializerClass = initializerResult.getElement(); if (initializerClass != null && !com.intellij.psi.util.PsiUtil.isRawSubstitutor(initializerClass, initializerResult.getSubstitutor())) { return initializerType; } } } return declaredType; }
@Nullable private PackageAnnotator.ClassCoverageInfo getClassCoverageInfo(final PsiClass aClass) { return myAnnotator.getClassCoverageInfo(ApplicationManager.getApplication().runReadAction(new NullableComputable<String>() { public String compute() { return aClass.isValid() ? aClass.getQualifiedName() : null; } })); }
@Nullable private static Trinity<String, Boolean, PsiClass> calcClassName(final SourcePosition classPosition) { return ApplicationManager.getApplication().runReadAction(new NullableComputable<Trinity<String, Boolean, PsiClass>>() { public Trinity<String, Boolean, PsiClass> compute() { final PsiClass psiClass = JVMNameUtil.getClassAt(classPosition); if(psiClass == null) { return null; } if(PsiUtil.isLocalOrAnonymousClass(psiClass)) { final PsiClass parentNonLocal = TopLevelParentClassProvider.getTopLevelParentClass(psiClass); if(parentNonLocal == null) { LOG.error("Local or anonymous class has no non-local parent"); return null; } final String parentClassName = JVMNameUtil.getNonAnonymousClassName(parentNonLocal); if(parentClassName == null) { LOG.error("The name of a parent of a local (anonymous) class is null"); return null; } return new Trinity<String, Boolean, PsiClass>(parentClassName, Boolean.FALSE, psiClass); } final String className = JVMNameUtil.getNonAnonymousClassName(psiClass); return className != null? new Trinity<String, Boolean, PsiClass>(className, Boolean.TRUE, psiClass) : null; } }); }
private static void inferMethodCallArgumentTypes(@NotNull final PsiExpression argument, final boolean forCompletion, @NotNull final PsiExpression[] args, final int index, @NotNull final PsiMethod method, @NotNull final PsiSubstitutor substitutor, @NotNull final Set<ExpectedTypeInfo> array) { LOG.assertTrue(substitutor.isValid()); PsiParameter[] parameters = method.getParameterList().getParameters(); if (!forCompletion && parameters.length != args.length) return; if (parameters.length <= index && !method.isVarArgs()) return; for (int j = 0; j < index; j++) { PsiType paramType = getParameterType(parameters[Math.min(parameters.length - 1, j)], substitutor); PsiType argType = args[j].getType(); if (argType != null && !paramType.isAssignableFrom(argType)) return; } PsiParameter parameter = parameters[Math.min(parameters.length - 1, index)]; PsiType parameterType = getParameterType(parameter, substitutor); TailType tailType = getMethodArgumentTailType(argument, index, method, substitutor, parameters); PsiType defaultType = getDefaultType(method, substitutor, parameterType, argument, args, index); ExpectedTypeInfoImpl info = createInfoImpl(parameterType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, defaultType, tailType); info.setCalledMethod(method); NullableComputable<String> propertyName = getPropertyName(parameter); info.expectedName = propertyName; array.add(info); if (index == parameters.length - 1 && parameter.isVarArgs()) { //Then we may still want to call with array argument final PsiArrayType arrayType = parameterType.createArrayType(); ExpectedTypeInfoImpl info1 = createInfoImpl(arrayType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, arrayType, tailType); info1.setCalledMethod(method); info1.expectedName = propertyName; array.add(info1); } }
public static boolean isSuppressedInStatement(final PsiElement place, final String toolId, final Class<? extends PsiElement> statementClass) { return ApplicationManager.getApplication().runReadAction(new NullableComputable<PsiElement>() { @Override public PsiElement compute() { return getStatementToolSuppressedIn(place, toolId, statementClass); } }) != null; }