CrReservedNameJava.java

  1. /* $Id$
  2.  *****************************************************************************
  3.  * Copyright (c) 2009 Contributors - see below
  4.  * All rights reserved. This program and the accompanying materials
  5.  * are made available under the terms of the Eclipse Public License v1.0
  6.  * which accompanies this distribution, and is available at
  7.  * http://www.eclipse.org/legal/epl-v10.html
  8.  *
  9.  * Contributors:
  10.  *    thn
  11.  *****************************************************************************
  12.  *
  13.  * Some portions of this file was previously release using the BSD License:
  14.  */

  15. // Copyright (c) 1996-2008 The Regents of the University of California. All
  16. // Rights Reserved. Permission to use, copy, modify, and distribute this
  17. // software and its documentation without fee, and without a written
  18. // agreement is hereby granted, provided that the above copyright notice
  19. // and this paragraph appear in all copies.  This software program and
  20. // documentation are copyrighted by The Regents of the University of
  21. // California. The software program and documentation are supplied "AS
  22. // IS", without any accompanying services from The Regents. The Regents
  23. // does not warrant that the operation of the program will be
  24. // uninterrupted or error-free. The end-user understands that the program
  25. // was developed for research purposes and is advised not to rely
  26. // exclusively on the program for any reason.  IN NO EVENT SHALL THE
  27. // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
  28. // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
  29. // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  30. // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
  31. // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
  32. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  33. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
  34. // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
  35. // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
  36. // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

  37. package org.argouml.language.java.cognitive.critics;

  38. import java.util.ArrayList;
  39. import java.util.List;

  40. import org.argouml.uml.cognitive.critics.CrReservedName;

  41. /**
  42.  * Critic to check whether the name of a ModelElement in the Model resembles or
  43.  * matches a Java keyword.
  44.  *
  45.  * @author Tom Morris
  46.  */
  47. public class CrReservedNameJava extends CrReservedName {

  48.     /**
  49.      * Constructor.
  50.      */
  51.     public CrReservedNameJava() {
  52.         super(getJavaNames());
  53.     }

  54.     /**
  55.      * Return a list of Java keywords and reserved names.
  56.      * @return the list of names
  57.      */
  58.     private static List<String> getJavaNames() {

  59.         List<String> javaReserved = new ArrayList<String>();

  60.         // The following are in the same order they appear in java.g
  61.        
  62.         // package definition and imports start everything off
  63.         javaReserved.add("package");
  64.         javaReserved.add("import");

  65.         javaReserved.add("extends");
  66.         javaReserved.add("super");
  67.        
  68.         // primitive data types
  69.         javaReserved.add("void");
  70.         javaReserved.add("boolean");
  71.         javaReserved.add("byte");
  72.         javaReserved.add("char");
  73.         javaReserved.add("short");
  74.         javaReserved.add("int");
  75.         javaReserved.add("float");
  76.         javaReserved.add("long");
  77.         javaReserved.add("double");
  78.        
  79.         javaReserved.add("interface");
  80.        
  81.         // modifiers
  82.         javaReserved.add("private");
  83.         javaReserved.add("public");
  84.         javaReserved.add("protected");
  85.         javaReserved.add("static");
  86.         javaReserved.add("transient");
  87.         javaReserved.add("final");
  88.         javaReserved.add("abstract");
  89.         javaReserved.add("native");
  90.         javaReserved.add("threadsafe");        
  91.         javaReserved.add("synchronized");
  92.         javaReserved.add("const");
  93.         javaReserved.add("volatile");
  94.         javaReserved.add("strictfp");

  95.         javaReserved.add("class");
  96.         javaReserved.add("extends");
  97.         javaReserved.add("implements");        
  98.        
  99.         javaReserved.add("enum");
  100.        
  101.         javaReserved.add("this");
  102.         // super already handled
  103.        
  104.         javaReserved.add("new");
  105.         javaReserved.add("throws");

  106.         javaReserved.add("if");
  107.         javaReserved.add("else");
  108.         javaReserved.add("for");
  109.         javaReserved.add("while");
  110.         javaReserved.add("do");
  111.         javaReserved.add("break");
  112.         javaReserved.add("continue");
  113.         javaReserved.add("return");
  114.         javaReserved.add("switch");
  115.         javaReserved.add("case");
  116.         javaReserved.add("default");

  117.         javaReserved.add("try");
  118.         javaReserved.add("catch");
  119.         javaReserved.add("finally");
  120.         javaReserved.add("throw");
  121.        
  122.         javaReserved.add("assert");

  123.         javaReserved.add("instanceof");

  124.         javaReserved.add("true");
  125.         javaReserved.add("false");
  126.         javaReserved.add("null");

  127.         // new already handled

  128.         ////////////// end of Java grammar keywords //////////////////
  129.        
  130.         // Some common java.* classes that we've historically checked for
  131.         // TODO: We should probably check for all or none
  132.         javaReserved.add("String");
  133.         javaReserved.add("Vector");
  134.         javaReserved.add("Hashtable");
  135.         javaReserved.add("Properties");        

  136.         // The rest of these aren't reserved Java words, but they were
  137.         // historically things that were checked for.  Disabled for now to
  138.         // minimize false alarms - tfm 20080506
  139. //        javaReserved.add("java");
  140. //        javaReserved.add("until");
  141. //        javaReserved.add("var");        
  142. //        javaReserved.add("rest");
  143. //        javaReserved.add("operator");
  144. //        javaReserved.add("inner");
  145. //        javaReserved.add("outer");
  146. //        javaReserved.add("byvalue");
  147. //        javaReserved.add("cast");
  148. //        javaReserved.add("future");
  149. //        javaReserved.add("generic");
  150. //        javaReserved.add("goto");

  151.         return javaReserved;
  152.     }

  153. }