コード例 #1
0
 @Override
 public void visit(SynchronizedStmt n, Object arg) {
   printer.print("synchronized (");
   n.getExpr().accept(this, arg);
   printer.print(") ");
   n.getBlock().accept(this, arg);
 }
コード例 #2
0
 @Override
 public void visit(VariableDeclaratorId n, Object arg) {
   printer.print(n.getName());
   for (int i = 0; i < n.getArrayCount(); i++) {
     printer.print("[]");
   }
 }
コード例 #3
0
 @Override
 public void visit(CatchClause n, Object arg) {
   printer.print(" catch (");
   n.getExcept().accept(this, arg);
   printer.print(") ");
   n.getCatchBlock().accept(this, arg);
 }
コード例 #4
0
  protected void generateSetObjectKeyMethod(SourcePrinter srcWriter) {
    srcWriter.println(
        "protected void setObjectKey("
            + getTargetObjectClassName()
            + " object, "
            + getKeyTypeName()
            + " key){");

    if (hasCompositeKey()) {
      for (int i = 0; i < keyPath.length; i++) {
        String k = keyPath[i];
        JType jType = JClassUtils.getTypeForProperty(k, targetObjectType);
        String setterMethod = JClassUtils.getSetterMethod(k, targetObjectType, jType);
        srcWriter.println(
            "object."
                + setterMethod
                + "((key==null?null:("
                + jType.getParameterizedQualifiedSourceName()
                + ")key["
                + i
                + "]));");
      }
    } else {
      String k = keyPath[0];
      JType jType = JClassUtils.getTypeForProperty(k, targetObjectType);
      String setterMethod = JClassUtils.getSetterMethod(k, targetObjectType, jType);
      srcWriter.println("object." + setterMethod + "(key);");
    }
    srcWriter.println("}");
    srcWriter.println();
  }
コード例 #5
0
 protected void generateOpenCursorMethod(SourcePrinter srcWriter) {
   srcWriter.println(
       "public void openCursor(KeyRange<"
           + getKeyTypeName()
           + "> keyRange, CursorDirection direction, final DatabaseCursorCallback<"
           + getKeyTypeName()
           + ", "
           + getTargetObjectClassName()
           + "> callback){");
   String cursorClassName =
       new SQLCursorProxyCreator(
               context,
               targetObjectType,
               objectStoreName,
               autoIncrement,
               getIndexColumns(),
               keyPath,
               keyPath,
               "ObjectStore_" + getTargetObjectClassName())
           .create();
   srcWriter.println(
       "new "
           + cursorClassName
           + "("
           + dbVariable
           + ", (WSQLKeyRange<"
           + getKeyTypeName()
           + ">)keyRange, direction, transaction).start(callback);");
   srcWriter.println("}");
   srcWriter.println();
 }
コード例 #6
0
 @Override
 public void visit(ArrayAccessExpr n, Object arg) {
   n.getName().accept(this, arg);
   printer.print("[");
   n.getIndex().accept(this, arg);
   printer.print("]");
 }
コード例 #7
0
 /**
  * Print out declarations from a stub file.
  *
  * @param members list of declarations
  * @param arg argument provided to the calling visitor method
  */
 private void printMembers(List<BodyDeclaration> members, Object arg) {
   for (BodyDeclaration member : members) {
     printer.printLn();
     member.accept(this, arg);
     printer.printLn();
   }
 }
コード例 #8
0
 @Override
 protected void generateProxyFields(SourcePrinter srcWriter) throws CruxGeneratorException {
   srcWriter.println(
       "private "
           + controllerClass.getQualifiedSourceName()
           + ControllerProxyCreator.CONTROLLER_PROXY_SUFFIX
           + " _controller;");
   srcWriter.println(
       "private "
           + DeviceAdaptiveViewContainer.class.getCanonicalName()
           + " viewContainer = new "
           + DeviceAdaptiveViewContainer.class.getCanonicalName()
           + "();");
   for (String messageClass : viewFactoryCreator.getDeclaredMessages().keySet()) {
     srcWriter.println(
         "private "
             + messageClass
             + " "
             + viewFactoryCreator.getDeclaredMessages().get(messageClass)
             + " = GWT.create("
             + messageClass
             + ".class);");
   }
   srcWriter.println(
       "private static "
           + Logger.class.getCanonicalName()
           + " "
           + viewFactoryCreator.getLoggerVariable()
           + " = "
           + Logger.class.getCanonicalName()
           + ".getLogger("
           + getProxySimpleName()
           + ".class.getName());");
   srcWriter.println("private static int _idGen = 0;");
 }
