@Override
  public void writeFieldReadStatement(
      VariableElement field,
      Collection<ExecutableElement> postCreateChildMethods,
      JavaWriter writer)
      throws IOException {
    DeclaredType type = (DeclaredType) field.asType();
    TypeMirror itemType = type.getTypeArguments().get(0);
    TypeMirror itemTypeErasure = processingEnv.getTypeUtils().erasure(itemType);

    String collectionInitializer;
    try {
      collectionInitializer = initializers.findCollectionInitializer(type);
    } catch (InvalidTypeException e) {
      processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), field);
      collectionInitializer = "null";
    }
    writer.beginControlFlow("if (bundle.containsKey(\"%s\"))", field.getSimpleName());
    writer.emitStatement("object.%s = %s", field.getSimpleName(), collectionInitializer);
    writer.emitStatement(
        "%1$s.readCollectionFromBundle(object.%2$s, bundle, %3$s.class, \"%2$s\")",
        CollectionBundler.class.getCanonicalName(), field.getSimpleName(), itemTypeErasure);

    writePostCreateChildMethodCalls(field, itemType, postCreateChildMethods, writer);
    writer.endControlFlow();
  }
 /**
  * INTERNAL: Visit a packing-info.java file. We currently don't support package level annotations,
  * but if we did and they impacted canonical model generation we would pick them up here. We
  * should never hit this visit since we filter out package elements, and package elements can not
  * be referenced from classes.
  */
 @Override
 public MetadataClass visitPackage(PackageElement packageElement, MetadataClass metadataClass) {
   processingEnv
       .getMessager()
       .printMessage(Kind.NOTE, "ElementVisitor Package NOT IMPLEMENTED : " + packageElement);
   return null;
 }
Пример #3
0
 /**
  * エラーログ。スタックのフルダンプ。
  *
  * @param t 発生した例外
  */
 protected void error(Throwable t) {
   Messager messager = environment.getMessager();
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   t.printStackTrace(pw);
   messager.printMessage(Kind.ERROR, sw.toString());
 }
Пример #4
0
 @Override
 public void init(ProcessingEnvironment processingEnv) {
   super.init(processingEnv);
   this.processingEnv = processingEnv;
   errorListener =
       new ErrorReceiverImpl(
           processingEnv.getMessager(),
           processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue()));
 }
Пример #5
0
  @Override
  public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    Elements elementUtils = processingEnv.getElementUtils();
    Types typeUtils = processingEnv.getTypeUtils();
    Filer filer = processingEnv.getFiler();
    Messager messager = processingEnv.getMessager();
  }
 @Override
 public synchronized void init(ProcessingEnvironment processingEnv) {
   super.init(processingEnv);
   elements = processingEnv.getElementUtils();
   types = processingEnv.getTypeUtils();
   messager = processingEnv.getMessager();
   factoryWriter = new FactoryWriter(processingEnv.getFiler());
   providedChecker = new ProvidedChecker(messager);
   declarationFactory = new AutoFactoryDeclaration.Factory(elements, messager);
   factoryDescriptorGenerator =
       new FactoryDescriptorGenerator(messager, elements, declarationFactory);
 }
  @Override
  public void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);

    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    eltUtils = processingEnv.getElementUtils();

    outputDir = processingEnv.getOptions().get("structoutputdir");
    outputDir = outputDir == null ? "gensrc" : outputDir;

    basedir = processingEnv.getOptions().get("basedir");
  }
Пример #8
0
 /** {@inheritDoc} */
 @Override
 public void init(ProcessingEnvironment procEnv) {
   super.init(procEnv);
   this.processingEnv = (JavacProcessingEnvironment) procEnv;
   placePostCompileAndDontMakeForceRoundDummiesHook();
   transformer = new JavacTransformer(procEnv.getMessager());
   trees = Trees.instance(procEnv);
   SortedSet<Long> p = transformer.getPriorities();
   if (p.isEmpty()) {
     this.priorityLevels = new long[] {0L};
     this.priorityLevelsRequiringResolutionReset = new HashSet<Long>();
   } else {
     this.priorityLevels = new long[p.size()];
     int i = 0;
     for (Long prio : p) this.priorityLevels[i++] = prio;
     this.priorityLevelsRequiringResolutionReset =
         transformer.getPrioritiesRequiringResolutionReset();
   }
 }
