@Nullable
  @Override
  public PsiElement getAliasNameElement() {
    GrImportStatementStub stub = getStub();
    if (stub != null) {
      String alias = stub.getAliasName();
      if (alias == null) return null;

      GrImportStatement imp =
          GroovyPsiElementFactory.getInstance(getProject())
              .createImportStatementFromText("import A as " + alias);
      return imp.getAliasNameElement();
    }

    return findChildByType(GroovyTokenTypes.mIDENT);
  }
예제 #2
0
 public static boolean processImports(
     ResolveState state,
     PsiElement lastParent,
     PsiElement place,
     PsiScopeProcessor importProcessor,
     GrImportStatement[] importStatements,
     boolean shouldProcessOnDemand) {
   for (int i = importStatements.length - 1; i >= 0; i--) {
     final GrImportStatement imp = importStatements[i];
     if (shouldProcessOnDemand != imp.isOnDemand()) continue;
     if (!imp.processDeclarations(importProcessor, state, lastParent, place)) {
       return false;
     }
   }
   return true;
 }
  private static boolean findClassByText(GrReferenceExpression ref) {
    final String text = ref.getText();
    final int i = text.indexOf('<');
    String className = i == -1 ? text : text.substring(0, i);

    PsiClass[] names =
        PsiShortNamesCache.getInstance(ref.getProject())
            .getClassesByName(className, ref.getResolveScope());
    if (names.length > 0) return true;

    PsiFile file = ref.getContainingFile();
    if (file instanceof GroovyFile) {
      GrImportStatement[] imports = ((GroovyFile) file).getImportStatements();
      for (GrImportStatement anImport : imports) {
        if (className.equals(anImport.getImportedName())) return true;
      }
    }

    return false;
  }