use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class AngularJSTargetElementEvaluator method getElementByReference.
@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
if (ref instanceof JSTextReference) {
final PsiElement element = ref.getElement();
final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
final JSExpression expression = call != null ? call.getMethodExpression() : null;
if (expression instanceof JSReferenceExpression) {
JSReferenceExpression callee = (JSReferenceExpression) expression;
JSExpression qualifier = callee.getQualifier();
if (qualifier != null && AngularJSIndexingHandler.INTERESTING_METHODS.contains(callee.getReferencedName()) && AngularIndexUtil.hasAngularJS(element.getProject())) {
return element;
}
}
}
return null;
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class JstdResolveTest method testResolveTestCaseFunction.
public void testResolveTestCaseFunction() throws Exception {
String fileText = "Test<ref>Case('', {});";
JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js");
final PsiElement resolved = doResolve(ref);
assertTrue(resolved instanceof JSFunction);
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class FlexReferenceImporter method doAutoImportReferenceAt.
private static boolean doAutoImportReferenceAt(final Editor editor, final PsiFile file, final int offset) {
if (!ActionScriptAutoImportOptionsProvider.isAddUnambiguousImportsOnTheFly())
return false;
if (!(file instanceof JSFile) || file.getLanguage() != JavaScriptSupportLoader.ECMA_SCRIPT_L4)
return false;
Document document = editor.getDocument();
int lineNumber = document.getLineNumber(offset);
int startOffset = document.getLineStartOffset(lineNumber);
int endOffset = document.getLineEndOffset(lineNumber);
List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(file, startOffset, endOffset);
for (PsiElement element : elements) {
if (element instanceof JSReferenceExpression && ((JSReferenceExpression) element).getQualifier() == null) {
if (((JSReferenceExpression) element).multiResolve(false).length == 0) {
new AddImportECMAScriptClassOrFunctionAction(editor, (PsiPolyVariantReference) element, true).execute();
return true;
}
}
}
return false;
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression in project intellij-plugins by JetBrains.
the class AngularMessageFormatCompletion method messageFormatCompletion.
static boolean messageFormatCompletion(CompletionParameters parameters, CompletionResultSet result) {
final PsiElement originalPosition = parameters.getOriginalPosition();
if (originalPosition == null)
return false;
final PsiElement parent = originalPosition.getParent();
if (parent instanceof JSReferenceExpression && parent.getParent() instanceof JSCommaExpression) {
final PsiElement[] children = parent.getParent().getChildren();
if (children.length >= 2 && children[1] == parent) {
messageFormatExtensions(result);
return true;
}
}
if (parent instanceof AngularJSMessageFormatExpression) {
final AngularJSMessageFormatExpression amfe = (AngularJSMessageFormatExpression) parent;
if (originalPosition == amfe.getExtensionTypeElement()) {
messageFormatExtensions(result);
return true;
}
if (originalPosition.getNode().getElementType() == AngularJSElementTypes.MESSAGE_FORMAT_SELECTION_KEYWORD) {
messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) parent).getExtensionType(), result);
return true;
}
if (originalPosition.getNode().getElementType() == JSTokenTypes.WHITE_SPACE) {
if (originalPosition.getNextSibling() != null && originalPosition.getNextSibling().getNode().getElementType() == AngularJSElementTypes.MESSAGE_FORMAT_SELECTION_KEYWORD || originalPosition.getPrevSibling() != null && originalPosition.getPrevSibling().getNode().getElementType() == JSTokenTypes.RBRACE) {
messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) parent).getExtensionType(), result);
return true;
}
}
}
final PsiElement sibling = originalPosition.getPrevSibling();
if (sibling instanceof AngularJSMessageFormatExpression) {
messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) sibling).getExtensionType(), result);
} else if (sibling instanceof JSExpressionStatement && sibling.getFirstChild() instanceof AngularJSMessageFormatExpression) {
messageFormatSelectionKeywords(((AngularJSMessageFormatExpression) sibling.getFirstChild()).getExtensionType(), result);
}
return false;
}
use of com.intellij.lang.javascript.psi.JSReferenceExpression 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;
}
Aggregations