com.intellij.lang.javascript.psi.JSObjectLiteralExpression Java Examples
The following examples show how to use
com.intellij.lang.javascript.psi.JSObjectLiteralExpression.
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: MustacheVarReference.java From weex-language-support with MIT License | 6 votes |
private PsiElement findDeclaration(PsiElement element, String type) { if (!(element instanceof XmlAttributeValue)) { return null; } JSObjectLiteralExpression exports = WeexFileUtil.getExportsStatement(element); if (exports == null) { return null; } else { String valueName = CodeUtil.getVarNameFromMustache(((XmlAttributeValue) element).getValue()); if ("function".equals(type)) { return WeexFileUtil.getFunctionDeclaration(value, valueName); } else { return WeexFileUtil.getVarDeclaration(value, valueName); } } }
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 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 #5
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 #6
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; }