コード例 #9
0
 @Override
 public void visit(WhileStmt n, Object arg) {
   printer.print("while (");
   n.getCondition().accept(this, arg);
   printer.print(") ");
   n.getBody().accept(this, arg);
 }
コード例 #10
0
 @Override
 public void visit(CastExpr n, Object arg) {
   printer.print("(");
   n.getType().accept(this, arg);
   printer.print(") ");
   n.getExpr().accept(this, arg);
 }
コード例 #11
0
 @Override
 public void visit(ConditionalExpr n, Object arg) {
   n.getCondition().accept(this, arg);
   printer.print(" ? ");
   n.getThenExpr().accept(this, arg);
   printer.print(" : ");
   n.getElseExpr().accept(this, arg);
 }
コード例 #12
0
 @Override
 public void visit(SuperExpr n, Object arg) {
   if (n.getClassExpr() != null) {
     n.getClassExpr().accept(this, arg);
     printer.print(".");
   }
   printer.print("super");
 }
コード例 #13
0
 @Override
 public void visit(PackageDeclaration n, Object arg) {
   printMemberAnnotations(n.getAnnotations(), arg);
   printer.print("package ");
   n.getName().accept(this, arg);
   printer.printLn(";");
   printer.printLn();
 }
コード例 #14
0
 @Override
 public void visit(SingleMemberAnnotationExpr n, Object arg) {
   printer.print("@");
   n.getName().accept(this, arg);
   printer.print("(");
   n.getMemberValue().accept(this, arg);
   printer.print(")");
 }
コード例 #15
0
 @Override
 public void visit(BreakStmt n, Object arg) {
   printer.print("break");
   if (n.getId() != null) {
     printer.print(" ");
     printer.print(n.getId());
   }
   printer.print(";");
 }
コード例 #16
0
 @Override
 public void visit(ForeachStmt n, Object arg) {
   printer.print("for (");
   n.getVariable().accept(this, arg);
   printer.print(" : ");
   n.getIterable().accept(this, arg);
   printer.print(") ");
   n.getBody().accept(this, arg);
 }
コード例 #17
0
 @Override
 public void visit(ContinueStmt n, Object arg) {
   printer.print("continue");
   if (n.getId() != null) {
     printer.print(" ");
     printer.print(n.getId());
   }
   printer.print(";");
 }
コード例 #18
0
 @Override
 public void visit(ReturnStmt n, Object arg) {
   printer.print("return");
   if (n.getExpr() != null) {
     printer.print(" ");
     n.getExpr().accept(this, arg);
   }
   printer.print(";");
 }
コード例 #19
0
 @Override
 public void visit(ClassOrInterfaceType n, Object arg) {
   printAnnotations(n.getAnnotations(), arg);
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
     printer.print(".");
   }
   printer.print(n.getName());
   printTypeArgs(n.getTypeArgs(), arg);
 }
コード例 #20
0
 @Override
 public void visit(MethodCallExpr n, Object arg) {
   if (n.getScope() != null) {
     n.getScope().accept(this, arg);
     printer.print(".");
   }
   printTypeArgs(n.getTypeArgs(), arg);
   printer.print(n.getName());
   printArguments(n.getArgs(), arg);
 }
コード例 #21
0
  @Override
  protected void generateProxyContructor(SourcePrinter srcWriter) throws CruxGeneratorException {
    srcWriter.println(
        "public "
            + getProxySimpleName()
            + "(WSQLAbstractDatabase db, String name, WSQLTransaction transaction){");
    srcWriter.println("super(db, name, transaction);");

    srcWriter.println("}");
  }
コード例 #22
0
 @Override
 public void visit(AssertStmt n, Object arg) {
   printer.print("assert ");
   n.getCheck().accept(this, arg);
   if (n.getMessage() != null) {
     printer.print(" : ");
     n.getMessage().accept(this, arg);
   }
   printer.print(";");
 }
