Package org.eclipse.jdt.core.formatter

Examples of org.eclipse.jdt.core.formatter.CodeFormatter


            DefaultCodeFormatterConstants.INDENT_BY_ONE));
        options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
        options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
        options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
        Document doc = new Document(m_compilationUnit.toString());
        CodeFormatter fmtr = ToolFactory.createCodeFormatter(options);
        String text = doc.get();
        TextEdit edits = fmtr.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
        File gendir = m_package.getGenerateDirectory();
        if (gendir != null) {
            try {
                File file = new File(gendir, m_name + ".java");
                FileWriter fwrit = new FileWriter(file);
View Full Code Here


    options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    TextEdit format = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
    IDocument document = new Document(text);
    format.apply(document);
    return document.get();
  }
View Full Code Here

    //DefaultCodeFormatter.USE_NEW_FORMATTER = true;
    HashMap hashMap = new HashMap();
    hashMap.put( JavaCore.COMPILER_SOURCE, "1.5");
    hashMap.put( JavaCore.COMPILER_COMPLIANCE, "1.5");
    hashMap.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");
    final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(hashMap);
   
    //new JavaFormatter().formatFile(new File("c:/temp/SomeJava.java"), codeFormatter);

  }
View Full Code Here

    options.put(
        DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT,
        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);
View Full Code Here

    options.put(
        DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT,
        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);
View Full Code Here

    options.put(
        DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT,
        DefaultCodeFormatterConstants.TRUE);

    // instantiate the default code formatter with the given options
    final CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(options);
    final TextEdit editCode = codeFormatter.format(
        CodeFormatter.K_COMPILATION_UNIT
            | CodeFormatter.F_INCLUDE_COMMENTS, source, 0,
        source.length(), 0, System.getProperty("line.separator"));

    IDocument document = new Document(source);
View Full Code Here

   /**
    * Format the given {@link String} as a Java source type, using the given Eclipse code format {@link Properties}.
    */
   public static String format(Properties prefs, String source)
   {
      final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(prefs);
      return _format(source, codeFormatter);
   }
View Full Code Here

   public static String format(String source)
   {
       // TODO locate user's eclipse project settings, use those if we can.
       Properties options = readConfig("org.eclipse.jdt.core.prefs");

       final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
       return ensureCorrectNewLines(formatFile(source, codeFormatter));
   }
View Full Code Here

   public static String format(JavaClass javaClass)
   {
      // TODO locate user's eclipse project settings, use those if we can.
      Properties options = readConfig("org.eclipse.jdt.core.prefs");

      final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
      String result = formatFile(javaClass, codeFormatter);

      return result;
   }
View Full Code Here

        .readConfig(pathToConfigFile);
    if (properties.isEmpty()) {
      throw new IllegalStateException("incorrect properties file");
    }

    CodeFormatter codeFormatter = ToolFactory
        .createCodeFormatter(properties);
    return codeFormatter;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.formatter.CodeFormatter

Copyright © 2018 www.massapicom. 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.