Esempio n. 1
0
 /**
  * Constructs a PropertyDescriptor for a property that follows the standard Java convention by
  * having getFoo and setFoo accessor methods. Thus if the argument name is "fred", it will assume
  * that the writer method is "setFred" and the reader method is "getFred" (or "isFred" for a
  * boolean property). Note that the property name should start with a lower case character, which
  * will be capitalized in the method names.
  *
  * @param propertyName The programmatic name of the property.
  * @param beanClass The Class object for the target bean. For example sun.beans.OurButton.class.
  * @exception IntrospectionException if an exception occurs during introspection.
  */
 public PropertyDescriptor(String propertyName, Class<?> beanClass) throws IntrospectionException {
   this(
       propertyName,
       beanClass,
       Introspector.IS_PREFIX + NameGenerator.capitalize(propertyName),
       Introspector.SET_PREFIX + NameGenerator.capitalize(propertyName));
 }
 @Override
 public String get() {
   return nameGenerator.generateNextName();
 }
 RenameLabels(final AbstractCompiler compiler, final NameGenerator nameGen) {
   this(compiler, new DefaultNameSupplier(nameGen), true);
   nameGen.restartNaming();
 }
Esempio n. 4
0
  public static void main(String[] args) {

    NameGenerator nameGenerator = new NameGenerator(NameGenerator.ENGLISH);
    String name = nameGenerator.nextName();
    System.out.println(name);
  }
 public void testBias() {
   nameGenerator = new NameGenerator(new HashSet<String>(0), "", null);
   nameGenerator.favors("AAAAAAAAHH");
   test("var x, y", "var A, H");
 }
Esempio n. 6
0
  /** Determines which new names to substitute for the original names. */
  private void assignNames(Set<Assignment> varsToRename) {
    NameGenerator globalNameGenerator =
        new NameGenerator(reservedNames, prefix, reservedCharacters);

    // Local variables never need a prefix.
    NameGenerator localNameGenerator =
        prefix.isEmpty()
            ? globalNameGenerator
            : new NameGenerator(reservedNames, "", reservedCharacters);

    // Generated names and the assignments for non-local vars.
    List<Assignment> pendingAssignments = new ArrayList<Assignment>();
    List<String> generatedNamesForAssignments = new ArrayList<String>();

    for (Assignment a : varsToRename) {
      if (a.newName != null) {
        continue;
      }

      if (externNames.contains(a.oldName)) {
        continue;
      }

      String newName;
      if (a.oldName.startsWith(LOCAL_VAR_PREFIX)) {
        // For local variable, we make the assignment right away.
        newName = localNameGenerator.generateNextName();
        finalizeNameAssignment(a, newName);
      } else {
        // For non-local variable, delay finalizing the name assignment
        // until we know how many new names we'll have of length 2, 3, etc.
        newName = globalNameGenerator.generateNextName();
        pendingAssignments.add(a);
        generatedNamesForAssignments.add(newName);
      }
      reservedNames.add(newName);
    }

    // Now that we have a list of generated names, and a list of variable
    // Assignment objects, we assign the generated names to the vars as
    // follows:
    // 1) The most frequent vars get the shorter names.
    // 2) If N number of vars are going to be assigned names of the same
    //    length, we assign the N names based on the order at which the vars
    //    first appear in the source. This makes the output somewhat less
    //    random, because symbols declared close together are assigned names
    //    that are quite similar. With this heuristic, the output is more
    //    compressible.
    //    For instance, the output may look like:
    //    var da = "..", ea = "..";
    //    function fa() { .. } function ga() { .. }

    int numPendingAssignments = generatedNamesForAssignments.size();
    for (int i = 0; i < numPendingAssignments; ) {
      SortedSet<Assignment> varsByOrderOfOccurrence =
          new TreeSet<Assignment>(ORDER_OF_OCCURRENCE_COMPARATOR);

      // Add k number of Assignment to the set, where k is the number of
      // generated names of the same length.
      int len = generatedNamesForAssignments.get(i).length();
      for (int j = i;
          j < numPendingAssignments && generatedNamesForAssignments.get(j).length() == len;
          j++) {
        varsByOrderOfOccurrence.add(pendingAssignments.get(j));
      }

      // Now, make the assignments
      for (Assignment a : varsByOrderOfOccurrence) {
        finalizeNameAssignment(a, generatedNamesForAssignments.get(i));
        ++i;
      }
    }
  }
Esempio n. 7
0
 // Calculate once since capitalize() is expensive.
 String getBaseName() {
   if (baseName == null) {
     baseName = NameGenerator.capitalize(getName());
   }
   return baseName;
 }