Пример #9
0
  /**
   * @param env the environment
   * @param annUtil utils
   * @param d the method
   */
  public MethodHandler(
      final ProcessingEnvironment env, final AnnUtil annUtil, final ExecutableElement d) {
    this.env = env;
    this.annUtil = annUtil;
    msg = env.getMessager();

    staticMethod = d.getModifiers().contains(Modifier.STATIC);
    methName = d.getSimpleName().toString();
    getter = methName.startsWith("get");
    setter = methName.startsWith("set");

    immutable = d.getAnnotation(Immutable.class) != null;

    CloneForOverride cfo = d.getAnnotation(CloneForOverride.class);
    cloneForOverride = cfo != null;
    if (cloneForOverride) {
      cloneCollectionType = cfo.cloneCollectionType();
      cloneElementType = cfo.cloneElementType();
    }

    returnType = d.getReturnType();
    returnsVoid = env.getTypeUtils().getNoType(TypeKind.VOID).equals(returnType);

    pars = d.getParameters();
    thrownTypes = d.getThrownTypes();

    if ((setter) && (pars != null) && (pars.size() == 1)) {
      fieldType = pars.iterator().next().asType();
      basicType = fieldType.getKind().isPrimitive();
    }

    if (getter) {
      fieldType = returnType;
      basicType = returnType.getKind().isPrimitive();
    }

    if (setter || getter) {
      ucFieldName = methName.substring(3);
      fieldName = ucFieldName.substring(0, 1).toLowerCase() + ucFieldName.substring(1);
    }
  }
Пример #10
0
 /**
  * Whether the specified element is assignable to the fqTn parameter
  *
  * @param processingEnvironment The environment this runs in
  * @param fqTn THe fully qualified type name of the element we want to check
  * @param element The element to check that implements
  * @return true if element implements the fqTn
  */
 public static boolean isSubclass(
     ProcessingEnvironment processingEnvironment, String fqTn, TypeElement element) {
   TypeElement typeElement = processingEnvironment.getElementUtils().getTypeElement(fqTn);
   if (typeElement == null) {
     processingEnvironment
         .getMessager()
         .printMessage(
             Diagnostic.Kind.ERROR,
             "Type Element was null for: "
                 + fqTn
                 + ""
                 + "ensure that the visibility of the class is not private.");
     return false;
   } else {
     TypeMirror classMirror = typeElement.asType();
     return classMirror != null
         && element != null
         && element.asType() != null
         && processingEnvironment.getTypeUtils().isSubtype(element.asType(), classMirror);
   }
 }
Пример #11
0
 public FieldElementModel(ProcessingEnvironment processingEnv) {
   this.processingEnv = processingEnv;
   messager = processingEnv.getMessager();
 }
Пример #12
0
 @Override
 public void printError(String message) {
   processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message);
 }
Пример #13
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {

    environment.getMessager().printMessage(Kind.NOTE, "MetaGen");

    logger.log("");
    logger.log("STARTED ROUND");
    logger.log("");

    BeanSpace beans = new BeanSpace();
    try {
      // TODO this should prob delegate to beanspace.add(element);
      // TODO beanspace should check if element is supported and error
      // otherwise
      for (TypeElement annotation : annotations) {
        logger.log("Processing annotation: %s", annotation.getQualifiedName());

        for (Element annotated : round.getElementsAnnotatedWith(annotation)) {
          TypeElement element = null;
          switch (annotated.getKind()) {
            case CLASS:
            case ENUM:
              element = (TypeElement) annotated;

              logger.log("Processing annotated class/enum: %s", element.getQualifiedName());

              if (accept(element)) {
                beans.add(element);
              }
              break;
            case FIELD:
            case METHOD:
              element = (TypeElement) annotated.getEnclosingElement();

              logger.log(
                  "Processing class/enum: %s derived from annotated element: %s",
                  element.getQualifiedName(), annotated.getSimpleName());

              if (accept(element)) {
                beans.add(element);
              }
              break;
            default:
              logger.log(
                  "Ignored element: %s of kind: %s",
                  annotated.getSimpleName(), annotated.getKind());
          }
        }
      }

      beans.accept(new PropertyResolvingVisitor(resolvers));
      // beans.accept(new PrintVisitor());
      beans.accept(new TrimmingVisitor());

      beans.accept(new ValidatingVisitor(environment));
      beans.accept(new SuperclassResolvingVisitor());

      beans.accept(new TrimmingVisitor());

      beans.accept(new CodeGeneratingVisitor(environment));

      logger.log("");
      logger.log("ROUND COMPLETED");
      logger.log("");

      // return false so we do not claim annotaitons like @Entity
      return false;
    } catch (RuntimeException e) {
      e.printStackTrace();
      logger.log("Error: %s", e.getMessage());
      environment.getMessager().printMessage(Kind.ERROR, e.getMessage());
      throw e;
    }
  }
 public static void note(Element element, String message, Object... args) {
   if (args.length > 0) {
     message = String.format(message, args);
   }
   processingEnvironment.getMessager().printMessage(Diagnostic.Kind.NOTE, message, element);
 }