コード例 #23
0
  protected void generateObjectStoresCreation(SourcePrinter srcWriter, String callback) {
    srcWriter.println("deleteDBTables(tx, new DatabaseCallback(){");
    srcWriter.println("public void onSuccess(){");

    ObjectStoreDef[] objectStores = databaseMetadata.objectStores();
    Set<String> addedObjectStores = new HashSet<String>();

    String objectStoreVar = "objectStore";
    String indexNamesVar = "indexNames";
    srcWriter.println("WSQLAbstractObjectStore " + objectStoreVar + ";");
    srcWriter.println("Array<String> " + indexNamesVar + ";");
    for (ObjectStoreDef objectStoreMetadata : objectStores) {
      JClassType objectStoreTarget = getObjectStoreTarget(objectStoreMetadata);
      String objectStoreName = getObjectStoreName(objectStoreMetadata, objectStoreTarget);
      if (addedObjectStores.contains(objectStoreName)) {
        throw new CruxGeneratorException(
            "Duplicated objectstore declared on Datasource [" + databaseMetadata.name() + "]");
      }
      addedObjectStores.add(objectStoreName);

      srcWriter.println(
          objectStoreVar + " = getObjectStore(" + EscapeUtils.quote(objectStoreName) + ", null);");

      srcWriter.println(objectStoreVar + ".createTable(tx, null);");
    }

    srcWriter.println("createFileStore(tx);");

    srcWriter.println("}");
    srcWriter.println("}, getDeleteErrorHandler(callback), false);");
  }
コード例 #24
0
  protected void generateUpdateDatabaseStructureMethod(SourcePrinter srcWriter) {
    srcWriter.println(
        "protected void updateDatabaseStructure(final "
            + SQLTransaction.class.getCanonicalName()
            + " tx, final DatabaseCallback callback){");

    generateObjectStoresCreation(srcWriter, "callback");

    srcWriter.println("}");
    srcWriter.println();
  }
コード例 #25
0
 @Override
 public void visit(IfStmt n, Object arg) {
   printer.print("if (");
   n.getCondition().accept(this, arg);
   printer.print(") ");
   n.getThenStmt().accept(this, arg);
   if (n.getElseStmt() != null) {
     printer.print(" else ");
     n.getElseStmt().accept(this, arg);
   }
 }
コード例 #26
0
  @Override
  public void visit(Parameter n, Object arg) {
    printAnnotations(n.getAnnotations(), arg);
    printModifiers(n.getModifiers());

    n.getType().accept(this, arg);
    if (n.isVarArgs()) {
      printer.print("...");
    }
    printer.print(" ");
    n.getId().accept(this, arg);
  }
コード例 #27
0
 @Override
 public void visit(ImportDeclaration n, Object arg) {
   printer.print("import ");
   if (n.isStatic()) {
     printer.print("static ");
   }
   n.getName().accept(this, arg);
   if (n.isAsterisk()) {
     printer.print(".*");
   }
   printer.printLn(";");
 }
コード例 #28
0
 /**
  * Print a list of method arguments in between parentheses.
  *
  * @param args method arguments
  * @param arg argument provided to the calling visitor method
  */
 private void printArguments(List<Expression> args, Object arg) {
   printer.print("(");
   if (args != null) {
     for (Iterator<Expression> i = args.iterator(); i.hasNext(); ) {
       Expression e = i.next();
       e.accept(this, arg);
       if (i.hasNext()) {
         printer.print(", ");
       }
     }
   }
   printer.print(")");
 }
コード例 #29
0
  @Override
  public void visit(ReferenceType n, Object arg) {
    printAnnotations(n.getAnnotations(), arg);

    n.getType().accept(this, arg);
    for (int i = 0; i < n.getArrayCount(); i++) {
      if (!n.getAnnotationsAtLevel(i).isEmpty()) {
        printer.print(" ");
        printAnnotations(n.getAnnotationsAtLevel(i), arg);
      }
      printer.print("[]");
    }
  }
コード例 #30
0
 @Override
 public void visit(WildcardType n, Object arg) {
   printAnnotations(n.getAnnotations(), arg);
   printer.print("?");
   if (n.getExtends() != null) {
     printer.print(" extends ");
     n.getExtends().accept(this, arg);
   }
   if (n.getSuper() != null) {
     printer.print(" super ");
     n.getSuper().accept(this, arg);
   }
 }