congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
JavaCodeStyleManager.optimizeImports
Code IndexAdd Tabnine 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)

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

  • Reactive rest calls using spring rest template
  • getContentResolver (Context)
  • putExtra (Intent)
  • setContentView (Activity)
  • Kernel (java.awt.image)
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now