Examples of CodeStyleManager


Examples of com.intellij.psi.codeStyle.CodeStyleManager

        PsiManager psiManager = PsiManager.getInstance( directory.getProject() );
        PsiFileFactory fileFactory = PsiFileFactory.getInstance( directory.getProject() );
        PsiFile file = fileFactory.createFileFromText( fileName, text );

        // Reformat the file according to project/default style
        CodeStyleManager codeStyleManager = CodeStyleManager.getInstance( psiManager );
        codeStyleManager.reformat( file );

        // Add newly created file to directory
        return (PsiFile) directory.add( file );
    }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

      PsiMethod actionMethod = elementFactory.createMethodFromText("public java.lang.String " + methodName + "() throws java.lang.Exception { return \"success\"; }",
                                                                   actionClass);

      final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(project);
      actionMethod = (PsiMethod) javaCodeStyleManager.shortenClassReferences(actionMethod);
      final CodeStyleManager codestylemanager = CodeStyleManager.getInstance(project);
      actionMethod = (PsiMethod) codestylemanager.reformat(actionMethod);

      final PsiMethod element = (PsiMethod) actionClass.add(actionMethod);

      //noinspection ConstantConditions
      OpenSourceUtil.navigate((Navigatable) element.getBody().getNavigationElement());
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

        return new Runnable() {
          @Override
          public void run() {
            try {
              TextRange rangeToUse = file.getTextRange();
              CodeStyleManager styleManager = CodeStyleManager.getInstance(getProject());
              styleManager.reformatText(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
            }
            catch (IncorrectOperationException e) {
              assertTrue(e.getLocalizedMessage(), false);
            }
          }
        };
      }
    };

    // define action to run "Adjust line indent" on every line in the "file" defined by beforeText
    FormatRunnableFactory lineFormatRunnableFactory = new FormatRunnableFactory() {
      @Override
      Runnable createFormatRunnable(final PsiFile file) {
        return new Runnable() {
          @Override
          public void run() {
            try {
              final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
              final Document document = manager.getDocument(file);

              assert document != null;

              for (int lineNum = 0; lineNum < document.getLineCount(); lineNum++) {
                CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
                int offset = document.getLineStartOffset(lineNum);
                @SuppressWarnings("deprecation") // if this breaks at some point, we should
                  // refactor to invoke AutoIndentLinesAction
                  // instead of doing the indent directly
                  boolean lineToBeIndented = codeStyleManager.isLineToBeIndented(file, offset);
                if (lineToBeIndented) {
                  codeStyleManager.adjustLineIndent(file, offset);
                }
              }
            }
            catch (IncorrectOperationException e) {
              assertTrue(e.getLocalizedMessage(), false);
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

    // run the formatter if the user just completed typing a SIMPLE_INVERSE or a CLOSE_BLOCK_STACHE
    if (closeOrSimpleInverseParent != null) {
      // grab the current caret position (AutoIndentLinesHandler is about to mess with it)
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
      CaretModel caretModel = editor.getCaretModel();
      CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
      codeStyleManager.adjustLineIndent(file, editor.getDocument().getLineStartOffset(caretModel.getLogicalPosition().line));
    }
  }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

      final PsiNamedElement newVariable = getVariable();
      if (newVariable != null) {
        final GherkinScenarioOutline scenario = PsiTreeUtil.getParentOfType(newVariable, GherkinScenarioOutline.class);

        if (scenario != null) {
          final CodeStyleManager csManager = CodeStyleManager.getInstance(newVariable.getProject());
          csManager.reformat(scenario);
        }
      }
    }
  }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

    return generateSetterPrototype(field, field.getContainingClass());
  }

  public static PsiMethod generateSetterPrototype(PsiField field, final PsiClass containingClass) {
    Project project = field.getProject();
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
    PsiElementFactory factory = field.getManager().getElementFactory();

    String name = field.getName();
    boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
    VariableKind kind = codeStyleManager.getVariableKind(field);
    String propertyName = codeStyleManager.variableNameToPropertyName(name, kind);
    String setName = suggestSetterName(project, field);
    try {
      PsiMethod setMethod = factory.createMethod(setName, PsiType.VOID);
      String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
      PsiParameter param = factory.createParameter(parameterName, field.getType());

      annotateWithNullableStuff(field, factory, param);

      setMethod.getParameterList().add(param);
      setMethod.getModifierList().setModifierProperty(PsiModifier.PUBLIC, true);
      setMethod.getModifierList().setModifierProperty(PsiModifier.STATIC, isStatic);

      @NonNls StringBuffer buffer = new StringBuffer();
      buffer.append("{\n");
      if (name.equals(parameterName)) {
        if (!isStatic) {
          buffer.append("this.");
        }
        else {
          String className = containingClass.getName();
          if (className != null) {
            buffer.append(className);
            buffer.append(".");
          }
        }
      }
      buffer.append(name);
      buffer.append("=");
      buffer.append(parameterName);
      buffer.append(";\n}");
      PsiCodeBlock body = factory.createCodeBlockFromText(buffer.toString(), null);
      setMethod.getBody().replace(body);
      setMethod = (PsiMethod)codeStyleManager.reformat(setMethod);
      return setMethod;
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
      return null;
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

    LOG.assertTrue(modifierList != null);
    modifierList.addAfter(factory.createAnnotationFromText("@" + annotationQName, listOwner), null);
  }

  public static String suggestPropertyName(Project project, PsiField field) {
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
    VariableKind kind = codeStyleManager.getVariableKind(field);
    return codeStyleManager.variableNameToPropertyName(field.getName(), kind);
  }
View Full Code Here

Examples of org.editorconfig.configmanagement.CodeStyleManager

    public ConfigProjectComponent(Project project) {
        this.project = project;

        // Register project-level config managers
        MessageBus bus = project.getMessageBus();
        codeStyleManager = new CodeStyleManager(project);
        EditorSettingsManager editorSettingsManager = new EditorSettingsManager();
        EncodingManager encodingManager = new EncodingManager(project);
        LineEndingsManager lineEndingsManager = new LineEndingsManager(project);
        bus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, codeStyleManager);
        bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, encodingManager);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.