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

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

Best Java code snippets using com.intellij.psi.codeStyle.JavaCodeStyleManager (Showing top 15 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: zzz40500/GsonFormat

filedPrefix = Config.getInstant().getFiledNamePreFixStr();
if (TextUtils.isEmpty(filedPrefix)) {
  JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
  filedPrefix = styleManager.getPrefixByVariableKind(VariableKind.FIELD
  );
origin: mustfun/mybatis-plus

public void addAnnotation(@NotNull PsiModifierListOwner parameter, @NotNull Annotation annotation) {
 PsiModifierList modifierList = parameter.getModifierList();
 if (JavaUtils.isAnnotationPresent(parameter, annotation) || null == modifierList) {
  return;
 }
 JavaService.getInstance(parameter.getProject()).importClazz((PsiJavaFile) parameter.getContainingFile(), annotation.getQualifiedName());
 
 PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
 PsiAnnotation psiAnnotation = elementFactory.createAnnotationFromText(annotation.toString(), parameter);
 modifierList.add(psiAnnotation);
 JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiAnnotation.getParent());
}
origin: t28hub/json2java4idea

@Nonnull
@Provides
@Singleton
public JavaCodeStyleManager provideCodeStyleManager(@Nonnull Project project) {
  return JavaCodeStyleManager.getInstance(project);
}
origin: com.github.adedayo.intellij.sdk/java-psi-api

public static PsiMethod generateSetterPrototype(PsiField field, final PsiClass containingClass, boolean returnSelf) {
 Project project = field.getProject();
 JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
 PsiElementFactory factory = JavaPsiFacade.getInstance(field.getProject()).getElementFactory();
 VariableKind kind = codeStyleManager.getVariableKind(field);
 String propertyName = codeStyleManager.variableNameToPropertyName(name, kind);
 String setName = suggestSetterName(field);
 try {
   .createMethodFromText(factory.createMethod(setName, returnSelf ? factory.createType(containingClass) : PsiType.VOID).getText(),
              field);
  String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
  PsiParameter param = factory.createParameter(parameterName, field.getType());
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);
    }
  }
}
origin: com.github.adedayo.intellij.sdk/java-psi-api

public static String suggestPropertyName(@NotNull PsiField field, @NotNull String fieldName) {
 JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(field.getProject());
 VariableKind kind = codeStyleManager.getVariableKind(field);
 String name = codeStyleManager.variableNameToPropertyName(fieldName, kind);
 if (!field.hasModifierProperty(PsiModifier.STATIC) && isBoolean(field.getType())) {
  if (name.startsWith(IS_PREFIX) && name.length() > IS_PREFIX.length() && Character.isUpperCase(name.charAt(IS_PREFIX.length()))) {
   name = Introspector.decapitalize(name.substring(IS_PREFIX.length()));
  }
 }
 return name;
}
origin: com.github.adedayo.intellij.sdk/java-psi-api

try {
 final Project project = operand.getProject();
 final String uniqueVariableName = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName("l", parent, false);
 final PsiDeclarationStatement declarationStatement =
  (PsiDeclarationStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText(
origin: t28hub/json2java4idea

@Nonnull
@Override
public String convert(@Nonnull String name, @Nonnull TypeName type) {
  final String propertyName = DefaultNamePolicy.format(name, CaseFormat.LOWER_CAMEL);
  final String fieldName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.FIELD);
  if (Strings.isNullOrEmpty(fieldName)) {
    throw new IllegalArgumentException("Cannot convert '" + name + "' to a field name");
  }
  return fieldName;
}
origin: mapstruct/mapstruct-idea

    mappingMethod.getModifierList()
  );
  JavaCodeStyleManager.getInstance( project ).shortenClassReferences( inserted );
}, containingFile );
origin: t28hub/json2java4idea

@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  final Project project = getProject();
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  underTest = new ParameterNamePolicy(codeStyleManager);
}
origin: t28hub/json2java4idea

  @Nonnull
  @Override
  public String convert(@Nonnull String name, @Nonnull TypeName type) {
    final String propertyName = DefaultNamePolicy.format(name, CaseFormat.LOWER_CAMEL);
    final String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
    if (Strings.isNullOrEmpty(parameterName)) {
      throw new IllegalArgumentException("Cannot convert '" + name + "' to a parameter name");
    }
    return parameterName;
  }
}
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: mustfun/mybatis-plus

JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiGetterAnnotation);
PsiAnnotation psiGetterAnnotation = elementFactory.createAnnotationFromText(Annotation.SETTER.toString(), clazz);
clazz.addBefore(psiGetterAnnotation,JavaUtils.findNealModifierElement(clazz.getFirstChild()).getFirstChild());
JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiGetterAnnotation);
origin: t28hub/json2java4idea

@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  final Project project = getProject();
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  underTest = new FieldNamePolicy(codeStyleManager);
}
com.intellij.psi.codeStyleJavaCodeStyleManager

Most used methods

  • getInstance
  • optimizeImports
    Optimizes imports in the specified Java or JSP file.
  • 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

  • Finding current android device location
  • getContentResolver (Context)
  • onRequestPermissionsResult (Fragment)
  • getApplicationContext (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Vector (java.util)
    The Vector class implements a growable array of objects. Like an array, it contains components that
  • Reference (javax.naming)
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
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