com.intellij.lang.javascript.psi.JSDefinitionExpression Java Examples
The following examples show how to use
com.intellij.lang.javascript.psi.JSDefinitionExpression.
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: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public Collection<JSDefinitionExpression> getDefinitions() { final PsiElement firstChild = getFirstChild(); if (firstChild instanceof JSDefinitionExpression) { return Collections.singletonList((JSDefinitionExpression) firstChild); } if (firstChild instanceof JSParenthesizedExpression) { final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); if (commaExpression != null) { return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); } } return Collections.emptyList(); }
Example #4
Source File: RTRepeatExpression.java From react-templates-plugin with MIT License | 5 votes |
public Collection<JSDefinitionExpression> getDefinitions() { final PsiElement firstChild = getFirstChild(); if (firstChild instanceof JSDefinitionExpression) { return Collections.singletonList((JSDefinitionExpression) firstChild); } if (firstChild instanceof JSParenthesizedExpression) { final PsiElement commaExpression = PsiTreeUtil.findChildOfType(firstChild, JSCommaExpression.class); if (commaExpression != null) { return PsiTreeUtil.findChildrenOfType(commaExpression, JSDefinitionExpression.class); } } return Collections.emptyList(); }
Example #5
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 #6
Source File: RTAsExpression.java From react-templates-plugin with MIT License | 4 votes |
@Nullable public JSDefinitionExpression getDefinition() { return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); }
Example #7
Source File: RTAsExpression.java From react-templates-plugin with MIT License | 4 votes |
@Nullable public JSDefinitionExpression getDefinition() { return PsiTreeUtil.getChildOfType(this, JSDefinitionExpression.class); }
Example #8
Source File: MockJSAssignmentExpression.java From needsmoredojo with Apache License 2.0 | 4 votes |
public MockJSAssignmentExpression(JSDefinitionExpression definition, String content) { super(mock(ASTNode.class)); this.definition = definition; this.content = content; }