PageRenderTime 25ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetCommand.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 303 lines | 192 code | 59 blank | 52 comment | 8 complexity | 12a28400c5d6e9c38bdb768047fab903 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.php.dbgp.packets;
  45. import org.netbeans.modules.php.dbgp.breakpoints.AbstractBreakpoint;
  46. /**
  47. * @author ads
  48. *
  49. */
  50. public class BrkpntSetCommand extends DbgpCommand {
  51. public enum Types {
  52. LINE, // at the time of writing ( protocol version 2.0.0 ) this command is supported
  53. CALL, // at the time of writing ( protocol version 2.0.0 ) this command is supported
  54. RETURN, // at the time of writing ( protocol version 2.0.0 ) this command is supported
  55. EXCEPTION, // at the time of writing ( protocol version 2.0.0 ) this command is NOT supported
  56. CONDITIONAL, // at the time of writing ( protocol version 2.0.0 ) this command is NOT supported
  57. WATCH; // at the time of writing ( protocol version 2.0.0 ) this command is NOT supported
  58. @Override
  59. public String toString()
  60. {
  61. return super.toString().toLowerCase();
  62. }
  63. }
  64. public enum State {
  65. ENABLED,
  66. DISABLED;
  67. @Override
  68. public String toString()
  69. {
  70. return super.toString().toLowerCase();
  71. }
  72. public static State forString( String str ) {
  73. State[] states = State.values();
  74. for (State state : states) {
  75. if( state.toString().equals( str )) {
  76. return state;
  77. }
  78. }
  79. return null;
  80. }
  81. }
  82. public static final String BREAKPOINT_SET = "breakpoint_set"; // NOI18N
  83. private static final String TYPE_ARG = "-t "; // NOI18N
  84. private static final String FILE_ARG = "-f "; // NOI18N
  85. private static final String LINE_ARG = "-n "; // NOI18N
  86. private static final String STATE_ARG = "-s "; // NOI18N
  87. private static final String TEMP_ARG = "-r "; // NOI18N
  88. private static final String FUNC_ARG = "-m "; // NOI18N
  89. private static final String EXCEPTION_ARG = "-x"; // NOI18N
  90. BrkpntSetCommand( String transactionId ) {
  91. this( BREAKPOINT_SET , transactionId );
  92. }
  93. BrkpntSetCommand( String cmndName , String transactionId ) {
  94. super( cmndName, transactionId);
  95. myState = State.ENABLED;
  96. myHitCount = -1;
  97. myHitValue = -1;
  98. myLineNumber = -1;
  99. }
  100. /* (non-Javadoc)
  101. * @see org.netbeans.modules.php.dbgp.packets.DbgpCommand#needAcknowledgment()
  102. */
  103. @Override
  104. public boolean wantAcknowledgment()
  105. {
  106. return true;
  107. }
  108. public void setBreakpoint( AbstractBreakpoint breakpoint ) {
  109. myBrkpnt = breakpoint;
  110. }
  111. public AbstractBreakpoint getBreakpoint() {
  112. return myBrkpnt;
  113. }
  114. public void setType( Types type) {
  115. myType = type;
  116. }
  117. public void setFile( String file ) {
  118. myFile = file;
  119. }
  120. public void setFunction( String function ) {
  121. myFunction = function;
  122. }
  123. public void setException( String exception ) {
  124. myException = exception;
  125. }
  126. public void setState( State state ) {
  127. myState = state;
  128. }
  129. public void setLineNumber( int line ) {
  130. myLineNumber = line;
  131. }
  132. public void setExpression( String expression ) {
  133. myException = expression;
  134. }
  135. public void setTemporary( boolean isTemp ) {
  136. isTemporary = isTemp;
  137. }
  138. public void setHitCount( int count ) {
  139. myHitCount = count;
  140. }
  141. public void setHitValue( int value ) {
  142. myHitValue = value;
  143. }
  144. public void setHitCondition( String condition) {
  145. myHitCondition = condition;
  146. }
  147. @Override
  148. protected String getData(){
  149. return myExpression;
  150. }
  151. @Override
  152. protected String getArguments() {
  153. assert myType != null;
  154. StringBuilder builder = new StringBuilder();
  155. setType( builder );
  156. setState( builder );
  157. setTemporary( builder );
  158. switch ( myType ) {
  159. case LINE:
  160. setLineArguments( builder );
  161. break;
  162. case CALL:
  163. setCallArguments( builder );
  164. break;
  165. case RETURN:
  166. setReturnArguments( builder );
  167. break;
  168. case EXCEPTION:
  169. setExceptionArguments( builder );
  170. break;
  171. case CONDITIONAL:
  172. setConditionalArguments( builder );
  173. break;
  174. case WATCH:
  175. // this case need only expression that is returned by getData() automatically
  176. break;
  177. default :
  178. assert false;
  179. }
  180. return builder.toString();
  181. }
  182. private void setTemporary( StringBuilder builder ) {
  183. if ( isTemporary ) {
  184. builder.append( SPACE );
  185. builder.append( TEMP_ARG );
  186. builder.append( 1 );
  187. }
  188. }
  189. private void setState( StringBuilder builder ) {
  190. if ( myState != null ) {
  191. builder.append( SPACE );
  192. builder.append( STATE_ARG );
  193. builder.append( myState.toString() );
  194. }
  195. }
  196. private void setConditionalArguments( StringBuilder builder ) {
  197. builder.append( SPACE );
  198. builder.append( FILE_ARG );
  199. builder.append( myFile );
  200. if ( myLineNumber > -1 ) {
  201. builder.append( SPACE );
  202. builder.append( FILE_ARG );
  203. builder.append( myFile );
  204. }
  205. }
  206. private void setExceptionArguments( StringBuilder builder ) {
  207. builder.append( SPACE );
  208. builder.append( EXCEPTION_ARG );
  209. builder.append( myException );
  210. }
  211. private void setReturnArguments( StringBuilder builder ) {
  212. setCallArguments( builder );
  213. }
  214. private void setCallArguments( StringBuilder builder ) {
  215. builder.append( SPACE );
  216. builder.append( FUNC_ARG );
  217. builder.append( myFunction );
  218. }
  219. private void setLineArguments( StringBuilder builder ) {
  220. builder.append( SPACE );
  221. builder.append( FILE_ARG );
  222. builder.append( myFile );
  223. builder.append( SPACE );
  224. builder.append( LINE_ARG );
  225. // line number is 1-based.
  226. builder.append( ( myLineNumber +1 ) );
  227. }
  228. private void setType( StringBuilder builder ) {
  229. builder.append( TYPE_ARG );
  230. builder.append( myType.toString() );
  231. }
  232. private String myFunction;
  233. private Types myType;
  234. private String myFile;
  235. private String myException;
  236. private State myState;
  237. private int myLineNumber;
  238. private String myExpression;
  239. private boolean isTemporary;
  240. private int myHitCount ;
  241. private int myHitValue;
  242. private String myHitCondition;
  243. private AbstractBreakpoint myBrkpnt;
  244. }