Пример #1
0
  private boolean addClassMemberStaticImports(String packageName) {
    try {
      Class c = Class.forName(packageName);
      initImports();
      if (c.isEnum()) {

        //noinspection unchecked
        for (Enum e : (EnumSet<?>) EnumSet.allOf(c)) {
          imports.put(e.name(), e);
        }
        return true;
      } else {
        for (Field f : c.getDeclaredFields()) {
          if ((f.getModifiers() & (Modifier.STATIC | Modifier.PUBLIC)) != 0) {
            imports.put(f.getName(), f.get(null));
          }
        }
      }
    } catch (ClassNotFoundException e) {
      // do nothing.
    } catch (IllegalAccessException e) {
      throw new RuntimeException("error adding static imports for: " + packageName, e);
    }
    return false;
  }
Пример #2
0
  public void addAllImports(Map<String, Object> imports) {
    if (imports == null) return;

    initImports();

    Object o;

    for (Map.Entry<String, Object> entry : imports.entrySet()) {
      if ((o = entry.getValue()) instanceof Method) {
        this.imports.put(entry.getKey(), new MethodStub((Method) o));
      } else {
        this.imports.put(entry.getKey(), o);
      }
    }
  }
Пример #3
0
 public void setAllImports(Map<String, Object> imports) {
   initImports();
   this.imports.clear();
   if (imports != null) this.imports.putAll(imports);
 }
Пример #4
0
 public void addImport(String name, MethodStub method) {
   initImports();
   this.imports.put(name, method);
 }
Пример #5
0
 public void addImport(String name, Proto proto) {
   initImports();
   this.imports.put(name, proto);
 }
Пример #6
0
 public void addImport(String name, Class cls) {
   initImports();
   this.imports.put(name, cls);
 }
Пример #7
0
 public void addImport(Class cls) {
   initImports();
   addImport(cls.getSimpleName(), cls);
 }