Пример #15
0
 @Override
 public void printWarning(String message, MetadataInfo element) {
   processingEnv
       .getMessager()
       .printMessage(Diagnostic.Kind.WARNING, message, ((APMetadataInfo) element).getElement());
 }
Пример #16
0
 /**
  * Init processor<br>
  * get filer, messager<br>
  * get options
  */
 @Override
 public void init(ProcessingEnvironment processingEnv) {
   super.init(processingEnv);
   messager = processingEnv.getMessager();
   filer = processingEnv.getFiler();
 }
Пример #17
0
 @Override
 public void printError(String message, MetadataInfo element) {
   processingEnv
       .getMessager()
       .printMessage(Diagnostic.Kind.ERROR, message, ((APMetadataInfo) element).getElement());
 }
Пример #18
0
 @Override
 public void printWarning(String message) {
   processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, message);
 }
Пример #19
0
 /**
  * ただのログ。
  *
  * @param msg
  */
 protected void log(String msg) {
   Messager messager = environment.getMessager();
   messager.printMessage(Kind.OTHER, msg);
 }
Пример #20
0
 /** Prints the ProcessorContext configuration. */
 protected final void logConfiguration() {
   processingEnv.getMessager().printMessage(Kind.NOTE, toString());
 }
Пример #21
0
 private void log(final Kind kind, final String message) {
   if (debug) {
     processingEnv.getMessager().printMessage(kind, message);
   }
 }
Пример #22
0
 @Override
 public void init(ProcessingEnvironment env) {
   filer = env.getFiler();
   messager = env.getMessager();
   elements = env.getElementUtils();
 }
Пример #23
0
  /**
   * Creates a new tool logger.
   *
   * @param processingEnv the processing environment
   * @return a new tool logger
   */
  public static ToolLogger getLogger(final ProcessingEnvironment processingEnv) {
    String debug = processingEnv.getOptions().get(LoggingToolsProcessor.DEBUG_OPTION);
    boolean isDebugEnabled = Boolean.parseBoolean(debug);

    return new ToolLogger(processingEnv.getMessager(), isDebugEnabled);
  }
Пример #24
0
 @Override
 public void printNote(String message) {
   processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
 }
