001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.definitions.reducedmodel;
038:
039: /**
040: * Shadowing state that indicates normal, unshadowed text.
041: * @version $Id: Free.java 4255 2007-08-28 19:17:37Z mgricken $
042: */
043: public class Free extends ReducedModelState {
044: public static final Free ONLY = new Free();
045:
046: private Free() {
047: }
048:
049: /**
050: * Walk function for when we're not inside a string or comment.
051: * Self-recursive and mutually recursive with other walk functions.
052: * <ol>
053: * <li> atEnd: return
054: * <li> If we find / *, * /, or / /, combine them into a single Brace,
055: * and keep the cursor on that Brace.
056: * <li> If current brace = //, go to next then call updateLineComment.<BR>
057: * If current brace = /*, go to next then call updateBlockComment.<BR>
058: * If current brace = ", go to next then call updateInsideDoubleQuote.<BR>
059: * Else, mark current brace as FREE, go to the next brace, and recur.
060: * </ol>
061: */
062: ReducedModelState update(TokenList.Iterator copyCursor) {
063: if (copyCursor.atEnd())
064: return STUTTER;
065:
066: _combineCurrentAndNextIfFind("/", "*", copyCursor);
067: _combineCurrentAndNextIfFind("/", "/", copyCursor);
068: _combineCurrentAndNextIfFind("", "", copyCursor);
069: //if a / preceeds a /* or a // combine them.
070: _combineCurrentAndNextIfFind("/", "/*", copyCursor);
071: _combineCurrentAndNextIfFind("/", "//", copyCursor);
072: _combineCurrentAndNextIfEscape(copyCursor);
073:
074: String type = copyCursor.current().getType();
075: if (type.equals("*/")) {
076: copyCursor._splitCurrentIfCommentBlock(true, false);
077: copyCursor.prev();
078: return STUTTER;
079: } else if (type.equals("//")) {
080: // open comment blocks are not set commented, they're set free
081: copyCursor.current().setState(FREE);
082: copyCursor.next();
083: return INSIDE_LINE_COMMENT;
084: } else if (type.equals("/*")) {
085: // open comment blocks are not set commented, they're set free
086: copyCursor.current().setState(FREE);
087: copyCursor.next();
088: return INSIDE_BLOCK_COMMENT;
089: } else if (type.equals("\'")) {
090: // make sure this is a OPEN single quote
091: if (copyCursor.current().isClosed()) {
092: copyCursor.current().flip();
093: }
094: copyCursor.current().setState(FREE);
095: copyCursor.next();
096: return INSIDE_SINGLE_QUOTE;
097: } else if (type.equals("\"")) {
098: // make sure this is a OPEN quote
099: if (copyCursor.current().isClosed()) {
100: copyCursor.current().flip();
101: }
102: copyCursor.current().setState(FREE);
103: copyCursor.next();
104: return INSIDE_DOUBLE_QUOTE;
105: } else {
106: copyCursor.current().setState(FREE);
107: copyCursor.next();
108: return FREE;
109: }
110: }
111: }
|