com.intellij.lang.javascript.psi.JSReferenceExpression Java Examples
The following examples show how to use
com.intellij.lang.javascript.psi.JSReferenceExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsPsiHelper.java From idea-php-dotenv-plugin with MIT License | 6 votes |
/** * @param psiElement checking element * @return true if this is process.env.*** variable */ static boolean checkPsiElement(@NotNull PsiElement psiElement) { if(!(psiElement instanceof LeafPsiElement)) { return false; } IElementType elementType = ((LeafPsiElement) psiElement).getElementType(); if(!elementType.toString().equals("JS:IDENTIFIER")) { return false; } PsiElement parent = psiElement.getParent(); if(!(parent instanceof JSReferenceExpression)) { return false; } return ((JSReferenceExpression) parent).getCanonicalText().startsWith("process.env"); }
Example #2
Source File: AMDValidator.java From needsmoredojo with Apache License 2.0 | 6 votes |
public static boolean elementIsAttachPoint(PsiElement element) { /* It's hard to detect when an element is an attach point, because of the use of this inside other functions this.attachpoint that.attachpoint ideally we would parse the template file in the beginning and cache all of the attach points, maybe that's a todo item... */ if(element == null || element.getParent() == null || !(element.getParent() instanceof JSReferenceExpression)) { return false; } // we can exclude JSCallExpressions at least because you will never reference an attach point like // this.attachpoint(...) if(element.getParent().getParent() instanceof JSCallExpression) { return false; } return true; }
Example #3
Source File: RequirejsPsiReferenceProvider.java From WebStormRequireJsPlugin with MIT License | 6 votes |
public boolean isDefineFirstCollection(PsiElement element) { PsiElement jsArrayLiteral = element.getParent(); if (null != jsArrayLiteral && jsArrayLiteral instanceof JSArrayLiteralExpression) { PsiElement jsArgumentList = jsArrayLiteral.getParent(); if (null != jsArgumentList && jsArgumentList instanceof JSArgumentList) { PsiElement jsReferenceExpression = jsArgumentList.getPrevSibling(); if (null != jsReferenceExpression && jsReferenceExpression instanceof JSReferenceExpression) { if (jsReferenceExpression.getText().equals(Settings.REQUIREJS_DEFINE_FUNCTION_NAME)) { return true; } } } } return false; }
Example #4
Source File: JsEnvironmentCallsVisitor.java From idea-php-dotenv-plugin with MIT License | 5 votes |
@Override public void visitElement(PsiElement element) { if(element instanceof JSReferenceExpression) { String possibleKey = JsPsiHelper.checkReferenceExpression((JSReferenceExpression) element); if(possibleKey != null) { collectedItems.add(new KeyUsagePsiElement(possibleKey, element)); } } super.visitElement(element); }
Example #5
Source File: JsPsiHelper.java From idea-php-dotenv-plugin with MIT License | 5 votes |
/** * Checks whole process.env.SOME_KEY reference element * @param referenceExpression checking expression * @return null or Environment key */ @Nullable static String checkReferenceExpression(@NotNull JSReferenceExpression referenceExpression) { String text = referenceExpression.getCanonicalText(); if(!text.startsWith("process.env.") || text.length() < 13) { return null; } return text.substring(12); }
Example #6
Source File: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 5 votes |
private static ImmutableList<PsiElement> resolveToDts(JSReferenceExpression referenceExpression) { return Stream.of(referenceExpression) .map(e -> e.multiResolve(false)) .flatMap(Arrays::stream) .filter(ResolveResult::isValidResult) .map(ResolveResult::getElement) .filter(Objects::nonNull) .flatMap( e -> e instanceof ES6ImportedBinding ? ((ES6ImportedBinding) e).findReferencedElements().stream() : Stream.of(e)) .collect(toImmutableList()); }
Example #7
Source File: GraphQLLanguageInjectionUtil.java From js-graphql-intellij-plugin with MIT License | 5 votes |
public static boolean isJSGraphQLLanguageInjectionTarget(PsiElement host, @Nullable Ref<String> envRef) { if (host instanceof JSStringTemplateExpression) { JSStringTemplateExpression template = (JSStringTemplateExpression) host; // check if we're a graphql tagged template final JSReferenceExpression tagExpression = PsiTreeUtil.getPrevSiblingOfType(template, JSReferenceExpression.class); if (tagExpression != null) { final String tagText = tagExpression.getText(); if (SUPPORTED_TAG_NAMES.contains(tagText)) { if (envRef != null) { envRef.set(getEnvironmentFromTemplateTag(tagText, host)); } return true; } final String builderTailName = tagExpression.getReferenceName(); if(builderTailName != null && SUPPORTED_TAG_NAMES.contains(builderTailName)) { // a builder pattern that ends in a tagged template, e.g. someQueryAPI.graphql`` if(envRef != null) { envRef.set(getEnvironmentFromTemplateTag(builderTailName, host)); } return true; } } // also check for "manual" language=GraphQL injection comments final GraphQLCommentBasedInjectionHelper commentBasedInjectionHelper = ServiceManager.getService(GraphQLCommentBasedInjectionHelper.class); if (commentBasedInjectionHelper != null) { return commentBasedInjectionHelper.isGraphQLInjectedUsingComment(host, envRef); } } return false; }
Example #8
Source File: UnityScriptEventFunctionLineMarkerProvider.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element) { if(element.getNode().getElementType() == JSTokenTypes.IDENTIFIER && element.getParent() instanceof JSReferenceExpression && element.getParent().getParent() instanceof JSFunction) { UnityFunctionManager functionManager = UnityFunctionManager.getInstance(); Map<String, UnityFunctionManager.FunctionInfo> map = functionManager.getFunctionsByType().get(Unity3dTypes.UnityEngine.MonoBehaviour); if(map == null) { return null; } UnityFunctionManager.FunctionInfo functionInfo = map.get(element.getText()); if(functionInfo == null) { return null; } Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class); if(extension == null) { return null; } JSFunction jsFunction = (JSFunction) element.getParent().getParent(); if(jsFunction.getParent() instanceof JSFile) { if(!isEqualParameters(functionInfo.getParameters(), jsFunction)) { return null; } return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(functionInfo.getDescription()), null, GutterIconRenderer.Alignment.LEFT); } } return null; }
Example #9
Source File: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 4 votes |
@Nullable @Override public PsiElement[] getGotoDeclarationTargets( @Nullable PsiElement sourceElement, int offset, Editor editor) { if (!typescriptGotoJavascript.getValue() || sourceElement == null || !isJsIdentifier(sourceElement) || !(sourceElement.getContainingFile().getLanguage() instanceof TypeScriptLanguageDialect)) { return null; } Project project = sourceElement.getProject(); BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); if (!Blaze.isBlazeProject(project) || projectData == null || !projectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.JAVASCRIPT) || !projectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.TYPESCRIPT)) { return null; } JSReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(sourceElement, JSReferenceExpression.class); boolean isConstructor; Collection<PsiElement> resolvedToDts; if (referenceExpression != null) { isConstructor = referenceExpression.getParent() instanceof JSNewExpression; resolvedToDts = resolveToDts(referenceExpression); } else if (sourceElement.getParent() instanceof ES6ImportedBinding) { // The symbols in import statements aren't reference expressions. E.g., // import {Foo} from 'goog:foo.bar.Foo'; ES6ImportedBinding parent = (ES6ImportedBinding) sourceElement.getParent(); isConstructor = false; resolvedToDts = parent.findReferencedElements(); } else { return null; } PsiManager psiManager = PsiManager.getInstance(project); LocalFileSystem lfs = VirtualFileSystemProvider.getInstance().getSystem(); ExecutionRootPathResolver pathResolver = ExecutionRootPathResolver.fromProject(project); if (pathResolver == null) { return null; } return resolvedToDts.stream() .map(e -> resolveToJs(pathResolver, lfs, psiManager, isConstructor, e)) .flatMap(Collection::stream) .toArray(PsiElement[]::new); }
Example #10
Source File: RTFilterExpression.java From react-templates-plugin with MIT License | 4 votes |
public JSReferenceExpression getFilterName() { return (JSReferenceExpression) getFirstChild(); }
Example #11
Source File: RTFilterExpression.java From react-templates-plugin with MIT License | 4 votes |
public JSReferenceExpression getFilterName() { return (JSReferenceExpression) getFirstChild(); }
Example #12
Source File: MethodGotoDeclarationHandler.java From needsmoredojo with Apache License 2.0 | 4 votes |
@Nullable @Override public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) { if(psiElement == null || !psiElement.getLanguage().equals(Language.findLanguageByID("JavaScript"))) { return new PsiElement[0]; } if(!isEnabled(psiElement.getProject())) { return new PsiElement[0]; } if(!(psiElement.getParent() != null && psiElement.getParent() instanceof JSReferenceExpression)) { return new PsiElement[0]; } if(psiElement.getPrevSibling() == null || psiElement.getPrevSibling().getPrevSibling() == null) { return new PsiElement[0]; } if(!(psiElement.getPrevSibling().getPrevSibling() instanceof JSReferenceExpression) && !(psiElement.getPrevSibling().getPrevSibling() instanceof JSThisExpression)) { return new PsiElement[0]; } PsiElement prevPrevSibling = psiElement.getPrevSibling().getPrevSibling(); /** * this case occurs when the user is trying to navigate ... declaration on a method off of this. At this point * we can search its base classes for the method in question. */ if(prevPrevSibling instanceof JSThisExpression) { if(psiElement.getText().equals("inherited")) { return new PsiElement[0]; } // if the method is defined in this file, return it instead of searching other files. Rely on this.inherited // references for that behavior. PsiElement resolvedInThisFile = AMDPsiUtil.fileHasMethod(psiElement.getContainingFile(), psiElement.getText(), false); if(resolvedInThisFile != null) { return new PsiElement[] { resolvedInThisFile }; } else { Set<PsiElement> resolvedMethods = AMDPsiUtil.resolveInheritedMethod(psiElement.getContainingFile(), psiElement.getProject(), psiElement.getText(), 0); return resolvedMethods.toArray(new PsiElement[resolvedMethods.size()]); } } /** * the second case is when the user is referencing a method off of another dojo module. In this case, we * use a less accurate approach because the module in question might not be a standard module that defines * its methods in a nice object literal. */ else { JSReferenceExpression referencedDefine = (JSReferenceExpression) prevPrevSibling; PsiElement resolvedDefine = AMDPsiUtil.resolveReferencedDefine(referencedDefine); if(resolvedDefine == null) { return new PsiElement[0]; } DojoModuleFileResolver resolver = new DojoModuleFileResolver(); PsiFile resolvedFile = resolver.resolveReferencedFile(psiElement.getProject(), resolvedDefine); if(resolvedFile == null) { return new PsiElement[0]; } String methodName = psiElement.getText(); PsiElement method = AMDPsiUtil.fileHasMethod(resolvedFile, methodName, true); if(method != null) { // found it! return new PsiElement[] { method }; } else { // didn't find it! return new PsiElement[0]; } } }