|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Free.java | 93.8% | 97.2% | 100% | 96.3% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * * Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * * Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
| 14 | * names of its contributors may be used to endorse or promote products | |
| 15 | * derived from this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | * | |
| 29 | * This software is Open Source Initiative approved Open Source Software. | |
| 30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
| 31 | * | |
| 32 | * This file is part of DrJava. Download the current version of this project | |
| 33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
| 34 | * | |
| 35 | * END_COPYRIGHT_BLOCK*/ | |
| 36 | ||
| 37 | package edu.rice.cs.drjava.model.definitions.reducedmodel; | |
| 38 | ||
| 39 | import static edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelStates.*; | |
| 40 | ||
| 41 | /** Shadowing state that indicates normal, unshadowed text. | |
| 42 | * @version $Id: Free.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 43 | */ | |
| 44 | public class Free extends ReducedModelState { | |
| 45 | public static final Free ONLY = new Free(); | |
| 46 | ||
| 47 | 62 | private Free() { } |
| 48 | ||
| 49 | /** Walk function for when we're not inside a string or comment. Mutually recursive with other walk functions. | |
| 50 | * <ol> | |
| 51 | * <li> atEnd: return | |
| 52 | * <li> If we find / *, * /, or / /, combine them into a single Brace, and keep the cursor on that Brace. | |
| 53 | * <li> If current brace = //, go to next then call updateLineComment.<BR> | |
| 54 | * If current brace = /*, go to next then call updateBlockComment.<BR> | |
| 55 | * If current brace = ", go to next then call updateInsideDoubleQuote.<BR> | |
| 56 | * Else, mark current brace as FREE, go to the next brace, and recur. | |
| 57 | * </ol> | |
| 58 | */ | |
| 59 | 4528 | ReducedModelState update(TokenList.Iterator copyCursor) { |
| 60 | 0 | if (copyCursor.atEnd()) return STUTTER; |
| 61 | ||
| 62 | 4528 | _combineCurrentAndNextIfFind("/", "*", copyCursor); |
| 63 | 4528 | _combineCurrentAndNextIfFind("/", "/", copyCursor); |
| 64 | 4528 | _combineCurrentAndNextIfFind("","", copyCursor); |
| 65 | //if a / preceeds a /* or a // combine them. | |
| 66 | 4528 | _combineCurrentAndNextIfFind("/","/*",copyCursor); |
| 67 | 4528 | _combineCurrentAndNextIfFind("/","//",copyCursor); |
| 68 | 4528 | _combineCurrentAndNextIfEscape(copyCursor); |
| 69 | ||
| 70 | 4528 | String type = copyCursor.current().getType(); |
| 71 | 4528 | if (type.equals("*/")) { |
| 72 | 7 | copyCursor._splitCurrentIfCommentBlock(true,false); |
| 73 | 7 | copyCursor.prev(); |
| 74 | 7 | return STUTTER; |
| 75 | } | |
| 76 | 4521 | else if (type.equals("//")) { |
| 77 | // open comment blocks are not set commented, they're set free | |
| 78 | 107 | copyCursor.current().setState(FREE); |
| 79 | 107 | copyCursor.next(); |
| 80 | 107 | return INSIDE_LINE_COMMENT; |
| 81 | } | |
| 82 | 4414 | else if (type.equals("/*")) { |
| 83 | // open comment blocks are not set commented, they're set free | |
| 84 | 10 | copyCursor.current().setState(FREE); |
| 85 | 10 | copyCursor.next(); |
| 86 | 10 | return INSIDE_BLOCK_COMMENT; |
| 87 | } | |
| 88 | 4404 | else if (type.equals("\'")) { |
| 89 | // make sure this is a OPEN single quote | |
| 90 | 64 | if (copyCursor.current().isClosed()) { |
| 91 | 4 | copyCursor.current().flip(); |
| 92 | } | |
| 93 | 64 | copyCursor.current().setState(FREE); |
| 94 | 64 | copyCursor.next(); |
| 95 | 64 | return INSIDE_SINGLE_QUOTE; |
| 96 | } | |
| 97 | 4340 | else if (type.equals("\"")) { |
| 98 | // make sure this is a OPEN quote | |
| 99 | 183 | if (copyCursor.current().isClosed()) { |
| 100 | 6 | copyCursor.current().flip(); |
| 101 | } | |
| 102 | 183 | copyCursor.current().setState(FREE); |
| 103 | 183 | copyCursor.next(); |
| 104 | 183 | return INSIDE_DOUBLE_QUOTE; |
| 105 | } | |
| 106 | else { | |
| 107 | 4157 | copyCursor.current().setState(FREE); |
| 108 | 4157 | copyCursor.next(); |
| 109 | 4157 | return FREE; |
| 110 | } | |
| 111 | } | |
| 112 | } |
|
||||||||||