Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12581 > unrolled thread

I develop a Java program to format Java codes

Started bygearss8888@gmail.com
First post2012-03-02 03:29 -0800
Last post2012-03-02 21:22 -0800
Articles 16 — 7 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  I develop a Java program to format Java codes gearss8888@gmail.com - 2012-03-02 03:29 -0800
    Re: I develop a Java program to format Java codes Novice <novice@example..com> - 2012-03-02 13:44 +0000
    Re: I develop a Java program to format Java codes Lew <noone@lewscanon.com> - 2012-03-02 09:25 -0800
    Re: I develop a Java program to format Java codes Roedy Green <see_website@mindprod.com.invalid> - 2012-03-02 10:04 -0800
      Re: I develop a Java program to format Java codes Lew <noone@lewscanon.com> - 2012-03-02 10:18 -0800
      Re: I develop a Java program to format Java codes Lars Enderin <lars.enderin@telia.com> - 2012-03-02 19:24 +0100
      Re: I develop a Java program to format Java codes Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 17:04 -0500
    Re: I develop a Java program to format Java codes gearss8888@gmail.com - 2012-03-02 15:55 -0800
      Re: I develop a Java program to format Java codes Arne Vajhøj <arne@vajhoej.dk> - 2012-03-02 19:05 -0500
      Re: I develop a Java program to format Java codes Lew <noone@lewscanon.com> - 2012-03-02 16:07 -0800
        Re: I develop a Java program to format Java codes gearss8888@gmail.com - 2012-03-02 19:24 -0800
          Re: I develop a Java program to format Java codes Lew <noone@lewscanon.com> - 2012-03-02 21:20 -0800
      Re: I develop a Java program to format Java codes Wanja Gayk <brixomatic@yahoo.com> - 2012-03-10 13:01 +0100
        Re: I develop a Java program to format Java codes Roedy Green <see_website@mindprod.com.invalid> - 2012-03-15 03:42 -0700
    Re: I develop a Java program to format Java codes gearss8888@gmail.com - 2012-03-02 18:57 -0800
      Re: I develop a Java program to format Java codes Lew <noone@lewscanon.com> - 2012-03-02 21:22 -0800

#12581 — I develop a Java program to format Java codes

Fromgearss8888@gmail.com
Date2012-03-02 03:29 -0800
SubjectI develop a Java program to format Java codes
Message-ID<5690138.193.1330687781011.JavaMail.geo-discussion-forums@ynca15>
The program can format Java codes, the codes formatted will have correct indent spaces.

//----------
/*
Modified: 2012-3-1
it can format java codes so as to get the correct indent spaces.


*/
import java.io.IOException;//引入类
import java.io.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JFileChooser;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

