public ClsJavaCodeReferenceElementImpl(PsiElement parent, String canonicalText) {
    myParent = parent;

    myCanonicalText = canonicalText;
    final String[] classParametersText = PsiNameHelper.getClassParametersText(canonicalText);
    int length = classParametersText.length;
    myTypeParameters = length == 0 ? EMPTY_ARRAY : new ClsTypeElementImpl[length];
    for (int i = 0; i < length; i++) {
      String s = classParametersText[length - i - 1];
      char variance = ClsTypeElementImpl.VARIANCE_NONE;
      if (s.startsWith(EXTENDS_PREFIX)) {
        variance = ClsTypeElementImpl.VARIANCE_EXTENDS;
        s = s.substring(EXTENDS_PREFIX.length());
      } else if (s.startsWith(SUPER_PREFIX)) {
        variance = ClsTypeElementImpl.VARIANCE_SUPER;
        s = s.substring(SUPER_PREFIX.length());
      } else if (StringUtil.startsWithChar(s, '?')) {
        variance = ClsTypeElementImpl.VARIANCE_INVARIANT;
        s = s.substring(1);
      }

      myTypeParameters[i] = new ClsTypeElementImpl(this, s, variance);
    }

    myQualifiedName = PsiNameHelper.getQualifiedClassName(myCanonicalText, false);
  }
  public static void checkCreateClassOrInterface(@NotNull PsiDirectory directory, String name)
      throws IncorrectOperationException {
    PsiUtil.checkIsIdentifier(directory.getManager(), name);

    String fileName = name + "." + StdFileTypes.JAVA.getDefaultExtension();
    directory.checkCreateFile(fileName);

    PsiNameHelper helper = JavaPsiFacade.getInstance(directory.getProject()).getNameHelper();
    PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    String qualifiedName = aPackage == null ? null : aPackage.getQualifiedName();
    if (!StringUtil.isEmpty(qualifiedName) && !helper.isQualifiedName(qualifiedName)) {
      throw new IncorrectOperationException(
          "Cannot create class in invalid package: '" + qualifiedName + "'");
    }
  }
  @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);
  }
 @NotNull
 @Override
 public PsiJavaCodeReferenceElement createReferenceElementByFQClassName(
     @NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) {
   final String shortName = PsiNameHelper.getShortClassName(qName);
   return new LightClassReference(myManager, shortName, qName, resolveScope);
 }
 public String getReferenceName() {
   if (myPackageName != null) {
     return PsiNameHelper.getShortClassName(myPackageName);
   } else {
     return myRefPackage.getName();
   }
 }
Beispiel #6
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;
       }
   }
 }
Beispiel #7
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);
 }
  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;
  }
 @Override
 public void indexStub(@NotNull GrReferenceListStub stub, @NotNull IndexSink sink) {
   for (String name : stub.getBaseClasses()) {
     if (name != null) {
       sink.occurrence(GrDirectInheritorsIndex.KEY, PsiNameHelper.getShortClassName(name));
     }
   }
 }
Beispiel #11
0
 private static PsiClass findSingleImportByShortName(
     @NotNull PsiJavaFile file, @NotNull String shortClassName) {
   PsiClass[] refs = file.getSingleClassImports(true);
   for (PsiClass ref : refs) {
     String className = ref.getQualifiedName();
     if (className != null && PsiNameHelper.getShortClassName(className).equals(shortClassName)) {
       return ref;
     }
   }
   for (PsiClass aClass : file.getClasses()) {
     String className = aClass.getQualifiedName();
     if (className != null && PsiNameHelper.getShortClassName(className).equals(shortClassName)) {
       return aClass;
     }
   }
   return null;
 }
  private String getText(boolean qualified, boolean annotated) {
    PsiAnnotation[] annotations = getAnnotations();
    if (!annotated || annotations.length == 0) return myName;

    StringBuilder sb = new StringBuilder();
    PsiNameHelper.appendAnnotations(sb, annotations, qualified);
    sb.append(myName);
    return sb.toString();
  }
 @NotNull
 public static String getShortTypeText(@Nullable String text) {
   if (text == null) {
     return "";
   }
   int i = text.length();
   while (i - 2 >= 0 && text.charAt(i - 2) == '[' && text.charAt(i - 1) == ']') {
     i -= 2;
   }
   return PsiNameHelper.getShortClassName(text.substring(0, i)) + text.substring(i);
 }
