src/jdk.jshell/share/classes/jdk/jshell/MaskCommentsAndModifiers.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 41940 langtools/src/jdk.jshell/share/classes/jdk/jshell/MaskCommentsAndModifiers.java@048d559e9da7
child 51766 3ca7d5385653
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 33362
diff changeset
    25
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
package jdk.jshell;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
import java.util.Set;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
import java.util.stream.Collectors;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
import java.util.stream.Stream;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
/**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
 * Within a String, mask code comments and ignored modifiers (within context).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 * @author Robert Field
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
class MaskCommentsAndModifiers {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    39
    private final static Set<String> IGNORED_MODIFIERS =
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
            Stream.of( "public", "protected", "private", "static", "final" )
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
                    .collect( Collectors.toSet() );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    43
    private final static Set<String> OTHER_MODIFIERS =
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    44
            Stream.of( "abstract", "strictfp", "transient", "volatile", "synchronized", "native", "default" )
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    45
                    .collect( Collectors.toSet() );
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    46
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    47
    // Builder to accumulate non-masked characters
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
    private final StringBuilder sbCleared = new StringBuilder();
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    49
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    50
    // Builder to accumulate masked characters
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
    private final StringBuilder sbMask = new StringBuilder();
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    52
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    53
    // The input string
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
    private final String str;
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    55
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    56
    // Entire input string length
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
    private final int length;
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    58
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    59
    // The next character position
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
    private int next = 0;
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    61
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    62
    // The current character
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    63
    private int c;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    64
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    65
    // Do we mask-off ignored modifiers?  Set by parameter and turned off after
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    66
    // initial modifier section
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    67
    private boolean maskModifiers;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    69
    // Does the string end with an unclosed '/*' style comment?
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    70
    private boolean openComment = false;
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    71
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    72
    MaskCommentsAndModifiers(String s, boolean maskModifiers) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        this.str = s;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        this.length = s.length();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        this.maskModifiers = maskModifiers;
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    76
        read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    77
        while (c >= 0) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    78
            next();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    79
            read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
    80
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    83
    String cleared() {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
        return sbCleared.toString();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    87
    String mask() {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
        return sbMask.toString();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    91
    boolean endsWithOpenComment() {
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    92
        return openComment;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
38835
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    95
    /****** private implementation methods ******/
37280d52d723 8131024: JShell: multi-line comment not detected as incomplete
rfield
parents: 34752
diff changeset
    96
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
     * Read the next character
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
    private int read() {
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   101
        return c = (next >= length)
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   102
                ? -1
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   103
                : str.charAt(next++);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   106
    private void unread() {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   107
        if (c >= 0) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   108
            --next;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   109
        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   110
    }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   111
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   112
    private void writeTo(StringBuilder sb, int ch) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        sb.append((char)ch);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
    private void write(int ch) {
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   117
        if (ch != -1) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   118
            writeTo(sbCleared, ch);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   119
            writeTo(sbMask, Character.isWhitespace(ch) ? ch : ' ');
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   120
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
    private void writeMask(int ch) {
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   124
        if (ch != -1) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   125
            writeTo(sbMask, ch);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   126
            writeTo(sbCleared, Character.isWhitespace(ch) ? ch : ' ');
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   127
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
    private void write(CharSequence s) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        for (int cp : s.chars().toArray()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
            write(cp);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
    private void writeMask(CharSequence s) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
        for (int cp : s.chars().toArray()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
            writeMask(cp);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   142
    private void next() {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   143
        switch (c) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   144
            case '\'':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   145
            case '"':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   146
                maskModifiers = false;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
                write(c);
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   148
                int match = c;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   149
                while (read() >= 0 && c != match && c != '\n' && c != '\r') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   150
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   151
                    if (c == '\\') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   152
                        write(read());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
                }
41940
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   155
                write(c); // write match // line-end
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   156
                break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   157
            case '/':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   158
                read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   159
                switch (c) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   160
                    case '*':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   161
                        writeMask('/');
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   162
                        writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   163
                        int prevc = 0;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   164
                        while (read() >= 0 && (c != '/' || prevc != '*')) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   165
                            writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   166
                            prevc = c;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   167
                        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   168
                        writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   169
                        openComment = c < 0;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   170
                        break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   171
                    case '/':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   172
                        writeMask('/');
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   173
                        writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   174
                        while (read() >= 0 && c != '\n' && c != '\r') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   175
                            writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   176
                        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   177
                        writeMask(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   178
                        break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   179
                    default:
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   180
                        maskModifiers = false;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   181
                        write('/');
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   182
                        unread();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   183
                        break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   184
                }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   185
                break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   186
            case '@':
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   187
                do {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   188
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   189
                    read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   190
                } while (Character.isJavaIdentifierPart(c));
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   191
                while (Character.isWhitespace(c)) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   192
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   193
                    read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   194
                }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   195
                // if this is an annotation with arguments, process those recursively
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   196
                if (c == '(') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   197
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   198
                    boolean prevMaskModifiers = maskModifiers;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   199
                    int parenCnt = 1;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   200
                    while (read() >= 0) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   201
                        if (c == ')') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   202
                            if (--parenCnt == 0) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   203
                                break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   204
                            }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   205
                        } else if (c == '(') {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   206
                            ++parenCnt;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   207
                        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   208
                        next(); // recurse to handle quotes and comments
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   209
                    }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   210
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   211
                    // stuff in annotation arguments doesn't effect inside determination
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   212
                    maskModifiers = prevMaskModifiers;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   213
                } else {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   214
                    unread();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   215
                }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   216
                break;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   217
            default:
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   218
                if (Character.isJavaIdentifierStart(c)) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   219
                    StringBuilder sb = new StringBuilder();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   220
                    do {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   221
                        writeTo(sb, c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   222
                        read();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   223
                    } while (Character.isJavaIdentifierPart(c));
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   224
                    unread();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   225
                    String id = sb.toString();
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   226
                    if (maskModifiers && IGNORED_MODIFIERS.contains(id)) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   227
                        writeMask(sb);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   228
                    } else {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   229
                        write(sb);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   230
                        if (maskModifiers && !OTHER_MODIFIERS.contains(id)) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   231
                            maskModifiers = false;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   232
                        }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   233
                    }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   234
                } else {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   235
                    if (!Character.isWhitespace(c)) {
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   236
                        maskModifiers = false;
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   237
                    }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   238
                    write(c);
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   239
                }
048d559e9da7 8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents: 38835
diff changeset
   240
                break;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
}