use of com.intellij.lang.javascript.psi.JSCallExpression in project intellij-plugins by JetBrains.
the class AngularModulesProvider method getDependencies.
@Override
public List<Link> getDependencies(@NotNull PsiFile file) {
final Project project = file.getProject();
if (!AngularIndexUtil.hasAngularJS(project))
return null;
if (!(file instanceof JSFile))
return null;
final SmartPointerManager spm = SmartPointerManager.getInstance(project);
final List<Link> result = new ArrayList<>();
final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
final GlobalSearchScope fileScope = GlobalSearchScope.fileScope(file);
final int fileId = FileBasedIndex.getFileId(file.getVirtualFile());
StubIndex.getInstance().processAllKeys(AngularModuleIndex.KEY, processor, fileScope, new IdFilter() {
@Override
public boolean containsFileId(int id) {
return id == fileId;
}
});
for (String key : processor.getResults()) {
AngularIndexUtil.multiResolve(project, AngularModuleIndex.KEY, key, element -> {
if (!file.equals(element.getContainingFile()))
return true;
final JSCallExpression expression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
if (expression != null) {
final List<String> dependencies = AngularModuleIndex.findDependenciesInModuleDeclaration(expression);
if (dependencies != null) {
for (String dependency : dependencies) {
final JSImplicitElement resolve = AngularIndexUtil.resolve(project, AngularModuleIndex.KEY, dependency);
if (resolve != null) {
result.add(new Link(spm.createSmartPsiElementPointer(element.getNavigationElement()), spm.createSmartPsiElementPointer(resolve.getNavigationElement()), key, resolve.getName(), AngularJSIcons.AngularJS));
}
}
}
}
return true;
});
}
return result;
}
use of com.intellij.lang.javascript.psi.JSCallExpression in project intellij-plugins by JetBrains.
the class AbstractMethodBasedInspection method createVisitor.
@NotNull
@Override
protected final JSElementVisitor createVisitor(final ProblemsHolder holder, LocalInspectionToolSession session) {
if (holder == null) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
Project project = holder.getProject();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
}
return new JSElementVisitor() {
@Override
public void visitJSCallExpression(final JSCallExpression jsCallExpression) {
JSFile jsFile = null;
if (jsCallExpression != null) {
jsFile = ObjectUtils.tryCast(jsCallExpression.getContainingFile(), JSFile.class);
}
if (jsFile == null) {
return;
}
JSReferenceExpression methodExpression = ObjectUtils.tryCast(jsCallExpression.getMethodExpression(), JSReferenceExpression.class);
if (methodExpression == null) {
return;
}
boolean suitableSymbol = isSuitableElement(jsFile, jsCallExpression);
if (suitableSymbol) {
boolean resolved = isResolved(methodExpression);
if (!resolved) {
TextRange rangeInElement = TextRange.create(0, methodExpression.getTextLength());
HintWrapperQuickFix fix = new HintWrapperQuickFix(methodExpression, rangeInElement, getFix());
holder.registerProblem(methodExpression, getProblemDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, fix);
}
}
}
};
}
use of com.intellij.lang.javascript.psi.JSCallExpression in project intellij-plugins by JetBrains.
the class JsTestDriverTestCaseWithoutTestsInspection method createVisitor.
@NotNull
@Override
protected PsiElementVisitor createVisitor(ProblemsHolder holder, LocalInspectionToolSession session) {
JSFile jsFile = ObjectUtils.tryCast(holder.getFile(), JSFile.class);
if (jsFile == null) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
Project project = holder.getProject();
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
}
VirtualFile virtualFile = jsFile.getVirtualFile();
if (virtualFile != null) {
boolean inScope = JstdLibraryUtil.isFileInJstdLibScope(project, virtualFile);
if (!inScope) {
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
}
JstdTestFileStructure testFileStructure = JstdTestFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
for (JstdTestCaseStructure structure : testFileStructure.getTestCaseStructures()) {
if (structure.getTestCount() == 0) {
JSCallExpression callExpression = structure.getEnclosingCallExpression();
if (callExpression.isValid()) {
JSReferenceExpression methodExpression = ObjectUtils.tryCast(callExpression.getMethodExpression(), JSReferenceExpression.class);
if (methodExpression != null) {
int startOffset = methodExpression.getStartOffsetInParent();
TextRange rangeInElement = TextRange.create(startOffset, startOffset + methodExpression.getTextLength());
holder.registerProblem(callExpression, "TestCase has no tests. Tests names should have 'test' prefix.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, LocalQuickFix.EMPTY_ARRAY);
}
}
}
}
return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
use of com.intellij.lang.javascript.psi.JSCallExpression in project intellij-plugins by JetBrains.
the class JstdAssertionFrameworkLineMarkerProvider method getQUnitLineMarkerInfo.
@Nullable
private static LineMarkerInfo getQUnitLineMarkerInfo(@NotNull JSFile jsFile, @NotNull PsiElement element) {
QUnitFileStructure qunitFileStructure = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
if (element instanceof JSCallExpression) {
JSCallExpression callExpression = (JSCallExpression) element;
String testElementName = qunitFileStructure.getNameByPsiElement(callExpression);
if (testElementName == null) {
return null;
}
return createLineMarkerFromElement(element, testElementName);
}
return null;
}
use of com.intellij.lang.javascript.psi.JSCallExpression in project intellij-plugins by JetBrains.
the class JstdGenerateNewTestAction method buildGenerator.
@Nullable
private static Runnable buildGenerator(@NotNull JstdTestFileStructure fileStructure, @NotNull GenerateActionContext context) {
int caretOffset = context.getDocumentCaretOffset();
JstdTestCaseStructure jstdTestCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
if (jstdTestCaseStructure != null) {
JSObjectLiteralExpression testsObjectLiteral = jstdTestCaseStructure.getTestsObjectsLiteral();
if (testsObjectLiteral != null) {
return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
} else {
if (jstdTestCaseStructure.getTestCount() == 0) {
JSCallExpression callExpression = jstdTestCaseStructure.getEnclosingCallExpression();
JSArgumentList argumentList = callExpression.getArgumentList();
JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
if (arguments.length == 1 && arguments[0] != null) {
return new TestGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
}
}
}
} else {
for (JstdTestCaseStructure testCaseStructure : fileStructure.getTestCaseStructures()) {
JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
}
}
}
return null;
}
Aggregations