public class Tidy extends JFrame {
    JButton SelectFilebtn, OKbtn;
    JTextField FileNameField;
    String TabBlank = "    "; // 每一次tab的空格大小,这里为默认的四个空格
    int HowManyTab = 0;
    boolean HaveUnCleanRow = false; // 记录有没有编写不规整的程序代码,如果有弹出对话框请用户改正再关闭控制台,如果没有,不显示对话框。
    boolean ForWhileIfBlock = false; // 标志这一行是否for, while or if 开头但却没有{}符号,这说明这个块只有一行。
    public Tidy () {
        this.setTitle( "文件整理器");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.WEST; //设定Layout的位置
        gbc.insets = new Insets(2,2,2,2); //设定与边界的距离(上,左,下,右)
        SelectFilebtn = new JButton("选择文件");
        SelectFilebtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                do_SelectFilebtn_actionPerformed(e);
            }
        });
        FileNameField = new JTextField("",40);
        gbc.gridy=1;
        gbc.gridx=0;
        this.add(SelectFilebtn, gbc);
        gbc.gridx=1;
        this.add(FileNameField, gbc);
        //--------------
        OKbtn = new JButton("OK");
        OKbtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String FileName = FileNameField.getText();
                do_OKbtn_actionPerformed(e, FileName);
            }
        });
        gbc.gridy=2;
        gbc.gridx=0;
        this.add(OKbtn, gbc);
        //---------------------
        this.pack();
        this.setVisible(true);
    }
    
    protected void do_SelectFilebtn_actionPerformed (ActionEvent e) {
        JFileChooser chooser = new JFileChooser();// 创建文件选择器
        int option = chooser.showOpenDialog(this);// 显示文件打开对话框
        if (option == JFileChooser.APPROVE_OPTION) {// 判断用户是否选定文件
            File file = chooser.getSelectedFile();// 获取用户选择文件
            FileNameField.setText(file.getAbsolutePath());// 把选择的文件路径显示在文本框中
        }
    }
    
    protected void do_OKbtn_actionPerformed(ActionEvent e, String ThisFile) {
        if (!ThisFile.equals("")) {
            HowManyTab = 0;
            ReadAndCombFile(ThisFile); // 文件名不能为空
        }
    }
    // 根据{和}的个数决定每一行前面需要添加多少个tab空格
    String FileInManyLines (String oneline, int CombRow, String Suffix) {
        String PreffixStr; // 这是每一行开始的空格,它是用来方便阅读的
        String TrimIt = oneline.trim();
        String newoneline = "";
        int Diff = 0;
        // Java程序
        if (Suffix.equals(".java")) {
            int Conutleft = strFind(TrimIt, "{", 0);
            int ConutRight = strFind(TrimIt, "}", 0);
            Diff = Conutleft - ConutRight;
            // 如果前面一行只有一个for, while or if但没有{},所以下面一行就缩进了
            if ((Conutleft == 0) && (ConutRight == 0) && ForWhileIfBlock)
                Diff = 50;
            // for, while or if 开头,但是却没有使用{},说明这个块只有一行。
            if ((Conutleft == 0) && (ConutRight == 0) && ((TrimIt.startsWith("for")) || (TrimIt.startsWith("while")) || (TrimIt.startsWith("if")) || (TrimIt.startsWith("else")) || (TrimIt.startsWith("else if")))) {
                ForWhileIfBlock = true;
                Diff= 100;
            }
            switch (Diff) {
                case 1 : {
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    HowManyTab = HowManyTab + 1;
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
                case -1 : {
                    HowManyTab = HowManyTab - 1;
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
                case 0 : {
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
                case 50 :{
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    HowManyTab = HowManyTab - 1;
                    ForWhileIfBlock = false;
                    break;
                }
                case 100 : {
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    HowManyTab = HowManyTab + 1;
                    break;
                }
                default: {
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    System.out.println("第"+CombRow+"行"+"编写不规整,请改正!");
                    HaveUnCleanRow = true; // 程序最后弹出对话框提醒用户这个程序有编写不规整的代码。
                }
            }
            }  else if (Suffix.equals(".f90") || Suffix.equals(".f95")) { // Fortran程序
            String LowCaseTrimIt = TrimIt.toLowerCase();
            if (LowCaseTrimIt.startsWith("program") || LowCaseTrimIt.startsWith("module") || LowCaseTrimIt.startsWith("subroutine") || ((strFind(LowCaseTrimIt, "function", 0) == 1)) || LowCaseTrimIt.startsWith("do ") || (LowCaseTrimIt.startsWith("if") && (LowCaseTrimIt.endsWith("then"))) || LowCaseTrimIt.startsWith("select") || LowCaseTrimIt.startsWith("case")) {
                Diff = 1;
            }
            else if (LowCaseTrimIt.startsWith("end ") || LowCaseTrimIt.startsWith("enddo") || LowCaseTrimIt.startsWith("endif")) {
                Diff = 2;
            }
            else if (LowCaseTrimIt.startsWith("else")) {
                Diff = 3;
            }
            else
                {Diff = 100;}
                switch (Diff) {
                    case 1 : {
                        PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    HowManyTab = HowManyTab + 1;
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
                case 2 : {
                    HowManyTab = HowManyTab - 1;
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
                case 3 : {
                    HowManyTab = HowManyTab - 1;
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    HowManyTab = HowManyTab + 1;
                    break;
                }
                case 100 : {
                    PreffixStr = ManyTabStr (HowManyTab, TabBlank);
                    newoneline = PreffixStr + TrimIt; // 把前缀空格添加到这一行前面
                    break;
                }
            }
            } else {// 其他格式的文件
            newoneline = oneline;
        }
        return 	newoneline;
    }
    // 生成一个n个tab空格的空白字符串
    String ManyTabStr (int howmany, String TabBlank) {
        String Str = "";
        for (int i = 0; i < howmany; i++)
            Str = Str + TabBlank;
        return Str;
    }
    // 方法strFind用于实现字符串查找,返回匹配的次数
    public int strFind(String s1, String s2, int pos) {
        // 变量i和j分别表示主串和模式串中当前字符串的位置,k表示匹配次数
        int i, j, k = 0;
        // pos代表主串中开始比较的位置
        // i=pos;
        i = 0;// 如果把i=pos改成此句将不从鼠标位置开始找,而是直接从字符串头开始找,i决定着开如查找的位置
        j = 0;
        while (i < s1.length() && j < s2.length()) {
            if (s1.charAt(i) == s2.charAt(j)) {
                ++i;
                ++j;
                if (j == s2.length()) {
                    // j=s2.length()表示字符串匹配成功,匹配成功次数加1
                    k = k + 1;
                    // 将指示主串和模式中当前字符的变量i和j进行回退
                    i = i - j + 1;
                    j = 0;
                }
                else {
                    i = i - j + 1;
                    j = 0;
                }
            }
            i++;
        }
        return k;// 为什么这个while循环没有一个循环控制器呢,我还没有理解它的结构?
    }
    
    //以行为单位读取文件
    String[] readFileByLines (String fileName){
        File file = new File(fileName);
        ArrayList<String> alllinks = new ArrayList<String>();
        BufferedReader reader = null;//创建缓存读取
        try {
            reader = new BufferedReader(new FileReader(file));//将文件放在缓存读取中
            String tempString = null;
            //一次读入一行,直到读入null为文件结束
            while ((tempString = reader.readLine()) != null){
                alllinks.add(tempString);
            }
            reader.close();
            } catch (IOException e) {//捕获异常
            e.printStackTrace();
            } finally {//内容总执行
            if (reader != null) {
                try {
                    reader.close();//关闭缓存读取
                    } catch (IOException e1) {
                }
            }
        }
        String[] links = new String[alllinks.size()];
        for (int count = 0; count < alllinks.size(); count++) {links[count] = alllinks.get(count);}
        return links;
    }
    
    // 把字符串数组写入文件, 即按行写入文件
    public boolean stringArrayToFile(String[] arrayres, String filePath) {
        boolean flag = true;
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        StringBuffer temp = new StringBuffer();
        for (String one : arrayres) {
            temp.append(one);
            temp.append("\n");
        }
        int x = temp.lastIndexOf("\n");
        temp.replace(x, temp.length(), "");
        String res = temp.toString();
        try {
            File distFile = new File(filePath);						//创建文件
            if (!distFile.getParentFile().exists())					//判断父路径是文件夹是否存在
                distFile.getParentFile().mkdirs();					//可以在不存在的目录中创建文件夹
            bufferedReader = new BufferedReader(
            new StringReader(res));							//将原字符串读入缓冲
            bufferedWriter = new BufferedWriter(
            new FileWriter(distFile));						//将文件写入缓冲
            char buf[] = new char[1024];							// 字符缓冲区
            int len;
            while ((len = bufferedReader.read(buf)) != -1) {		//while循环
                bufferedWriter.write(buf, 0, len);					//将字符串写入文件
            }
            bufferedWriter.flush();									//刷新写入流的缓冲
            bufferedReader.close();									//关闭读出流
            bufferedWriter.close();									//关闭写入流
            } catch (IOException e) {									//捕获异常
            e.printStackTrace();
            flag = false;
            return flag;
            } finally {												//finally方法总被执行
            if (bufferedReader != null) {							//判断读出流是否为空
                try {
                    bufferedReader.close();							//确保读出流关闭
                    } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return flag;												//返回布尔类型
    }
    
    void ReadAndCombFile (String filename) {
        String[] FileDivideToManyLines = readFileByLines (filename);
        // 获取文件的后缀名
        int FileSuffixLoc = filename.lastIndexOf(".");
        String FileSuffix = filename.substring(FileSuffixLoc, filename.length());
        ArrayList<String> FileCombed = new ArrayList <String> (); // 储存加入合适前面空行的新的一行字符
        int RowNumber = 1; // 记录现在处理第几行的代码,使用这个行数提醒开发者哪里出错了
        for (String oneline : FileDivideToManyLines) {
            String newLine = FileInManyLines (oneline, RowNumber, FileSuffix);
            FileCombed.add(newLine);
            RowNumber = RowNumber + 1;
        }
        String[] FileCombInStr = new String[FileCombed.size()];
        for (int count = 0; count < FileCombed.size(); count ++) {FileCombInStr [count] = FileCombed.get(count);}
        stringArrayToFile (FileCombInStr, filename);
        if (HaveUnCleanRow) {JOptionPane.showMessageDialog(null, "有不规整的代码,请改正。");}
    }
    
    public static void main(String[] args)  {
        Tidy TideFiles = new Tidy();
    }
}

[toc] | [next] | [standalone]


#12582

FromNovice <novice@example..com>
Date2012-03-02 13:44 +0000
Message-ID<XnsA00A59F5371jpnasty@94.75.214.39>
In reply to#12581
gearss8888@gmail.com wrote in
news:5690138.193.1330687781011.JavaMail.geo-discussion-forums@ynca15: 

> The program can format Java codes, the codes formatted will have
> correct indent spaces. 
> 

> //----------
> /*
> Modified: 2012-3-1
> it can format java codes so as to get the correct indent spaces.
> 
> 
> */
> import java.io.IOException;//引入类
> import java.io.*;
> import java.io.BufferedReader;

[snip]

Are you simply trying to tell us that you have written a program that 
formats Java source code so that we know? Or do you have a question of 
some kind?

Also, are you aware that at least some popular IDEs already have built-in 
source code editors with user-adjustable formatting? For example, Eclipse 
has configurable editors so that you can tell it how many spaces you want 
to indent, whether you want to use Tabs or Spaces, whether you want line 
breaks before open braces or after close braces, etc. etc. 

That means I'd have no real interest in using your program since my IDE 
already does these things in a satisfactory way. I just mention this in 
case you were hoping a lot of people would use or even buy this code.

-- 
Novice

[toc] | [prev] | [next] | [standalone]


#12587

FromLew <noone@lewscanon.com>
Date2012-03-02 09:25 -0800
Message-ID<jiqvq9$hds$1@news.albasani.net>
In reply to#12581
On 03/02/2012 03:29 AM, gearss8888@gmail.com wrote:
> The program can format Java codes, the codes formatted will have correct indent spaces.
>
> //----------
> /*
> Modified: 2012-3-1
> it can format java codes so as to get the correct indent spaces.
>
>
> */
> import java.io.IOException;//引入类
> import java.io.*;

It is better to use single-type imports than import-on-demand. Certainly don't 
do both on the same types.

> import java.io.BufferedReader;
> import java.io.BufferedWriter;
> import java.io.File;
> import java.io.FileWriter;
> import java.io.InputStreamReader;
> import java.io.StringReader;
> import java.io.StringWriter;
> import java.io.FileInputStream;
> import java.io.FileReader;
> import java.io.InputStream;
> import java.io.Reader;
> import java.util.ArrayList;
> import javax.swing.JOptionPane;
> import java.awt.event.*;
> import java.awt.*;
> import javax.swing.*;
> import java.awt.Graphics;

Don't mix single-type imports and import-on-demand for the same types.

> import java.awt.Color;
> import javax.swing.JFileChooser;
> import javax.swing.SwingConstants;
> import javax.swing.UIManager;
>
> public class Tidy extends JFrame {
>      JButton SelectFilebtn, OKbtn;

The Java naming convention is to use  lower-case first letter in variable and 
method identifiers, and camel case thereafter. Thus, 'selectFileBtn', not 
'SelectFilebtn'.

>      JTextField FileNameField;
>      String TabBlank = "    "; // 每一次tab的空格大小,这里为默认的四个空格

Is there a tab in there? If so, you should use '\t' rather than an embedded TAB.

>      int HowManyTab = 0;

There is no need to set the default value twice like this, except there's 
really no harm, either. In this case you could argue that the redundant 
initialization helps document your intent.

>      boolean HaveUnCleanRow = false; // 记录有没有编写不规整的程序代码,如果有弹出对话框请用户改正再关闭控制台,如果没有,不显示对话框。
>      boolean ForWhileIfBlock = false; // 标志这一行是否for, while or if 开头但却没有{}符号,这说明这个块只有一行。
>      public Tidy () {

Your constructor is a bit unwieldy - too long and complicated. I suggest that 
you refactor the fancy logic into a separate private method.

>          this.setTitle( "文件整理器");
>          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>          this.setLayout(new GridBagLayout());
>          GridBagConstraints gbc = new GridBagConstraints();
>          gbc.anchor = GridBagConstraints.WEST; //设定Layout的位置
>          gbc.insets = new Insets(2,2,2,2); //设定与边界的距离(上,左,下,右)
>          SelectFilebtn = new JButton("选择文件");
>          SelectFilebtn.addActionListener(new ActionListener() {
>              public void actionPerformed(ActionEvent e) {
>                  do_SelectFilebtn_actionPerformed(e);
>              }
>          });
>          FileNameField = new JTextField("",40);
>          gbc.gridy=1;
>          gbc.gridx=0;
>          this.add(SelectFilebtn, gbc);
>          gbc.gridx=1;
>          this.add(FileNameField, gbc);
>          //--------------
>          OKbtn = new JButton("OK");
>          OKbtn.addActionListener(new ActionListener() {
>              public void actionPerformed(ActionEvent e) {
>                  String FileName = FileNameField.getText();
>                  do_OKbtn_actionPerformed(e, FileName);
>              }
>          });
>          gbc.gridy=2;
>          gbc.gridx=0;
>          this.add(OKbtn, gbc);
>          //---------------------
>          this.pack();
>          this.setVisible(true);
>      }

I strongly recommend that the 'setVisible()' call happen after the constructor.

>
>      protected void do_SelectFilebtn_actionPerformed (ActionEvent e) {

Why is this method 'protected'?

>          JFileChooser chooser = new JFileChooser();// 创建文件选择器
>          int option = chooser.showOpenDialog(this);// 显示文件打开对话框
>          if (option == JFileChooser.APPROVE_OPTION) {// 判断用户是否选定文件
>              File file = chooser.getSelectedFile();// 获取用户选择文件
>              FileNameField.setText(file.getAbsolutePath());// 把选择的文件路径显示在文本框中
>          }
>      }
>
>      protected void do_OKbtn_actionPerformed(ActionEvent e, String ThisFile) {

Why is this method 'protected'?

Naming convention: 'thisFile', not 'ThisFile'.

>          if (!ThisFile.equals("")) {

You forgot to check for the parameter being 'null'. This could cause a 
'NullPointerException'. Tsk, tsk.

>              HowManyTab = 0;
>              ReadAndCombFile(ThisFile); // 文件名不能为空
>          }
>      }
>      // 根据{和}的个数决定每一行前面需要添加多少个tab空格
>      String FileInManyLines (String oneline, int CombRow, String Suffix) {

Why is this method package-private?

Naming convention. 'fileInManyLines()'.  'combRow'. 'suffix'.

>          String PreffixStr; // 这是每一行开始的空格,它是用来方便阅读的

There's only one "f" in "prefix". Don't put the type of the variable in the 
name ("Str")!

> ... [snip] ...
>      public static void main(String[] args)  {
>          Tidy TideFiles = new Tidy();
>      }
> }

Start GUIs on the Event Dispatch Thread (EDT)!

Do file operations *off* the EDT!

I suggest reading the Swing tutorial and other references about Swing 
programming. Also, study the Java coding conventions, around since 1999. Your 
code is not thread-safe. Heck, it's not any kind of safe - you leave room for 
runtime exceptions, you don't comment the strange parts of your logic (like 
your switch on 'Diff' [sic] and the magic values it assumes). Your 
pretty-print source is indented incorrectly - how good can your pretty-printer 
be if you don't indent correctly in the first place? You don't control the 
scope of your variables well ('i' and 'j' in 'strFind()', 'flag' and 
'bufferedWriter' in 'stringArrayToFile()'), you don't declare constant those 
that should be constants ('TabBlank' [sic]), and you redundantly initialize 
variables ('BufferedReader reader = null;', 'int HowManyTab = 0;', etc.). You 
declare methods as 'protected' or package-private willy-nilly without 
explanation for the choices.

I will venture to guess that you wrote this as an exercise and though you 
didn't explicitly say so, posted it here for critique. There are so many Java 
pretty-printers out there already. Use one on your own code, why don't you?

Your code needs good formatting, proper naming, corrected access control, 
controlled scope, controlled heritability, and the bugs eliminated.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#12588

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-03-02 10:04 -0800
Message-ID<ok22l71lm06p3l8v9bt448ok0cm95vjkma@4ax.com>
In reply to#12581
On Fri, 2 Mar 2012 03:29:41 -0800 (PST), gearss8888@gmail.com wrote,
quoted or indirectly quoted someone who said :

>   PreffixStr =3D ManyTabStr (HowManyTab, TabBlank);
>                    HowManyTab =3D HowManyTab + 1;
>                    newoneline =3D PreffixStr + TrimIt; // =B0=D1=C7=B0=D7=
>=BA=BF=D5=B8=F1=CC=ED=BC=D3=B5=BD=D5=E2=D2=BB=D0=D0=C7=B0=C3=E6
>                    break;
>                }
>                case -1 : {

the process of posting on a newsreader is scrambling your code. Try
posting it somewhere and giving the URL.

see http://mindprod.com/jgloss/sscce.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
One of the most useful comments you can put in a program is 
"If you change this, remember to change ?XXX? too".
 

[toc] | [prev] | [next] | [standalone]


#12589

FromLew <noone@lewscanon.com>
Date2012-03-02 10:18 -0800
Message-ID<jir2tc$nrj$1@news.albasani.net>
In reply to#12588
Roedy Green wrote:
> gearss8888@gmail.com wrote, quoted or indirectly quoted someone who said :
>
>>    PreffixStr =3D ManyTabStr (HowManyTab, TabBlank);
>>                     HowManyTab =3D HowManyTab + 1;
>>                     newoneline =3D PreffixStr + TrimIt; // =B0=D1=C7=B0=D7=
>> =BA=BF=D5=B8=F1=CC=ED=BC=D3=B5=BD=D5=E2=D2=BB=D0=D0=C7=B0=C3=E6
>>                     break;
>>                 }
>>                 case -1 : {
>
> the process of posting on a newsreader is scrambling your code. Try
> posting it somewhere and giving the URL.
>
> see http://mindprod.com/jgloss/sscce.html

He *gave* us an SSCCE, already!

It wasn't scrambled here. Perhaps it's something specific to your newsreader. 
It clearly wasn't scrambled by "the process of posting on a newsreader" or 
everyone would've seen the problem.

His code even survived my newsreader placing it into the reply as "quoted 
text", without loss of formatting or other issues. Does the quoted code look 
scrambled in my reply? That would be a good data point.

I do note however that your reply is scrambled, in the sense that it didn't 
transcribe the Chinese characters. I infer that your newsreader used the wrong 
text encoding. You should fix that.

I recommend against the OP's posting the code on a separate URL. It's easier 
to get answers when the respondents have everything they need in one place. I 
was grateful that they included their SSCCE in their post.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#12590

FromLars Enderin <lars.enderin@telia.com>
Date2012-03-02 19:24 +0100
Message-ID<4F51105C.6010001@telia.com>
In reply to#12588
2012-03-02 19:04, Roedy Green skrev:
> On Fri, 2 Mar 2012 03:29:41 -0800 (PST), gearss8888@gmail.com wrote,
> quoted or indirectly quoted someone who said :
> 
>>   PreffixStr =3D ManyTabStr (HowManyTab, TabBlank);
>>                    HowManyTab =3D HowManyTab + 1;
>>                    newoneline =3D PreffixStr + TrimIt; // =B0=D1=C7=B0=D7=
>> =BA=BF=D5=B8=F1=CC=ED=BC=D3=B5=BD=D5=E2=D2=BB=D0=D0=C7=B0=C3=E6
>>                    break;
>>                }
>>                case -1 : {
> 
> the process of posting on a newsreader is scrambling your code. Try

Blame your own newsreader! I had no trouble reading the OP with
Thunderbird, Chinese comments and all.
The headers are a bit unusual, granted:
Content-Type: text/plain; charset=GB2312
Content-Transfer-Encoding: quoted-printable
(which your newsreader ignores completely)

> posting it somewhere and giving the URL.

-- 
Lars Enderin

[toc] | [prev] | [next] | [standalone]


#12592

FromArne Vajhøj <arne@vajhoej.dk>
Date2012-03-02 17:04 -0500
Message-ID<4f5143ec$0$293$14726298@news.sunsite.dk>
In reply to#12588
On 3/2/2012 1:04 PM, Roedy Green wrote:
> On Fri, 2 Mar 2012 03:29:41 -0800 (PST), gearss8888@gmail.com wrote,
> quoted or indirectly quoted someone who said :
>>    PreffixStr =3D ManyTabStr (HowManyTab, TabBlank);
>>                     HowManyTab =3D HowManyTab + 1;
>>                     newoneline =3D PreffixStr + TrimIt; // =B0=D1=C7=B0=D7=
>> =BA=BF=D5=B8=F1=CC=ED=BC=D3=B5=BD=D5=E2=D2=BB=D0=D0=C7=B0=C3=E6
>>                     break;
>>                 }
>>                 case -1 : {
>
> the process of posting on a newsreader is scrambling your code. Try
> posting it somewhere and giving the URL.

You need a newsreader that understands Quoted Printable.

Something from late 90's or later should support that.

Arne

[toc] | [prev] | [next] | [standalone]


#12606

Fromgearss8888@gmail.com
Date2012-03-02 15:55 -0800
Message-ID<15449731.9.1330732532136.JavaMail.geo-discussion-forums@ynbq18>
In reply to#12581
I am a Java beginner, perhaps it is my third Java program, sorry for my poor skill in Java. I donot use Eclipse to write Java codes, it is not good at editting codes, I prefer notepad ++ (http://notepad-plus-plus.org/download/v5.9.8.html) and SciTE(http://www.scintilla.org), Eclipse is a good integrated tool for developing Java program, but it is not the suitable editor to purely edit codes. I learn a lot from people's comment, later I will continue to post my codes here for comments.
I donot know how to post long codes, I donot have space to attach my program.

[toc] | [prev] | [next] | [standalone]


#12608

FromArne Vajhøj <arne@vajhoej.dk>
Date2012-03-02 19:05 -0500
Message-ID<4f516039$0$285$14726298@news.sunsite.dk>
In reply to#12606
On 3/2/2012 6:55 PM, gearss8888@gmail.com wrote:
> I am a Java beginner, perhaps it is my third Java program, sorry for my poor skill in Java. I donot use Eclipse to write Java codes, it is not good at editting codes, I prefer notepad ++ (http://notepad-plus-plus.org/download/v5.9.8.html) and SciTE(http://www.scintilla.org), Eclipse is a good integrated tool for developing Java program, but it is not the suitable editor to purely edit codes. I learn a lot from people's comment, later I will continue to post my codes here for comments.
> I donot know how to post long codes, I donot have space to attach my program.

I think you will find out that >95% of Java developers use Eclipse or
similar Java IDE to edit Java code.

Arne

[toc] | [prev] | [next] | [standalone]


#12609

FromLew <noone@lewscanon.com>
Date2012-03-02 16:07 -0800
Message-ID<jirncp$1gj$2@news.albasani.net>
In reply to#12606
On 03/02/2012 03:55 PM, gearss8888@gmail.com wrote:
> I am a Java beginner, perhaps it is my third Java program, sorry for my poor skill in Java. I donot use Eclipse to write Java codes, it is not good at editting codes, I prefer notepad ++ (http://notepad-plus-plus.org/download/v5.9.8.html) and SciTE(http://www.scintilla.org), Eclipse is a good integrated tool for developing Java program, but it is not the suitable editor to purely edit codes. I learn a lot from people's comment, later I will continue to post my codes here for comments.
> I donot know how to post long codes, I donot have space to attach my program.

I disagree. Eclipse is entirely suitable as a code editor, even if you ignore 
all its other features. Ditto NetBeans. Ditto many others.

I am interested in the details of why you find Eclipse unsuitable. What are they?

Don't post long programs. Post simple, short, complete, compilable examples 
(SSCCEs) that reveal your difficulty.
http://sscce.org/

What you posted in the beginning was an SSCCE. It was enough from my point of 
view, anyway.

As for not having space to attach your programs, sure you do. You've already 
done it. Not that you should attach anything, you should do exactly as you did 
and include it in the body of your post.

However, this is a discussion group, so when people ask you questions you 
should participate in the discussion.

> Novice wrote:
>> Are you simply trying to tell us that you have written a program that
>> formats Java source code so that we know? Or do you have a question of
>> some kind?

He has a point. We don't know why you came to us. Why did you?

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#12618

Fromgearss8888@gmail.com
Date2012-03-02 19:24 -0800
Message-ID<30936032.148.1330745050532.JavaMail.geo-discussion-forums@ynil17>
In reply to#12609
> am interested in the details of why you find Eclipse unsuitable. What are they?
------------
before I used SciTe to edit rebol codes, so I get used to the operation of SciTE, it is one the reasons that I continue to use the old editor. I tried Ecplise, I find it cannot hightlight the matched "{" or "}", I am afraid it is because I donot know how to properly configure Ecplise. Addtionall, I find it is inconvenient to use SEARCH function in Ecplise.

[toc] | [prev] | [next] | [standalone]


#12619

FromLew <noone@lewscanon.com>
Date2012-03-02 21:20 -0800
Message-ID<jis9m5$so3$1@news.albasani.net>
In reply to#12618
On 03/02/2012 07:24 PM, gearss8888@gmail.com wrote:
>> am interested in the details of why you find Eclipse unsuitable. What are they?
> ------------
> before I used SciTe to edit rebol codes, so I get used to the operation of SciTE,
> it is one the reasons that I continue to use the old editor. I tried Ecplise,
> I find it cannot hightlight the matched "{" or "}", I am afraid it is because I
> donot know how to properly configure Ecplise.

You are right.

There is a setting in Eclipse to highlight matching braces.

With any highlighting editor one has to invest time to configure the various 
syntax-coloring, indentation, layout, whatever options to our taste. If you 
don't, it's not the editor's fault.

> Addtionall, I find it is inconvenient to use SEARCH function in Ecplise.

Again, what's inconvenient about it? You type Ctrl-F, type in the search term 
and hit ENTER. Most of the GUI apps that allow search from browsers to editors 
to word processors to spreadsheets and beyond use the exact same idiom.

What does SciTE do that's better, read your mind?

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#12833

FromWanja Gayk <brixomatic@yahoo.com>
Date2012-03-10 13:01 +0100
Message-ID<MPG.29c560f1efa352dd9896fb@202.177.16.121>
In reply to#12606
In article <15449731.9.1330732532136.JavaMail.geo-discussion-
forums@ynbq18>, gearss8888@gmail.com says...
> 
> I am a Java beginner

As a beginner in programming, you should really better start with a 
lower hanging fruit. If you have done this in other languages before, 
and are just a beginner in Java, good luck. 

Still, if you're new to programming, you will probably quite quickly see 
that this is not as trivial as you thought it was - if you want to do it 
right that is.
Properly formating Java code involves first parsing the code into an 
AST, an abstract syntax tree, and then exporting the AST to text using 
your own formatting-rules for indentation, spaces, line breaks, etc.
You wil probably quite quickly hit the first problem with simple 
mathematic expressions, lika a=(b+c)*t, let alone making a distinction 
with string-concatenation and variables and method calls within those.

Kind regards,


-- 
..Alesi's problem was that the back of the car was jumping up and down 
dangerously - and I can assure you from having been teammate to 
Jean Alesi and knowing what kind of cars that he can pull up with, 
when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

[toc] | [prev] | [next] | [standalone]


#13017

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-03-15 03:42 -0700
Message-ID<9oh3m7lh5rt7kl8innshakvdm9ed88dnau@4ax.com>
In reply to#12833
On Sat, 10 Mar 2012 13:01:20 +0100, Wanja Gayk <brixomatic@yahoo.com>
wrote, quoted or indirectly quoted someone who said :

>
>As a beginner in programming, you should really better start with a 
>lower hanging fruit.

For example, try reflowing some text to make sure no lines are longer
than n.  

Then add blank line collapsing, preserve blank lines or multiple blank
lines as one blank line. 

I have a project in limbo right now to reflow HTML.  You might look at
IntelliJ for a remarkably complete set of specifications on just how
you want the final result so look.

see http://mindprod.com/jgloss/intellij.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
One of the most useful comments you can put in a program is 
"If you change this, remember to change ?XXX? too".
 

[toc] | [prev] | [next] | [standalone]


#12617

Fromgearss8888@gmail.com
Date2012-03-02 18:57 -0800
Message-ID<27159758.159.1330743479554.JavaMail.geo-discussion-forums@ynlp18>
In reply to#12581
>He has a point. We don't know why you came to us. Why did you?
-------
My work doesnot need Java, I learn Java just for fun. Find some people to talk about something is interesting.

[toc] | [prev] | [next] | [standalone]


#12620

FromLew <noone@lewscanon.com>
Date2012-03-02 21:22 -0800
Message-ID<jis9ql$sqg$1@news.albasani.net>
In reply to#12617
On 03/02/2012 06:57 PM, gearss8888@gmail.com wrote:
>> He has a point. We don't know why you came to us. Why did you?
> -------
> My work doesnot need Java, I learn Java just for fun. Find some people to talk about something is interesting.

OK, but why did you come to us with that first post?

You were asked a specific question that you keep avoiding for some reason. 
I'll repeat it, since you edited it out:

> Novice wrote:
>> Are you simply trying to tell us that you have written a program that
>> formats Java source code so that we know? Or do you have a question of
>> some kind?

In other words, what was the specific point you made with your original post?

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web