com.intellij.lang.javascript.psi.JSProperty Java Examples
The following examples show how to use
com.intellij.lang.javascript.psi.JSProperty.
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: BlazeTypescriptGotoDeclarationHandlerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testGotoEnum() { configureUserTs( "import ESSixClass from 'goog:foo.bar.ESSixClass';", // "ESSixClass.E<caret>num.F<caret>OO;"); PsiElement esSixClassEnum = getElementUnderCaret(0); assertThat(esSixClassEnum).isInstanceOf(JSDefinitionExpression.class); assertThat(esSixClassEnum.getText()).isEqualTo("foo.bar.ESSixClass.Enum"); assertThat(esSixClassEnum.getParent().getText()) .isEqualTo( String.join( "\n", // "foo.bar.ESSixClass.Enum = {", " FOO: 0,", "}")); PsiElement esSixClassEnumFoo = getElementUnderCaret(1); assertThat(esSixClassEnumFoo).isInstanceOf(JSProperty.class); assertThat(esSixClassEnumFoo.getText()).isEqualTo("FOO: 0"); }
Example #2
Source File: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 5 votes |
private static ImmutableList<? extends JSQualifiedNamedElement> getResolveCandidates( PsiElement dtsElement, ImmutableList<JSFile> jsFiles) { if (dtsElement instanceof TypeScriptClass) { return Stream.concat( findChildrenOfType(jsFiles, JSClass.class).stream(), // Apparently you can declare a JS class with just a constructor function and // attach some properties to it. findChildrenOfType(jsFiles, JSFunction.class).stream()) .collect(toImmutableList()); } else if (dtsElement instanceof TypeScriptFunction) { TypeScriptFunction dtsFunction = (TypeScriptFunction) dtsElement; return findChildrenOfType(jsFiles, JSFunction.class).stream() .filter(f -> staticModifierEquals(f, dtsFunction)) .collect(toImmutableList()); } else if (dtsElement instanceof TypeScriptEnum) { return findChildrenOfType(jsFiles, JSObjectLiteralExpression.class).stream() .map(PsiElement::getParent) .filter(JSAssignmentExpression.class::isInstance) .map(PsiElement::getFirstChild) .filter(JSDefinitionExpression.class::isInstance) .map(JSDefinitionExpression.class::cast) .collect(toImmutableList()); } else if (dtsElement instanceof TypeScriptEnumField) { return findChildrenOfType(jsFiles, JSProperty.class); } return ImmutableList.of(); }
Example #3
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
@Nullable public static JSProperty getProperty(@NotNull PsiElement position) { JSProperty property = PsiTreeUtil.getParentOfType(position, JSProperty.class, false); if (property != null) { JSObjectLiteralExpression objectLiteralExpression = ObjectUtils.tryCast(property.getParent(), JSObjectLiteralExpression.class); if (objectLiteralExpression != null) { return property; } } return null; }
Example #4
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
@Nullable public static PsiElement getStringLiteral(@NotNull JSProperty property) { PsiElement firstElement = property.getFirstChild(); if (firstElement != null && isStringLiteral(firstElement)) { return firstElement; } return null; }
Example #5
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
@Nullable public static JSProperty getProperty(@NotNull PsiElement position) { JSProperty property = PsiTreeUtil.getParentOfType(position, JSProperty.class, false); if (property != null) { JSObjectLiteralExpression objectLiteralExpression = ObjectUtils.tryCast(property.getParent(), JSObjectLiteralExpression.class); if (objectLiteralExpression != null) { return property; } } return null; }
Example #6
Source File: RTFileUtil.java From react-templates-plugin with MIT License | 5 votes |
@Nullable public static PsiElement getStringLiteral(@NotNull JSProperty property) { PsiElement firstElement = property.getFirstChild(); if (firstElement != null && isStringLiteral(firstElement)) { return firstElement; } return null; }
Example #7
Source File: ESLintConfigFileUtil.java From eslint-plugin with MIT License | 5 votes |
@Nullable public static JSProperty getProperty(@NotNull PsiElement position) { JSProperty property = PsiTreeUtil.getParentOfType(position, JSProperty.class, false); if (property != null) { JSObjectLiteralExpression objectLiteralExpression = ObjectUtils.tryCast(property.getParent(), JSObjectLiteralExpression.class); if (objectLiteralExpression != null) { return property; } } return null; }
Example #8
Source File: ESLintConfigFileUtil.java From eslint-plugin with MIT License | 5 votes |
@Nullable public static PsiElement getStringLiteral(@NotNull JSProperty property) { PsiElement firstElement = property.getFirstChild(); if (firstElement != null && isStringLiteral(firstElement)) { return firstElement; } return null; }
Example #9
Source File: MockJSObjectLiteralExpression.java From needsmoredojo with Apache License 2.0 | 5 votes |
@Override public JSProperty[] getProperties() { List<JSProperty> props = new ArrayList<JSProperty>(); for(Map.Entry<String, String> entry : properties.entrySet()) { JSProperty property = mock(JSProperty.class); // TODO props.add(property); } return props.toArray(new JSProperty[0]); }
Example #10
Source File: BlazeTypescriptGotoDeclarationHandler.java From intellij with Apache License 2.0 | 4 votes |
private static boolean jsIsStatic(JSFunction jsFunction) { if (jsFunction.getParent() instanceof JSAssignmentExpression) { // pre-ES6 prototype assignment based classes // Class.foo = function() {}; <- static // Class.prototype.bar = function() {}; <- non-static return Optional.of(jsFunction) .map(PsiElement::getParent) .map(PsiElement::getFirstChild) .filter(JSDefinitionExpression.class::isInstance) .filter(d -> !d.getText().contains(".prototype.")) .isPresent(); } else if (jsFunction.getParent() instanceof JSProperty) { // goog.defineClass(..., { // foo: function() {}, <--- JSFunction (non-static) // v----------------------- JSProperty // statics: { <------------ JSObjectLiteralExpression // v--------------------- JSProperty // bar: function() {}, <- JSFunction (static) // }, // }) return Optional.of(jsFunction) .map(PsiElement::getParent) .map(PsiElement::getParent) .filter(JSObjectLiteralExpression.class::isInstance) .map(PsiElement::getParent) .filter(JSProperty.class::isInstance) .map(JSProperty.class::cast) .filter(p -> Objects.equals(p.getName(), "statics")) .isPresent(); } else if (jsFunction.getParent() instanceof JSClass) { // ES6 classes return Optional.of(jsFunction) .map(JSAttributeListOwner::getAttributeList) .filter(a -> a.hasModifier(ModifierType.STATIC)) .isPresent(); } // Shouldn't happen unless it's a standalone function. // Probably makes sense to call it static. // It wouldn't match any class-qualified TS function by name anyway. return true; }
Example #11
Source File: TemplatedWidgetUtil.java From needsmoredojo with Apache License 2.0 | 4 votes |
@Nullable public PsiFile findTemplateFromDeclare(@Nullable DeclareStatementItems statement) { if(statement == null) { return null; } for(JSProperty property : statement.getMethodsToConvert()) { // just continue if this property is invalid for some reason if(property == null || property.getName() == null || property.getValue() == null) { continue; } /** * have to account for these scenarios * templateString: <reference to an imported template> * templateString: 'inline template' * templateString: 'inline template ' + * ' spanning multiple lines ' */ if(property.getName().equals("templateString")) { String template = property.getValue().getText(); if(property.getValue() instanceof JSLiteralExpression || property.getValue() instanceof JSBinaryExpression) { return property.getContainingFile(); } else { // find the parameter and define that matches the template parameter PsiElement relevantDefine = AMDPsiUtil.getDefineForVariable(file, template); if(relevantDefine == null) { // we couldn't find the module that templateString reference for whatever reason // (it could be an invalid reference to a module) return null; } String templatePath = relevantDefine.getText().substring(relevantDefine.getText().lastIndexOf('!') + 1); // now open the file and find the reference in it VirtualFile htmlFile = SourcesLocator.getAMDImportFile(relevantDefine.getProject(), templatePath, relevantDefine.getContainingFile().getContainingDirectory()); // if we can't resolve it return null for now TODO if(htmlFile == null) { return null; } PsiFile templateFile = PsiManager.getInstance(file.getProject()).findFile(htmlFile); return templateFile; } } } return null; }
Example #12
Source File: DeclareStatementItems.java From needsmoredojo with Apache License 2.0 | 4 votes |
public DeclareStatementItems(JSExpression[] expressionsToMixin, JSProperty[] methodsToConvert, JSElement returnStatement) { this.expressionsToMixin = expressionsToMixin; this.methodsToConvert = methodsToConvert; this.declareContainingStatement = returnStatement; }
Example #13
Source File: DeclareStatementItems.java From needsmoredojo with Apache License 2.0 | 4 votes |
public DeclareStatementItems(JSLiteralExpression className, JSExpression[] expressionsToMixin, JSProperty[] methodsToConvert, JSElement declareContainingStatement) { this(expressionsToMixin, methodsToConvert, declareContainingStatement); this.className = className; }
Example #14
Source File: DeclareStatementItems.java From needsmoredojo with Apache License 2.0 | 4 votes |
public JSProperty[] getMethodsToConvert() { return methodsToConvert; }