congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
JavaCodeStyleManager
Code IndexAdd Tabnine 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)

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

  • Creating JSON documents from java classes using gson
  • getContentResolver (Context)
  • putExtra (Intent)
  • notifyDataSetChanged (ArrayAdapter)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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