Java源码示例:com.intellij.lang.javascript.psi.JSNewExpression

示例1
@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);
}
 
示例2
@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);
}