1 28 package org.jruby.util; 29 30 public final class IdUtil { 31 public static final int CONSTANT = 0; 32 public static final int INSTANCE_VAR = 1; 33 public static final int CLASS_VAR = 2; 34 public static final int GLOBAL_VAR = 4; 35 public static final int LOCAL_VAR = 8; 36 37 45 public static int getVarType(String id) { 46 char c = id.charAt(0); 47 48 switch (c) { 49 case '@': 50 return id.charAt(1) == '@' ? CLASS_VAR : INSTANCE_VAR; 51 case '$': 52 return GLOBAL_VAR; 53 } 54 55 return Character.isUpperCase(c) ? CONSTANT : LOCAL_VAR; 56 } 57 58 61 public static boolean isConstant(String id) { 62 return Character.isUpperCase(id.charAt(0)); 63 } 64 65 68 public static boolean isClassVariable(String id) { 69 return id.length()>1 && id.charAt(0) == '@' && id.charAt(1) == '@'; 70 } 71 72 75 public static boolean isInstanceVariable(String id) { 76 return id.length()>0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@'); 77 } 78 79 82 public static boolean isGlobal(String id) { 83 return id.length()>0 && id.charAt(0) == '$'; 84 } 85 86 89 public static boolean isLocal(String id) { 90 return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id); 91 } 92 93 public static boolean isAttrSet(String id) { 94 return id.endsWith("="); 95 } 96 } 97 | Popular Tags |