Beispiel #14
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);
   }
 }
  public void _commit(boolean finishChosen) throws CommitStepException {
    // Stop editing if any
    final TableCellEditor cellEditor = myTable.getCellEditor();
    if (cellEditor != null) {
      cellEditor.stopCellEditing();
    }

    // Check that all included fields are bound to valid bean properties
    final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(myData.myProject).getNameHelper();
    for (int i = 0; i < myData.myBindings.length; i++) {
      final FormProperty2BeanProperty binding = myData.myBindings[i];
      if (binding.myBeanProperty == null) {
        continue;
      }

      if (!nameHelper.isIdentifier(binding.myBeanProperty.myName)) {
        throw new CommitStepException(
            UIDesignerBundle.message(
                "error.X.is.not.a.valid.property.name", binding.myBeanProperty.myName));
      }
    }

    myData.myGenerateIsModified = myChkIsModified.isSelected();
  }
  @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);
  }
  public static PsiType buildTypeFromTypeString(
      @NotNull final String typeName,
      @NotNull final PsiElement context,
      @NotNull final PsiFile psiFile) {
    PsiType resultType;
    final PsiManager psiManager = psiFile.getManager();

    if (typeName.indexOf('<') != -1 || typeName.indexOf('[') != -1 || typeName.indexOf('.') == -1) {
      try {
        return JavaPsiFacade.getInstance(psiManager.getProject())
            .getElementFactory()
            .createTypeFromText(typeName, context);
      } catch (Exception ignored) {
      } // invalid syntax will produce unresolved class type
    }

    PsiClass aClass =
        JavaPsiFacade.getInstance(psiManager.getProject())
            .findClass(typeName, context.getResolveScope());

    if (aClass == null) {
      final LightClassReference ref =
          new LightClassReference(
              psiManager,
              PsiNameHelper.getShortClassName(typeName),
              typeName,
              PsiSubstitutor.EMPTY,
              psiFile);
      resultType = new PsiClassReferenceType(ref, null);
    } else {
      PsiElementFactory factory =
          JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
      PsiSubstitutor substitutor = factory.createRawSubstitutor(aClass);
      resultType = factory.createType(aClass, substitutor);
    }

    return resultType;
  }