Пример #25
0
  @Override
  public StringBuffer generate(
      final String packageName,
      final PackageElement packageElement,
      final String className,
      final Element element,
      final ProcessingEnvironment processingEnvironment)
      throws GenerationException {

    final Messager messager = processingEnvironment.getMessager();
    messager.printMessage(Kind.NOTE, "Starting code generation for [" + className + "]");

    final Elements elementUtils = processingEnvironment.getElementUtils();

    // Extract required information
    final TypeElement classElement = (TypeElement) element;
    final String annotationName = ClientAPIModule.getWorkbenchScreenClass();

    String identifier = null;
    Integer preferredHeight = null;
    Integer preferredWidth = null;

    for (final AnnotationMirror am : classElement.getAnnotationMirrors()) {
      if (annotationName.equals(am.getAnnotationType().toString())) {
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry :
            am.getElementValues().entrySet()) {
          AnnotationValue aval = entry.getValue();
          if ("identifier".equals(entry.getKey().getSimpleName().toString())) {
            identifier = aval.getValue().toString();
          } else if ("preferredHeight".equals(entry.getKey().getSimpleName().toString())) {
            final int _preferredHeight = (Integer) aval.getValue();
            if (_preferredHeight > 0) {
              preferredHeight = _preferredHeight;
            }
          } else if ("preferredWidth".equals(entry.getKey().getSimpleName().toString())) {
            final int _preferredWidth = (Integer) aval.getValue();
            if (_preferredWidth > 0) {
              preferredWidth = _preferredWidth;
            }
          }
        }
        break;
      }
    }

    final String owningPlace =
        GeneratorUtils.getOwningPerspectivePlaceRequest(classElement, processingEnvironment);

    final String beanActivatorClass =
        GeneratorUtils.getBeanActivatorClassName(classElement, processingEnvironment);

    final ExecutableElement onStartupMethod =
        GeneratorUtils.getOnStartupMethodForNonEditors(classElement, processingEnvironment);

    final String onStartup0ParameterMethodName;
    final String onStartup1ParameterMethodName;
    if (onStartupMethod == null) {
      onStartup0ParameterMethodName = null;
      onStartup1ParameterMethodName = null;
    } else if (onStartupMethod.getParameters().isEmpty()) {
      onStartup0ParameterMethodName = onStartupMethod.getSimpleName().toString();
      onStartup1ParameterMethodName = null;
    } else {
      onStartup0ParameterMethodName = null;
      onStartup1ParameterMethodName = onStartupMethod.getSimpleName().toString();
    }

    final String onMayCloseMethodName =
        GeneratorUtils.getOnMayCloseMethodName(classElement, processingEnvironment);
    final String onCloseMethodName =
        GeneratorUtils.getOnCloseMethodName(classElement, processingEnvironment);
    final String onShutdownMethodName =
        GeneratorUtils.getOnShutdownMethodName(classElement, processingEnvironment);
    final String onOpenMethodName =
        GeneratorUtils.getOnOpenMethodName(classElement, processingEnvironment);
    final String onLostFocusMethodName =
        GeneratorUtils.getOnLostFocusMethodName(classElement, processingEnvironment);
    final String onFocusMethodName =
        GeneratorUtils.getOnFocusMethodName(classElement, processingEnvironment);
    final String getDefaultPositionMethodName =
        GeneratorUtils.getDefaultPositionMethodName(classElement, processingEnvironment);
    final String getTitleMethodName =
        GeneratorUtils.getTitleMethodName(classElement, processingEnvironment);
    final String getContextIdMethodName =
        GeneratorUtils.getContextIdMethodName(classElement, processingEnvironment);
    final ExecutableElement getTitleWidgetMethod =
        GeneratorUtils.getTitleWidgetMethodName(classElement, processingEnvironment);
    final String getTitleWidgetMethodName =
        getTitleWidgetMethod == null ? null : getTitleWidgetMethod.getSimpleName().toString();
    final ExecutableElement getWidgetMethod =
        GeneratorUtils.getWidgetMethodName(classElement, processingEnvironment);
    final String getWidgetMethodName =
        getWidgetMethod == null ? null : getWidgetMethod.getSimpleName().toString();
    final boolean hasUberView =
        GeneratorUtils.hasUberViewReference(classElement, processingEnvironment, getWidgetMethod);

    final boolean isWidget = GeneratorUtils.getIsWidget(classElement, processingEnvironment);
    final String getMenuBarMethodName =
        GeneratorUtils.getMenuBarMethodName(classElement, processingEnvironment);
    final String getToolBarMethodName =
        GeneratorUtils.getToolBarMethodName(classElement, processingEnvironment);
    final String securityTraitList =
        GeneratorUtils.getSecurityTraitList(elementUtils, classElement);
    final String rolesList = GeneratorUtils.getRoleList(elementUtils, classElement);

    if (GeneratorUtils.debugLoggingEnabled()) {
      messager.printMessage(Kind.NOTE, "Package name: " + packageName);
      messager.printMessage(Kind.NOTE, "Class name: " + className);
      messager.printMessage(Kind.NOTE, "Identifier: " + identifier);
      messager.printMessage(Kind.NOTE, "Owning Perspective Identifier: " + owningPlace);
      messager.printMessage(Kind.NOTE, "Preferred Height: " + preferredHeight);
      messager.printMessage(Kind.NOTE, "Preferred Width: " + preferredWidth);
      messager.printMessage(Kind.NOTE, "getContextIdMethodName: " + getContextIdMethodName);
      messager.printMessage(
          Kind.NOTE, "onStartup0ParameterMethodName: " + onStartup0ParameterMethodName);
      messager.printMessage(
          Kind.NOTE, "onStartup1ParameterMethodName: " + onStartup1ParameterMethodName);
      messager.printMessage(Kind.NOTE, "onMayCloseMethodName: " + onMayCloseMethodName);
      messager.printMessage(Kind.NOTE, "onCloseMethodName: " + onCloseMethodName);
      messager.printMessage(Kind.NOTE, "onShutdownMethodName: " + onShutdownMethodName);
      messager.printMessage(Kind.NOTE, "onOpenMethodName: " + onOpenMethodName);
      messager.printMessage(Kind.NOTE, "onLostFocusMethodName: " + onLostFocusMethodName);
      messager.printMessage(Kind.NOTE, "onFocusMethodName: " + onFocusMethodName);
      messager.printMessage(
          Kind.NOTE, "getDefaultPositionMethodName: " + getDefaultPositionMethodName);
      messager.printMessage(Kind.NOTE, "getTitleMethodName: " + getTitleMethodName);
      messager.printMessage(Kind.NOTE, "getTitleWidgetMethodName: " + getTitleWidgetMethodName);
      messager.printMessage(Kind.NOTE, "getWidgetMethodName: " + getWidgetMethodName);
      messager.printMessage(Kind.NOTE, "isWidget: " + Boolean.toString(isWidget));
      messager.printMessage(Kind.NOTE, "hasUberView: " + Boolean.toString(hasUberView));
      messager.printMessage(Kind.NOTE, "getMenuBarMethodName: " + getMenuBarMethodName);
      messager.printMessage(Kind.NOTE, "getToolBarMethodName: " + getToolBarMethodName);
      messager.printMessage(Kind.NOTE, "securityTraitList: " + securityTraitList);
      messager.printMessage(Kind.NOTE, "rolesList: " + rolesList);
    }

    // Validate getWidgetMethodName and isWidget
    if (!isWidget && getWidgetMethodName == null) {
      throw new GenerationException(
          "The WorkbenchScreen must either extend IsWidget or provide a @WorkbenchPartView annotated method to return a com.google.gwt.user.client.ui.IsWidget.",
          packageName + "." + className);
    }
    if (isWidget && getWidgetMethodName != null) {
      final String msg =
          "The WorkbenchScreen both extends com.google.gwt.user.client.ui.IsWidget and provides a @WorkbenchPartView annotated method. The annotated method will take precedence.";
      messager.printMessage(Kind.WARNING, msg, classElement);
    }

    // Validate getTitleMethodName and getTitleWidgetMethodName
    if (getTitleMethodName == null) {
      throw new GenerationException(
          "The WorkbenchScreen must provide a @WorkbenchPartTitle annotated method to return a java.lang.String.",
          packageName + "." + className);
    }

    // Setup data for template sub-system
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("packageName", packageName);
    root.put("className", className);
    root.put("identifier", identifier);
    root.put("owningPlace", owningPlace);
    root.put("preferredHeight", preferredHeight);
    root.put("preferredWidth", preferredWidth);
    root.put("getContextIdMethodName", getContextIdMethodName);
    root.put("realClassName", classElement.getSimpleName().toString());
    root.put("beanActivatorClass", beanActivatorClass);
    root.put("onStartup0ParameterMethodName", onStartup0ParameterMethodName);
    root.put("onStartup1ParameterMethodName", onStartup1ParameterMethodName);
    root.put("onMayCloseMethodName", onMayCloseMethodName);
    root.put("onCloseMethodName", onCloseMethodName);
    root.put("onShutdownMethodName", onShutdownMethodName);
    root.put("onOpenMethodName", onOpenMethodName);
    root.put("onLostFocusMethodName", onLostFocusMethodName);
    root.put("onFocusMethodName", onFocusMethodName);
    root.put("getDefaultPositionMethodName", getDefaultPositionMethodName);
    root.put("getTitleMethodName", getTitleMethodName);
    root.put("getTitleWidgetMethodName", getTitleWidgetMethodName);
    root.put("getWidgetMethodName", getWidgetMethodName);
    root.put("isWidget", isWidget);
    root.put("hasUberView", hasUberView);
    root.put("getMenuBarMethodName", getMenuBarMethodName);
    root.put("getToolBarMethodName", getToolBarMethodName);
    root.put("securityTraitList", securityTraitList);
    root.put("rolesList", rolesList);

    // Generate code
    final StringWriter sw = new StringWriter();
    final BufferedWriter bw = new BufferedWriter(sw);
    try {
      final Template template = config.getTemplate("activityScreen.ftl");
      template.process(root, bw);
    } catch (IOException ioe) {
      throw new GenerationException(ioe);
    } catch (TemplateException te) {
      throw new GenerationException(te);
    } finally {
      try {
        bw.close();
        sw.close();
      } catch (IOException ioe) {
        throw new GenerationException(ioe);
      }
    }
    messager.printMessage(Kind.NOTE, "Successfully generated code for [" + className + "]");

    return sw.getBuffer();
  }
Пример #26
0
 public Messager getMessager() {
   return processingEnvironment.getMessager();
 }
Пример #27
0
 private Logger(ProcessingEnvironment pe) {
   mMessager = new WeakReference<>(pe.getMessager());
 }