001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * File : VBAttributeStateHandler.java
044: * Created on : Dec 12, 2003
045: * Author : Aztec
046: */
047: package org.netbeans.modules.uml.core.reverseengineering.parsingfacilities.translation.statehandlers;
048:
049: import org.dom4j.Node;
050:
051: import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ITokenDescriptor;
052: import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
053: import org.netbeans.modules.uml.core.support.umlutils.ETList;
054:
055: /**
056: * @author Aztec
057: */
058: public class VBAttributeStateHandler extends AttributeStateHandler {
059:
060: public VBAttributeStateHandler(String language) {
061: super (language);
062: }
063:
064: public StateHandler createSubStateHandler(String stateName,
065: String language) {
066: StateHandler retVal = null;
067:
068: if ("Object Creation".equals(stateName)) {
069: retVal = this ;
070: setTypeState(true);
071: }
072:
073: if (retVal == null) {
074: retVal = super .createSubStateHandler(stateName, language);
075: } else {
076: if (retVal != null && retVal != this ) {
077: Node pNode = getDOMNode();
078:
079: if (pNode != null) {
080: retVal.setDOMNode(pNode);
081: }
082: }
083: }
084: return retVal;
085: }
086:
087: public void initialize() {
088: super .initialize();
089: setNodeAttribute("type", "Variant");
090: }
091:
092: public void processToken(ITokenDescriptor pToken, String language) {
093: if (pToken == null)
094: return;
095:
096: super .processToken(pToken, language);
097:
098: String tokenType = pToken.getType();
099: if ("Modifier".equals(tokenType)) {
100: String value = pToken.getValue();
101: if (value != null) {
102: if (isModifierSame("WithEvents", language, value)) {
103: setNodeAttribute("isWithEvents", "true");
104: }
105: }
106: }
107: }
108:
109: public void stateComplete(String stateName) {
110: if ("Object Creation".equals(stateName)) {
111: setTypeState(false);
112: } else {
113: super .stateComplete(stateName);
114: }
115: }
116:
117: public String cleanseComment(String origComment) {
118: String retVal = "";
119:
120: ETList<String> lines = StringUtilities.splitOnDelimiter(
121: origComment, "\n");
122: int count = 0;
123: if (lines != null && (count = lines.size()) > 0) {
124: for (int i = 0; i < count; ++i) {
125: String curLine = lines.get(i);
126: String test = curLine.substring(0, 3);
127: if ("rem".equalsIgnoreCase(test)) {
128: retVal += curLine.substring(3);
129: } else if ("'".equals(curLine.substring(1))) {
130: // The only other comment style is to start the line with a '
131: retVal += curLine.substring(1);
132: } else {
133: // The only other comment style is to start the line with a '
134: retVal += curLine;
135: }
136: }
137: }
138: return retVal;
139: }
140:
141: protected void handleName(ITokenDescriptor pToken) {
142: if (pToken == null)
143: return;
144:
145: super .handleName(pToken);
146:
147: String value = pToken.getValue();
148:
149: updateByTypeSpecifier(value);
150:
151: }
152:
153: protected void updateByTypeSpecifier(String typeName) {
154: if (typeName != null) {
155: String value = null;
156: String lastChar = typeName.substring(typeName.length() - 1);
157: if ("%".equals(lastChar)) {
158: value = "Integer";
159: } else if ("!".equals(lastChar)) {
160: value = "Single";
161: } else if ("$".equals(lastChar)) {
162: value = "String";
163: } else if ("@".equals(lastChar)) {
164: value = "Decimal";
165: } else if ("#".equals(lastChar)) {
166: value = "Double";
167: } else if ("&".equals(lastChar)) {
168: value = "Long";
169: }
170:
171: if (value != null) {
172: setNodeAttribute("type", value);
173: }
174: }
175: }
176:
177: }
|