Beispiel #20
0
  /**
   * Adds import if it is needed.
   *
   * @return false when the FQ-name have to be used in code (e.g. when conflicting imports already
   *     exist)
   */
  public boolean addImport(@NotNull PsiJavaFile file, @NotNull PsiClass refClass) {
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(file.getProject());
    PsiElementFactory factory = facade.getElementFactory();
    PsiResolveHelper helper = facade.getResolveHelper();

    String className = refClass.getQualifiedName();
    if (className == null) return true;
    String packageName = getPackageOrClassName(className);
    String shortName = PsiNameHelper.getShortClassName(className);

    PsiClass conflictSingleRef = findSingleImportByShortName(file, shortName);
    if (conflictSingleRef != null) {
      return className.equals(conflictSingleRef.getQualifiedName());
    }

    PsiClass curRefClass = helper.resolveReferencedClass(shortName, file);
    if (file.getManager().areElementsEquivalent(refClass, curRefClass)) {
      return true;
    }

    boolean useOnDemand = true;
    if (packageName.length() == 0) {
      useOnDemand = false;
    }

    PsiElement conflictPackageRef = findImportOnDemand(file, packageName);
    if (conflictPackageRef != null) {
      useOnDemand = false;
    }

    List<PsiElement> classesToReimport = new ArrayList<PsiElement>();

    List<PsiJavaCodeReferenceElement> importRefs = getImportsFromPackage(file, packageName);
    if (useOnDemand) {
      if (mySettings.USE_SINGLE_CLASS_IMPORTS
          && importRefs.size() + 1 < mySettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND
          && !mySettings.PACKAGES_TO_USE_IMPORT_ON_DEMAND.contains(packageName)) {
        useOnDemand = false;
      }
      // name of class we try to import is the same as of the class defined in this file
      if (curRefClass != null) {
        useOnDemand = true;
      }
      // check conflicts
      if (useOnDemand) {
        PsiElement[] onDemandRefs = file.getOnDemandImports(false, true);
        if (onDemandRefs.length > 0) {
          PsiPackage aPackage = facade.findPackage(packageName);
          if (aPackage != null) {
            PsiDirectory[] dirs = aPackage.getDirectories();
            for (PsiDirectory dir : dirs) {
              PsiFile[] files = dir.getFiles(); // do not iterate classes - too slow when not loaded
              for (PsiFile aFile : files) {
                if (aFile instanceof PsiJavaFile) {
                  String name = aFile.getVirtualFile().getNameWithoutExtension();
                  for (PsiElement ref : onDemandRefs) {
                    String refName =
                        ref instanceof PsiClass
                            ? ((PsiClass) ref).getQualifiedName()
                            : ((PsiPackage) ref).getQualifiedName();
                    String conflictClassName = refName + "." + name;
                    GlobalSearchScope resolveScope = file.getResolveScope();
                    PsiClass conflictClass = facade.findClass(conflictClassName, resolveScope);
                    if (conflictClass != null && helper.isAccessible(conflictClass, file, null)) {
                      String conflictClassName2 = aPackage.getQualifiedName() + "." + name;
                      PsiClass conflictClass2 = facade.findClass(conflictClassName2, resolveScope);
                      if (conflictClass2 != null
                          && helper.isAccessible(conflictClass2, file, null)) {
                        if (ReferencesSearch.search(
                                    conflictClass, new LocalSearchScope(file), false)
                                .findFirst()
                            != null) {
                          classesToReimport.add(conflictClass);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    try {
      PsiImportList importList = file.getImportList();
      PsiImportStatement statement;
      if (useOnDemand) {
        statement = factory.createImportStatementOnDemand(packageName);
      } else {
        statement = factory.createImportStatement(refClass);
      }
      importList.add(statement);
      if (useOnDemand) {
        for (PsiJavaCodeReferenceElement ref : importRefs) {
          LOG.assertTrue(ref.getParent() instanceof PsiImportStatement);
          if (!ref.isValid()) continue; // todo[dsl] Q?
          classesToReimport.add(ref.resolve());
          PsiImportStatement importStatement = (PsiImportStatement) ref.getParent();
          importStatement.delete();
        }
      }

      for (PsiElement aClassesToReimport : classesToReimport) {
        PsiClass aClass = (PsiClass) aClassesToReimport;
        if (aClass != null) {
          addImport(file, aClass);
        }
      }
    } catch (IncorrectOperationException e) {
      LOG.error(e);
    }
    return true;
  }
Beispiel #21
0
  @NotNull
  private static Set<String> findSingleImports(
      @NotNull final PsiJavaFile file,
      @NotNull String[] names,
      @NotNull final Set<String> onDemandImports,
      @NotNull Set<String> namesToImportStaticly) {
    final GlobalSearchScope resolveScope = file.getResolveScope();
    Set<String> namesToUseSingle = new THashSet<String>();
    final String thisPackageName = file.getPackageName();
    final Set<String> implicitlyImportedPackages =
        new THashSet<String>(Arrays.asList(file.getImplicitlyImportedPackages()));
    final PsiManager manager = file.getManager();
    for (String name : names) {
      String prefix = getPackageOrClassName(name);
      if (prefix.length() == 0) continue;
      final boolean isImplicitlyImported = implicitlyImportedPackages.contains(prefix);
      if (!onDemandImports.contains(prefix) && !isImplicitlyImported) continue;
      String shortName = PsiNameHelper.getShortClassName(name);

      String thisPackageClass =
          thisPackageName.length() > 0 ? thisPackageName + "." + shortName : shortName;
      if (JavaPsiFacade.getInstance(manager.getProject()).findClass(thisPackageClass, resolveScope)
          != null) {
        namesToUseSingle.add(name);
        continue;
      }
      if (!isImplicitlyImported) {
        String langPackageClass = JAVA_LANG_PACKAGE + "." + shortName; // TODO : JSP!
        if (JavaPsiFacade.getInstance(manager.getProject())
                .findClass(langPackageClass, resolveScope)
            != null) {
          namesToUseSingle.add(name);
          continue;
        }
      }
      for (String onDemandName : onDemandImports) {
        if (prefix.equals(onDemandName)) continue;
        if (namesToImportStaticly.contains(name)) {
          PsiClass aClass =
              JavaPsiFacade.getInstance(manager.getProject()).findClass(onDemandName, resolveScope);
          if (aClass != null) {
            PsiField field = aClass.findFieldByName(shortName, true);
            if (field != null && field.hasModifierProperty(PsiModifier.STATIC)) {
              namesToUseSingle.add(name);
            } else {
              PsiClass inner = aClass.findInnerClassByName(shortName, true);
              if (inner != null && inner.hasModifierProperty(PsiModifier.STATIC)) {
                namesToUseSingle.add(name);
              } else {
                PsiMethod[] methods = aClass.findMethodsByName(shortName, true);
                for (PsiMethod method : methods) {
                  if (method.hasModifierProperty(PsiModifier.STATIC)) {
                    namesToUseSingle.add(name);
                  }
                }
              }
            }
          }
        } else {
          PsiClass aClass =
              JavaPsiFacade.getInstance(manager.getProject())
                  .findClass(onDemandName + "." + shortName, resolveScope);
          if (aClass != null) {
            namesToUseSingle.add(name);
          }
        }
      }
    }
    return namesToUseSingle;
  }
 @Override
 public String getReferenceName() {
   return PsiNameHelper.getShortClassName(myCanonicalText);
 }
Beispiel #23
0
 private boolean isIdentifier(String name) {
   return PsiNameHelper.getInstance(myProject).isIdentifier(name, LanguageLevel.HIGHEST);
 }
 @Override
 public String getText() {
   return PsiNameHelper.getPresentableText(this);
 }
 private boolean isIdentifier(@NotNull String name) {
   return PsiNameHelper.getInstance(myManager.getProject()).isIdentifier(name);
 }
  private void buildText(
      @NotNull PsiClass aClass,
      @NotNull PsiSubstitutor substitutor,
      @NotNull StringBuilder buffer,
      @NotNull TextType textType,
      boolean annotated) {
    if (aClass instanceof PsiAnonymousClass) {
      ClassResolveResult baseResolveResult =
          ((PsiAnonymousClass) aClass).getBaseClassType().resolveGenerics();
      PsiClass baseClass = baseResolveResult.getElement();
      if (baseClass != null) {
        buildText(baseClass, baseResolveResult.getSubstitutor(), buffer, textType, false);
      }
      return;
    }

    boolean qualified = textType != TextType.PRESENTABLE;

    PsiClass enclosingClass = null;
    if (!aClass.hasModifierProperty(PsiModifier.STATIC)) {
      PsiElement parent = aClass.getParent();
      if (parent instanceof PsiClass && !(parent instanceof PsiAnonymousClass)) {
        enclosingClass = (PsiClass) parent;
      }
    }
    if (enclosingClass != null) {
      buildText(enclosingClass, substitutor, buffer, textType, false);
      buffer.append('.');
    } else if (qualified) {
      String fqn = aClass.getQualifiedName();
      if (fqn != null) {
        String prefix = StringUtil.getPackageName(fqn);
        if (!StringUtil.isEmpty(prefix)) {
          buffer.append(prefix);
          buffer.append('.');
        }
      }
    }

    if (annotated) {
      PsiNameHelper.appendAnnotations(buffer, getAnnotations(), qualified);
    }

    buffer.append(aClass.getName());

    PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
    if (typeParameters.length > 0) {
      int pos = buffer.length();
      buffer.append('<');

      for (int i = 0; i < typeParameters.length; i++) {
        PsiTypeParameter typeParameter = typeParameters[i];
        PsiUtilCore.ensureValid(typeParameter);

        if (i > 0) {
          buffer.append(',');
          if (textType == TextType.PRESENTABLE) buffer.append(' ');
        }

        PsiType substitutionResult = substitutor.substitute(typeParameter);
        if (substitutionResult == null) {
          buffer.setLength(pos);
          pos = -1;
          break;
        }
        PsiUtil.ensureValidType(substitutionResult);

        if (textType == TextType.PRESENTABLE) {
          buffer.append(substitutionResult.getPresentableText());
        } else if (textType == TextType.CANONICAL) {
          buffer.append(substitutionResult.getCanonicalText(annotated));
        } else {
          buffer.append(substitutionResult.getInternalCanonicalText());
        }
      }

      if (pos >= 0) {
        buffer.append('>');
      }
    }
  }
  @Override
  public void visit(
      int version,
      int access,
      String name,
      String signature,
      String superName,
      String[] interfaces) {
    String fqn = getClassName(name);
    String shortName = myShortName != null ? myShortName : PsiNameHelper.getShortClassName(fqn);

    int flags = myAccess == 0 ? access : myAccess;
    boolean isDeprecated = (flags & Opcodes.ACC_DEPRECATED) != 0;
    boolean isInterface = (flags & Opcodes.ACC_INTERFACE) != 0;
    boolean isEnum = (flags & Opcodes.ACC_ENUM) != 0;
    boolean isAnnotationType = (flags & Opcodes.ACC_ANNOTATION) != 0;

    byte stubFlags =
        PsiClassStubImpl.packFlags(
            isDeprecated, isInterface, isEnum, false, false, isAnnotationType, false, false);
    myResult =
        new PsiClassStubImpl(JavaStubElementTypes.CLASS, myParent, fqn, shortName, null, stubFlags);

    LanguageLevel languageLevel = convertFromVersion(version);
    ((PsiClassStubImpl) myResult).setLanguageLevel(languageLevel);

    myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags));

    CharacterIterator signatureIterator =
        signature != null ? new StringCharacterIterator(signature) : null;
    if (signatureIterator != null) {
      try {
        SignatureParsing.parseTypeParametersDeclaration(signatureIterator, myResult);
      } catch (ClsFormatException e) {
        signatureIterator = null;
      }
    } else {
      new PsiTypeParameterListStubImpl(myResult);
    }

    String convertedSuper;
    List<String> convertedInterfaces = new ArrayList<String>();
    if (signatureIterator == null) {
      convertedSuper = parseClassDescription(superName, interfaces, convertedInterfaces);
    } else {
      try {
        convertedSuper = parseClassSignature(signatureIterator, convertedInterfaces);
      } catch (ClsFormatException e) {
        new PsiTypeParameterListStubImpl(myResult);
        convertedSuper = parseClassDescription(superName, interfaces, convertedInterfaces);
      }
    }

    if (isInterface) {
      if (isAnnotationType) {
        convertedInterfaces.remove(JAVA_LANG_ANNOTATION_ANNOTATION);
      }
      newReferenceList(
          JavaStubElementTypes.EXTENDS_LIST,
          myResult,
          ArrayUtil.toStringArray(convertedInterfaces));
      newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult);
    } else {
      if (convertedSuper == null
          || JAVA_LANG_OBJECT.equals(convertedSuper)
          || isEnum
              && (JAVA_LANG_ENUM.equals(convertedSuper)
                  || (JAVA_LANG_ENUM + "<" + fqn + ">").equals(convertedSuper))) {
        newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult);
      } else {
        newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, convertedSuper);
      }
      newReferenceList(
          JavaStubElementTypes.IMPLEMENTS_LIST,
          myResult,
          ArrayUtil.toStringArray(convertedInterfaces));
    }
  }
 private void updateOkStatus() {
   String text = getEnteredName();
   setOKActionEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(text));
 }