Пример #1
0
 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   switch (columnIndex) {
     case CHECKMARK_COLUMN:
       {
         getVariableData()[rowIndex].passAsParameter = ((Boolean) aValue).booleanValue();
         fireTableRowsUpdated(rowIndex, rowIndex);
         myTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex);
         updateSignature();
         break;
       }
     case PARAMETER_NAME_COLUMN:
       {
         VariableData data = getVariableData()[rowIndex];
         String name = (String) aValue;
         if (PsiNameHelper.getInstance(myProject).isIdentifier(name)) {
           data.name = name;
         }
         updateSignature();
         break;
       }
     case PARAMETER_TYPE_COLUMN:
       {
         VariableData data = getVariableData()[rowIndex];
         data.type = (PsiType) aValue;
         updateSignature();
         break;
       }
   }
 }
  @Nullable
  private MoveDestination selectDestination() {
    final String packageName = getTargetPackage().trim();
    if (packageName.length() > 0
        && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) {
      Messages.showErrorDialog(
          myProject,
          RefactoringBundle.message("please.enter.a.valid.target.package.name"),
          RefactoringBundle.message("move.title"));
      return null;
    }
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(myManager, packageName);
    if (!targetPackage.exists()) {
      final int ret =
          Messages.showYesNoDialog(
              myProject,
              RefactoringBundle.message("package.does.not.exist", packageName),
              RefactoringBundle.message("move.title"),
              Messages.getQuestionIcon());
      if (ret != Messages.YES) return null;
    }

    return ((DestinationFolderComboBox) myDestinationFolderCB)
        .selectDirectory(targetPackage, mySuggestToMoveToAnotherRoot);
  }
Пример #3
0
 @Override
 protected void canRun() throws ConfigurationException {
   String name = getParameterName();
   if (name == null || !PsiNameHelper.getInstance(myProject).isIdentifier(name)) {
     throw new ConfigurationException(
         "\'" + (name != null ? name : "") + "\' is invalid parameter name");
   }
 }
 @NotNull
 @Override
 public PsiKeyword createKeyword(@NotNull final String text) throws IncorrectOperationException {
   if (!PsiNameHelper.getInstance(myManager.getProject()).isKeyword(text)) {
     throw new IncorrectOperationException("\"" + text + "\" is not a keyword.");
   }
   return new LightKeyword(myManager, text);
 }
Пример #5
0
  @Override
  public boolean processDeclarations(
      @NotNull PsiScopeProcessor processor,
      @NotNull ResolveState state,
      PsiElement lastParent,
      @NotNull PsiElement place) {
    GlobalSearchScope scope = place.getResolveScope();

    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);

    final Condition<String> nameCondition = processor.getHint(JavaCompletionHints.NAME_FILTER);

    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
      NameHint nameHint = processor.getHint(NameHint.KEY);
      if (nameHint != null) {
        final String shortName = nameHint.getName(state);
        final PsiClass[] classes = findClassByShortName(shortName, scope);
        if (!processClasses(processor, state, classes, Conditions.<String>alwaysTrue()))
          return false;
      } else {
        PsiClass[] classes = getClasses(scope);
        if (!processClasses(
            processor,
            state,
            classes,
            nameCondition != null ? nameCondition : Conditions.<String>alwaysTrue())) return false;
      }
    }
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)) {
      NameHint nameHint = processor.getHint(NameHint.KEY);
      if (nameHint != null) {
        PsiPackage aPackage = findSubPackageByName(nameHint.getName(state));
        if (aPackage != null) {
          if (!processor.execute(aPackage, state)) return false;
        }
      } else {
        PsiPackage[] packs = getSubPackages(scope);
        for (PsiPackage pack : packs) {
          final String packageName = pack.getName();
          if (packageName == null) continue;
          if (!PsiNameHelper.getInstance(myManager.getProject())
              .isIdentifier(packageName, PsiUtil.getLanguageLevel(this))) {
            continue;
          }
          if (!processor.execute(pack, state)) {
            return false;
          }
        }
      }
    }
    return true;
  }
  private String calculateDelegateFieldName() {
    final Project project = sourceClass.getProject();
    final CodeStyleSettingsManager settingsManager = CodeStyleSettingsManager.getInstance(project);
    final CodeStyleSettings settings = settingsManager.getCurrentSettings();

    final String baseName =
        settings.FIELD_NAME_PREFIX.length() == 0
            ? StringUtil.decapitalize(newClassName)
            : newClassName;
    String name = settings.FIELD_NAME_PREFIX + baseName + settings.FIELD_NAME_SUFFIX;
    if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
      return name;
    }
    int counter = 1;
    while (true) {
      name = settings.FIELD_NAME_PREFIX + baseName + counter + settings.FIELD_NAME_SUFFIX;
      if (!existsFieldWithName(name) && !PsiNameHelper.getInstance(project).isKeyword(name)) {
        return name;
      }
      counter++;
    }
  }
 @Override
 protected void canRun() throws ConfigurationException {
   if (isMoveToPackage()) {
     String name = getTargetPackage().trim();
     if (name.length() != 0
         && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(name)) {
       throw new ConfigurationException("\'" + name + "\' is invalid destination package name");
     }
   } else {
     if (findTargetClass() == null)
       throw new ConfigurationException("Destination class not found");
     final String validationError = verifyInnerClassDestination();
     if (validationError != null) throw new ConfigurationException(validationError);
   }
 }
  @NotNull
  @Override
  public PsiImportStatement createImportStatementOnDemand(@NotNull final String packageName)
      throws IncorrectOperationException {
    if (packageName.isEmpty()) {
      throw new IncorrectOperationException("Cannot create import statement for default package.");
    }
    if (!PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) {
      throw new IncorrectOperationException("Incorrect package name: \"" + packageName + "\".");
    }

    final PsiJavaFile aFile = createDummyJavaFile("import " + packageName + ".*;");
    final PsiImportStatementBase statement = extractImport(aFile, false);
    return (PsiImportStatement)
        CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
  }
  private boolean hasAcceptablePackage(@NotNull VirtualFile vFile) {
    if (vFile.getFileType() == JavaClassFileType.INSTANCE) {
      // See IDEADEV-5626
      final VirtualFile root =
          ProjectRootManager.getInstance(myManager.getProject())
              .getFileIndex()
              .getClassRootForFile(vFile);
      VirtualFile parent = vFile.getParent();
      final PsiNameHelper nameHelper = PsiNameHelper.getInstance(myManager.getProject());
      while (parent != null && !Comparing.equal(parent, root)) {
        if (!nameHelper.isIdentifier(parent.getName())) return false;
        parent = parent.getParent();
      }
    }

    return true;
  }
Пример #10
0
 private boolean isIdentifier(String name) {
   return PsiNameHelper.getInstance(myProject).isIdentifier(name, LanguageLevel.HIGHEST);
 }
 private void updateOkStatus() {
   String text = getEnteredName();
   setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(text));
 }
 private boolean isIdentifier(@NotNull String name) {
   return PsiNameHelper.getInstance(myManager.getProject()).isIdentifier(name);
 }