com.intellij.lang.javascript.JSTokenTypes Java Examples
The following examples show how to use
com.intellij.lang.javascript.JSTokenTypes.
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: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 6 votes |
private static ImmutableList<JSFile> jsFilesFromDtsSymbol( ExecutionRootPathResolver pathResolver, LocalFileSystem lfs, PsiManager psiManager, PsiElement dtsElement) { while (dtsElement != null && !(dtsElement instanceof PsiFile)) { PsiElement comment = PsiTreeUtil.findSiblingBackward(dtsElement, JSTokenTypes.END_OF_LINE_COMMENT, null); if (comment != null) { Matcher matcher = SYMBOL_GENERATED_FROM_JS_COMMENT.matcher(comment.getText()); if (matcher.find()) { JSFile file = pathToJsFile(pathResolver, lfs, psiManager, matcher.group(1)); return file != null ? ImmutableList.of(file) : ImmutableList.of(); } } dtsElement = dtsElement.getParent(); } return ImmutableList.of(); }
Example #2
Source File: DojoUnresolvedVariableInspection.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public boolean isSuppressedFor(@NotNull PsiElement element) { Project project = element.getProject(); DojoSettings settings = ServiceManager.getService(project, DojoSettings.class); if(!settings.isNeedsMoreDojoEnabled()) { return super.isSuppressedFor(element); } if(element instanceof LeafPsiElement) { LeafPsiElement leafPsiElement = (LeafPsiElement) element; if(leafPsiElement.getElementType() == JSTokenTypes.IDENTIFIER && leafPsiElement.getParent() != null && leafPsiElement.getParent().getFirstChild() instanceof JSThisExpression) { return AttachPointResolver.getGotoDeclarationTargets(element, 0, null).length > 0 || super.isSuppressedFor(element); } } return super.isSuppressedFor(element); }
Example #3
Source File: SendToEndAction.java From needsmoredojo with Apache License 2.0 | 6 votes |
private PsiElement moveImportToEnd(JSArrayLiteralExpression imports, JSParameterList parameters, String module, String parameter, PsiElement lastDefine, PsiElement lastParameter) { // TODO move to AMDPsiUtil if we need to reuse this in the future PsiElement lastChild = imports.getChildren()[imports.getChildren().length-1]; if(lastDefine != null) { lastChild = lastDefine; } PsiElement element = imports.addAfter(JSChangeUtil.createExpressionFromText(imports.getProject(), String.format("%s", module)).getPsi(), lastChild); imports.getNode().addLeaf(JSTokenTypes.COMMA, ",", element.getNode()); imports.getNode().addLeaf(JSTokenTypes.WHITE_SPACE, "\n", element.getNode()); PsiElement lastParameterChild = parameters.getChildren()[parameters.getChildren().length-1]; if(lastParameter != null) { lastParameterChild = lastParameter; } PsiElement parameterElement = parameters.addAfter(JSChangeUtil.createExpressionFromText(imports.getProject(), String.format("%s", parameter)).getPsi(), lastParameterChild); parameters.getNode().addLeaf(JSTokenTypes.COMMA, ",", parameterElement.getNode()); return element; }
Example #4
Source File: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 5 votes |
private static boolean isJsIdentifier(PsiElement sourceElement) { return Optional.of(sourceElement) .filter(e -> e.getLanguage().is(JavascriptLanguage.INSTANCE)) .filter(LeafPsiElement.class::isInstance) .map(LeafPsiElement.class::cast) .filter(e -> e.getElementType().equals(JSTokenTypes.IDENTIFIER)) .isPresent(); }
Example #5
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
private static void parsePackageObject(TreeElement node, Package p) { if (null == node) { return; } if (node.getElementType() == JSElementTypes.PROPERTY) { TreeElement identifier = (TreeElement) node.findChildByType(JSTokenTypes.IDENTIFIER); String identifierName = null; if (null != identifier) { identifierName = identifier.getText(); } else { TreeElement identifierString = (TreeElement) node.findChildByType(JSTokenTypes.STRING_LITERAL); if (null != identifierString) { identifierName = dequote(identifierString.getText()); } } if (null != identifierName) { if (identifierName.equals("name")) { p.name = getJSPropertyLiteralValue(node); } else if (identifierName.equals("location")) { p.location = getJSPropertyLiteralValue(node); } else if (identifierName.equals("main")) { p.main = getJSPropertyLiteralValue(node); } } } TreeElement next = node.getTreeNext(); parsePackageObject(next, p); }
Example #6
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
protected String getJSPropertyName(TreeElement jsProperty) { TreeElement identifier = (TreeElement) jsProperty.findChildByType( TokenSet.create(JSTokenTypes.IDENTIFIER, JSTokenTypes.STRING_LITERAL, JSTokenTypes.PUBLIC_KEYWORD) ); String identifierName = null; if (null != identifier) { identifierName = dequote(identifier.getText()); } return identifierName; }
Example #7
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 5 votes |
public void parseMainJsFile(TreeElement node) { TreeElement firstChild = node.getFirstChildNode(); if (firstChild != null) { parseMainJsFile(firstChild); } TreeElement nextNode = node.getTreeNext(); if (nextNode != null) { parseMainJsFile(nextNode); } if (node.getElementType() == JSTokenTypes.IDENTIFIER) { if (node.getText().equals("requirejs") || node.getText().equals("require")) { TreeElement treeParent = node.getTreeParent(); if (null != treeParent) { ASTNode firstTreeChild = treeParent.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION); TreeElement nextTreeElement = treeParent.getTreeNext(); if (null != firstTreeChild) { parseRequirejsConfig((TreeElement) firstTreeChild .getFirstChildNode() ); } else if (null != nextTreeElement && nextTreeElement.getElementType() == JSTokenTypes.DOT) { nextTreeElement = nextTreeElement.getTreeNext(); if (null != nextTreeElement && nextTreeElement.getText().equals("config")) { treeParent = nextTreeElement.getTreeParent(); findAndParseConfig(treeParent); } } else { findAndParseConfig(treeParent); } } } } }
Example #8
Source File: ESLintConfigFileUtil.java From eslint-plugin with MIT License | 5 votes |
public static boolean isStringLiteral(@NotNull PsiElement element) { if (element instanceof ASTNode) { ASTNode node = (ASTNode) element; return node.getElementType().equals(JSTokenTypes.STRING_LITERAL); } return false; }
Example #9
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 #10
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
public static boolean isStringLiteral(@NotNull PsiElement element) { if (element instanceof ASTNode) { ASTNode node = (ASTNode) element; return node.getElementType().equals(JSTokenTypes.STRING_LITERAL); } return false; }
Example #11
Source File: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public JSExpression getCollection() { final ASTNode myNode = getNode(); final ASTNode secondExpression = myNode.findChildByType( JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) ); return secondExpression != null ? (JSExpression) secondExpression.getPsi() : null; }
Example #12
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
public static boolean isStringLiteral(@NotNull PsiElement element) { if (element instanceof ASTNode) { ASTNode node = (ASTNode) element; return node.getElementType().equals(JSTokenTypes.STRING_LITERAL); } return false; }
Example #13
Source File: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public JSExpression getCollection() { final ASTNode myNode = getNode(); final ASTNode secondExpression = myNode.findChildByType( JSElementTypes.EXPRESSIONS, myNode.findChildByType(JSTokenTypes.IN_KEYWORD) ); return secondExpression != null ? (JSExpression) secondExpression.getPsi() : null; }
Example #14
Source File: RTLexer.java From react-templates-plugin with MIT License | 4 votes |
public RTLexer() { super(new FlexAdapter(new _RTLexer((Reader) null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); }
Example #15
Source File: RTSyntaxHighlighterFactory.java From react-templates-plugin with MIT License | 4 votes |
public RTSyntaxHighlighter() { super(RTLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(JSTokenTypes.IN_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); // myKeysMap.put(RTTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); }
Example #16
Source File: GraphQLTemplateFragmentLanguageInjector.java From js-graphql-intellij-plugin with MIT License | 4 votes |
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if(GraphQLLanguageInjectionUtil.isJSGraphQLLanguageInjectionTarget(context)) { final JSStringTemplateExpression template = (JSStringTemplateExpression)context; final TextRange graphQlTextRange = GraphQLLanguageInjectionUtil.getGraphQLTextRange(template); if(graphQlTextRange.isEmpty()) { // all whitespace return; } registrar.startInjecting(GraphQLLanguage.INSTANCE); final StringBuilder sb = new StringBuilder(); final TextRange[] stringRanges = template.getStringRanges(); int stringIndex = 0; boolean insideTemplate = false; for (ASTNode astNode : template.getNode().getChildren(null)) { if(astNode.getElementType() == JSTokenTypes.BACKQUOTE) { insideTemplate = true; continue; } if(astNode.getElementType() == JSTokenTypes.STRING_TEMPLATE_PART) { registrar.addPlace(sb.toString(), "", (PsiLanguageInjectionHost) template, stringRanges[stringIndex]); stringIndex++; sb.setLength(0); } else if(insideTemplate) { sb.append(astNode.getText()); } } registrar.doneInjecting(); // update graphql config notifications final VirtualFile virtualFile = context.getContainingFile().getVirtualFile(); if(virtualFile != null && !ApplicationManager.getApplication().isUnitTestMode()) { EditorNotifications.getInstance(context.getProject()).updateNotifications(virtualFile); } } }
Example #17
Source File: RTLexer.java From react-templates-plugin with MIT License | 4 votes |
public RTLexer() { super(new FlexAdapter(new _RTLexer((Reader) null)), TokenSet.create(JSTokenTypes.STRING_LITERAL)); }
Example #18
Source File: RequirejsProjectComponent.java From WebStormRequireJsPlugin with MIT License | 4 votes |
public void parseRequirejsConfig(TreeElement node) { if (null == node) { return ; } try { if (node.getElementType() == JSElementTypes.PROPERTY) { TreeElement identifier = (TreeElement) node.findChildByType(JSTokenTypes.IDENTIFIER); String identifierName = null; if (null != identifier) { identifierName = identifier.getText(); } else { TreeElement identifierString = (TreeElement) node.findChildByType(JSTokenTypes.STRING_LITERAL); if (null != identifierString) { identifierName = dequote(identifierString.getText()); } } if (null != identifierName) { if (identifierName.equals("baseUrl")) { String baseUrl = null; if (!settings.overrideBaseUrl) { ASTNode baseUrlNode = node .findChildByType(JSElementTypes.LITERAL_EXPRESSION); if (null != baseUrlNode) { baseUrl = dequote(baseUrlNode.getText()); } } else { LOG.info("baseUrl override is enabled, overriding with '" + settings.baseUrl + "'"); baseUrl = settings.baseUrl; } if (null != baseUrl) { LOG.info("Setting baseUrl to '" + baseUrl + "'"); setBaseUrl(baseUrl); packageConfig.baseUrl = baseUrl; } else { LOG.debug("BaseUrl not set"); } } else if (identifierName.equals("paths")) { ASTNode pathsNode = node .findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION); if (null != pathsNode) { parseRequireJsPaths( (TreeElement) pathsNode.getFirstChildNode() ); } } else if (identifierName.equals("packages")) { TreeElement packages = (TreeElement) node.findChildByType(JSElementTypes.ARRAY_LITERAL_EXPRESSION); LOG.debug("parsing packages"); parsePackages(packages); LOG.debug("parsing packages done, found " + packageConfig.packages.size() + " packages"); } else if (identifierName.equals("map")) { TreeElement mapElement = (TreeElement) node.findChildByType(JSElementTypes.OBJECT_LITERAL_EXPRESSION); parseMapsConfig(mapElement); } } } } catch (NullPointerException exception) { LOG.error(exception.getMessage(), exception); } TreeElement next = node.getTreeNext(); if (null != next) { parseRequirejsConfig(next); } }
Example #19
Source File: RTSyntaxHighlighterFactory.java From react-templates-plugin with MIT License | 4 votes |
public RTSyntaxHighlighter() { super(RTLanguage.INSTANCE.getOptionHolder()); myKeysMap.put(JSTokenTypes.AS_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); myKeysMap.put(JSTokenTypes.IN_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); // myKeysMap.put(RTTokenTypes.TRACK_BY_KEYWORD, DefaultLanguageHighlighterColors.KEYWORD); }
Example #20
Source File: BlazeJavaScriptTestRunLineMarkerContributor.java From intellij with Apache License 2.0 | 4 votes |
@Nullable @Override public Info getInfo(PsiElement element) { if (!enableJavascriptRunLineMarkers.getValue()) { return null; } JSFile file = Optional.of(element) .filter(PsiElement::isValid) .filter(LeafPsiElement.class::isInstance) .map(LeafPsiElement.class::cast) .filter(e -> e.getElementType().equals(JSTokenTypes.IDENTIFIER)) .map(PsiElement::getContainingFile) .filter(JSFile.class::isInstance) .map(JSFile.class::cast) .orElse(null); if (file == null) { return null; } Collection<Label> labels = getWrapperTests(file); if (labels.isEmpty()) { return null; } JsTestElementPath jasmineTestElement = CachedValuesManager.getCachedValue( file, () -> Result.create( JasmineFileStructureBuilder.getInstance().buildTestFileStructure(file), file)) .findTestElementPath(element); if (jasmineTestElement != null) { return new Info( getJasmineTestIcon(file.getProject(), labels, jasmineTestElement), null, ExecutorAction.getActions()); } PsiElement parent = element.getParent(); if (parent instanceof JSFunction && element.getText().startsWith("test")) { return new Info( getClosureTestIcon(file.getProject(), labels, file, (JSFunction) parent), null, ExecutorAction.getActions()); } return null; }