com.intellij.lang.javascript.psi.JSNewExpression Java Examples

The following examples show how to use com.intellij.lang.javascript.psi.JSNewExpression. 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: NoNewBaseActionFix.java    From eslint-plugin with MIT License 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement element, @NotNull PsiElement end) throws IncorrectOperationException {
    PsiElement parent = element.getParent();
    if (!(parent instanceof JSNewExpression)) return;
    final JSExpressionCodeFragment useStrict = JSElementFactory.createExpressionCodeFragment(project, getNewExp(), parent);
    PsiElement child = useStrict.getFirstChild();
    parent.replace(child);
}
 
Example #2
Source File: BlazeTypescriptGotoDeclarationHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@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);
}