Codota Logo
JavaCodeStyleManager.optimizeImports
Code IndexAdd Codota to your IDE (free)

How to use
optimizeImports
method
in
com.intellij.psi.codeStyle.JavaCodeStyleManager

Best Java code snippets using com.intellij.psi.codeStyle.JavaCodeStyleManager.optimizeImports (Showing top 3 results out of 315)

  • Common ways to obtain JavaCodeStyleManager
private void myMethod () {
JavaCodeStyleManager j =
  • Codota IconStyle.JavaCodeStyleManager javaCodeStyleManager;Project project;javaCodeStyleManager.getInstance(project)
  • Smart code suggestions by Codota
}
origin: zzz40500/GsonFormat

protected void formatJavCode(PsiClass cls) {
  if (cls == null) {
    return;
  }
  JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(cls.getProject());
  styleManager.optimizeImports(cls.getContainingFile());
  styleManager.shortenClassReferences(cls);
}
origin: mustfun/mybatis-plus

protected PsiFile createFile(Project project, @NotNull PsiDirectory psiDirectory, String fileName, String context, LanguageFileType fileType) {
  //+        final String simpleContent = XmlSorterUtil.replaceAllByRegex(content, ">" + lineSeparator + "*\\s+?<", "><");
  String replace = context.replaceAll("\r\n", "\n");
  PsiFile file = psiDirectory.findFile(fileName);
  if (file!=null){
    file.delete();
  }
  PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(fileName, fileType, replace);
  // reformat class
  CodeStyleManager.getInstance(project).reformat(psiFile);
  if (psiFile instanceof PsiJavaFile) {
    JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
    styleManager.optimizeImports(psiFile);
    styleManager.shortenClassReferences(psiFile);
  }
  //加载到磁盘中
  psiDirectory.add(psiFile);
  return psiFile;
}
origin: t28hub/json2java4idea

  @Override
  protected void run(@NotNull Result<PsiFile> result) throws Throwable {
    final PsiPackage packageElement = directoryService.getPackage(directory);
    if (packageElement == null) {
      throw new InvalidDirectoryException("Target directory does not provide a package");
    }

    final String fileName = Extensions.append(name, StdFileTypes.JAVA);
    final PsiFile found = directory.findFile(fileName);
    if (found != null) {
      throw new ClassAlreadyExistsException("Class '" + name + "'already exists in " + packageElement.getName());
    }

    final String packageName = packageElement.getQualifiedName();
    final String className = Extensions.remove(this.name, StdFileTypes.JAVA);
    try {
      final String java = converter.convert(packageName, className, json);
      final PsiFile classFile = fileFactory.createFileFromText(fileName, JavaFileType.INSTANCE, java);
      CodeStyleManager.getInstance(classFile.getProject()).reformat(classFile);
      JavaCodeStyleManager.getInstance(classFile.getProject()).optimizeImports(classFile);
      final PsiFile created = (PsiFile) directory.add(classFile);
      result.setResult(created);
    } catch (IOException e) {
      throw new ClassCreationException("Failed to create new class from JSON", e);
    }
  }
}
com.intellij.psi.codeStyleJavaCodeStyleManageroptimizeImports

Javadoc

Optimizes imports in the specified Java or JSP file.

Popular methods of JavaCodeStyleManager

  • getInstance
  • shortenClassReferences
    Replaces fully-qualified class names in a part of contents of the specified element with non-qualifi
  • propertyNameToVariableName
    Appends code style defined prefixes and/or suffixes for the specified variable kind to the specified
  • getPrefixByVariableKind
  • getVariableKind
    Returns the kind of the specified variable (local, parameter, field, static field or static final fi
  • suggestUniqueVariableName
  • suggestVariableName
  • variableNameToPropertyName
    Generates a stripped-down name (with no code style defined prefixes or suffixes, usable as a propert

Popular in Java

  • Creating JSON documents from java classes using gson
  • compareTo (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • getSystemService (Context)
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • DataSource (javax.sql)
    A factory for connections to the physical data source that this DataSource object represents. An alt
  • JLabel (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now