public static void appendName(@NotNull final StringBuilder buffer, @NotNull final String name) {
   if (GroovyNamesUtil.isIdentifier(name)) {
     buffer.append(name);
   } else {
     buffer.append("'");
     buffer.append(GrStringUtil.escapeSymbolsForString(name, true, false));
     buffer.append("'");
   }
 }
Exemple #2
0
  public static void addAvailableScripts(
      final Collection<String> result, @Nullable final VirtualFile root) {
    if (root == null || !root.isDirectory()) {
      return;
    }

    final VirtualFile scripts = root.findChild("scripts");

    if (scripts == null || !scripts.isDirectory()) {
      return;
    }

    for (VirtualFile child : scripts.getChildren()) {
      if (isScriptFile(child)) {
        result.add(GroovyNamesUtil.camelToSnake(child.getNameWithoutExtension()));
      }
    }
  }
Exemple #3
0
  public static void addAvailableSystemScripts(
      final Collection<String> result, @NotNull Module module) {
    VirtualFile scriptRoot = null;

    GlobalSearchScope searchScope =
        GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);

    for (PsiClass aClass :
        JavaPsiFacade.getInstance(module.getProject()).findClasses("CreateApp_", searchScope)) {
      PsiClass superClass = aClass.getSuperClass();
      if (superClass != null
          && GroovyCommonClassNames.GROOVY_LANG_SCRIPT.equals(superClass.getQualifiedName())) {
        PsiFile psiFile = aClass.getContainingFile();
        if (psiFile != null) {
          VirtualFile file = psiFile.getVirtualFile();
          if (file != null && file.getFileSystem() instanceof ArchiveFileSystem) {
            VirtualFile parent = file.getParent();
            if (parent != null && parent.findChild("Console.class") != null) {
              scriptRoot = parent;
              break;
            }
          }
        }
      }
    }

    if (scriptRoot == null) return;

    Pattern scriptPattern = Pattern.compile("([A-Za-z0-9]+)_?\\.class");

    for (VirtualFile file : scriptRoot.getChildren()) {
      Matcher matcher = scriptPattern.matcher(file.getName());
      if (matcher.matches()) {
        result.add(GroovyNamesUtil.camelToSnake(matcher.group(1)));
      }
    }
  }
  @Override
  protected ValidationInfo doValidate() {
    final String text = getEnteredName();
    if (!GroovyNamesUtil.isIdentifier(text)) {
      return new ValidationInfo(
          GroovyRefactoringBundle.message("name.is.wrong", text), myNameSuggestionsField);
    }

    if (myTypeComboBox.isClosureSelected()) {
      final Ref<ValidationInfo> info = new Ref<ValidationInfo>();
      toRemoveCBs.forEachEntry(
          new TObjectIntProcedure<JCheckBox>() {
            @Override
            public boolean execute(JCheckBox checkbox, int index) {
              if (!checkbox.isSelected()) return true;

              final GrParameter param = myInfo.getToReplaceIn().getParameters()[index];
              final ParameterInfo pinfo = findParamByOldName(param.getName());
              if (pinfo == null || !pinfo.passAsParameter()) return true;

              final String message =
                  GroovyRefactoringBundle.message(
                      "you.cannot.pass.as.parameter.0.because.you.remove.1.from.base.method",
                      pinfo.getName(),
                      param.getName());
              info.set(new ValidationInfo(message));
              return false;
            }
          });
      if (info.get() != null) {
        return info.get();
      }
    }

    return null;
  }