コード例 #1
0
  /**
   * Adds the given parameter to this JConstructor's list of parameters.
   *
   * @param parameter The parameter to add to the this JConstructor's list of parameters.
   */
  public void addParameter(final JParameter parameter) {
    if (parameter == null) {
      return;
    }

    // -- check current params
    if (_params.get(parameter.getName()) != null) {
      StringBuilder err = new StringBuilder(64);
      err.append("A parameter already exists for the constructor, ");
      err.append(this._declaringClass.getName());
      err.append(", with the name: ");
      err.append(parameter.getName());
      throw new IllegalArgumentException(err.toString());
    }

    _params.put(parameter.getName(), parameter);

    // -- be considerate and add the class name to the
    // -- declaring class's list of imports
    if (_declaringClass != null) {
      JType jType = parameter.getType();
      if (!jType.isPrimitive()) {
        _declaringClass.addImport(jType.getName());
      }
    }
  }
コード例 #2
0
ファイル: JProgram.java プロジェクト: imatellan/gwt
 public Collection<JType> getSubclasses(JType type) {
   return Collections2.transform(
       typeOracle.getSubTypeNames(type.getName()),
       new Function<String, JType>() {
         @Override
         public JType apply(String typeName) {
           return getFromTypeMap(typeName);
         }
       });
 }
コード例 #3
0
ファイル: JInterface.java プロジェクト: sonatype/modello
  /**
   * Adds the given JMethodSignature to this JClass
   *
   * @param jMethodSig the JMethodSignature to add.
   * @throws java.lang.IllegalArgumentException when the given JMethodSignature conflicts with an
   *     existing method signature.
   */
  public void addMethod(JMethodSignature jMethodSig) throws IllegalArgumentException {
    if (jMethodSig == null) {
      String err = "The JMethodSignature cannot be null.";
      throw new IllegalArgumentException(err);
    }

    // -- check method name and signatures *add later*

    // -- keep method list sorted for esthetics when printing
    // -- START SORT :-)
    boolean added = false;
    //        short modifierVal = 0;
    JModifiers modifiers = jMethodSig.getModifiers();
    for (int i = 0; i < methods.size(); i++) {
      JMethodSignature tmp = (JMethodSignature) methods.elementAt(i);
      // -- first compare modifiers
      if (tmp.getModifiers().isProtected()) {
        if (!modifiers.isProtected()) {
          methods.insertElementAt(jMethodSig, i);
          added = true;
          break;
        }
      }
      // -- compare names
      if (jMethodSig.getName().compareTo(tmp.getName()) < 0) {
        methods.insertElementAt(jMethodSig, i);
        added = true;
        break;
      }
    }
    // -- END SORT
    if (!added) methods.addElement(jMethodSig);

    // -- check return type to make sure it's included in the
    // -- import list
    JType jType = jMethodSig.getReturnType();
    if (jType != null) {
      while (jType.isArray()) jType = jType.getComponentType();

      if (!jType.isPrimitive()) addImport(jType.getName());
    }
    // -- check exceptions
    JClass[] exceptions = jMethodSig.getExceptions();
    for (JClass exception : exceptions) {
      addImport(exception.getName());
    }
  } // -- addMethod
コード例 #4
0
ファイル: JArrayType.java プロジェクト: damocles33/gwt
 public JArrayType(JType elementType) {
   super(
       elementType.getSourceInfo().makeChild(SourceOrigin.UNKNOWN), elementType.getName() + "[]");
   assert !(elementType instanceof JNonNullType);
   this.elementType = elementType;
 }