package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;

public final class MainPanel extends JPanel {
    private final JTextArea textArea = new JTextArea();
    private final JScrollPane scroll = new JScrollPane(textArea);

    public MainPanel() {
        super(new BorderLayout());
        StringBuilder sb = new StringBuilder();
        String dummy   = "aaaaaaaaaaaaa\n";
        String comment = "#comment\n";
        for (int i = 0; i < 200; i++) {
            sb.append(dummy);
            if (i % 16 == 0) {
                sb.append(comment);
            }
        }
        textArea.setText(sb.toString());
        scroll.setRowHeaderView(new LineNumberView(textArea));
        textArea.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));

        JButton button = new JButton("count commented lines: startsWith(\"#\")");

        button.addActionListener(e -> {
            int count = 0;
            StringTokenizer st = new StringTokenizer(textArea.getText(), "\n");
            while (st.hasMoreTokens()) {
                //if (st.nextToken().startsWith("#")) {
                //if (st.nextToken().charAt(0) == '#') {
                if (st.nextToken().codePointAt(0) == '#') {
                    count++;
                }
            }
//             //String#split >>>>
//             for (String line: textArea.getText().split("\\n")) {
//                 if (!line.isEmpty() && line.codePointAt(0) == '#') {
//                     count++;
//                 }
//             }
//             //<<<< String#split
//
//             //LineNumberReader >>>>
//             try (java.io.LineNumberReader lnr = new java.io.LineNumberReader(new java.io.StringReader(textArea.getText()))) {
//                 String line = null;
//                 while ((line = lnr.readLine()) != null) {
//                     if (!line.isEmpty() && line.codePointAt(0) == '#') {
//                         count++;
//                     }
//                 }
//             } catch (java.io.IOException ex) {
//                 ex.printStackTrace();
//             }
//             //<<<< LineNumberReader
//
//             //ElementCount >>>>
//             Document doc = textArea.getDocument();
//             Element root = doc.getDefaultRootElement();
//             try {
//                 for (int i = 0; i < root.getElementCount(); i++) {
//                     Element elem = root.getElement(i);
//                     String line = doc.getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset());
//                     if (line.codePointAt(0) == '#') {
//                         count++;
//                     }
//                 }
//             } catch (BadLocationException ex) {
//                 ex.printStackTrace();
//             }
//             //<<<< ElementCount

            JOptionPane.showMessageDialog(scroll, "commented lines: " + count, "title", JOptionPane.INFORMATION_MESSAGE);
        });
        //frame.getRootPane().setDefaultButton(button);
        EventQueue.invokeLater(() -> getRootPane().setDefaultButton(button));

        add(button, BorderLayout.NORTH);
        add(scroll);
        setPreferredSize(new Dimension(320, 240));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class LineNumberView extends JComponent {
    private static final int MARGIN = 5;
    private final JTextArea textArea;
    private final FontMetrics fontMetrics;
    //private final int topInset;
    private final int fontAscent;
    private final int fontHeight;
    private final int fontDescent;
    private final int fontLeading;

    protected LineNumberView(JTextArea textArea) {
        super();
        this.textArea = textArea;
        Font font   = textArea.getFont();
        fontMetrics = getFontMetrics(font);
        fontHeight  = fontMetrics.getHeight();
        fontAscent  = fontMetrics.getAscent();
        fontDescent = fontMetrics.getDescent();
        fontLeading = fontMetrics.getLeading();
        //topInset    = textArea.getInsets().top;

        textArea.getDocument().addDocumentListener(new DocumentListener() {
            @Override public void insertUpdate(DocumentEvent e) {
                repaint();
            }
            @Override public void removeUpdate(DocumentEvent e) {
                repaint();
            }
            @Override public void changedUpdate(DocumentEvent e) { /* not needed */ }
        });
        textArea.addComponentListener(new ComponentAdapter() {
            @Override public void componentResized(ComponentEvent e) {
                revalidate();
                repaint();
            }
        });
        Insets i = textArea.getInsets();
        setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createMatteBorder(0, 0, 0, 1, Color.GRAY),
            BorderFactory.createEmptyBorder(i.top, MARGIN, i.bottom, MARGIN - 1)));
        setOpaque(true);
        setBackground(Color.WHITE);
        setFont(font);
    }
    private int getComponentWidth() {
        Document doc  = textArea.getDocument();
        Element root  = doc.getDefaultRootElement();
        int lineCount = root.getElementIndex(doc.getLength());
        int maxDigits = Math.max(3, String.valueOf(lineCount).length());
        Insets i = getBorder().getBorderInsets(this);
        return maxDigits * fontMetrics.stringWidth("0") + i.left + i.right;
        //return 48;
    }
    private int getLineAtPoint(int y) {
        Element root = textArea.getDocument().getDefaultRootElement();
        int pos = textArea.viewToModel(new Point(0, y));
        return root.getElementIndex(pos);
    }
    @Override public Dimension getPreferredSize() {
        return new Dimension(getComponentWidth(), textArea.getHeight());
    }
    @Override protected void paintComponent(Graphics g) {
        g.setColor(getBackground());
        Rectangle clip = g.getClipBounds();
        g.fillRect(clip.x, clip.y, clip.width, clip.height);

        g.setColor(getForeground());
        int base  = clip.y;
        int start = getLineAtPoint(base);
        int end   = getLineAtPoint(base + clip.height);
        int y     = start * fontHeight;
        int rmg   = getBorder().getBorderInsets(this).right;
        for (int i = start; i <= end; i++) {
            String text = String.valueOf(i + 1);
            int x = getComponentWidth() - rmg - fontMetrics.stringWidth(text);
            y += fontAscent;
            g.drawString(text, x, y);
            y += fontDescent + fontLeading;
        }
    }
}

@@ -150,24 +150,59 @@
 ava.util.*;%0A
+import java.util.stream.IntStream;%0A
 import javax
@@ -639,37 +639,44 @@
     
-for (int i = 0; i %3C 200; i++)
+IntStream.range(0, 200).forEach(i -%3E
  %7B%0A 
@@ -786,32 +786,34 @@
      %7D%0A        %7D
+);
 %0A        textAre

use IntStream.range(...) instead of for (...)