Package javax.lang.model.element

Examples of javax.lang.model.element.Element


    if (InternalUtils.isSyntheticConstructor(member)) {
      return;
    }
    boolean ok = false;
    if (member instanceof VariableTree) {
      Element memberElement = TreeUtils.elementFromDeclaration((VariableTree) member);
      ok = memberElement.getKind() == ElementKind.ENUM_CONSTANT;
    }
    if (!ok) {
      context.addError(member, "Enums with fields or methods are not supported");
    }
  }
View Full Code Here


    return true;
  }

  @Override
  public Void visit(CheckVisitor visitor, IdentifierTree tree, GenerationContext<Void> context) {
    Element fieldElement = TreeUtils.elementFromUse(tree);
    if (!isRegularField(fieldElement, tree)) {
      return null;
    }

    if (fieldElement.getAnnotation(ServerSide.class) != null) {
      context.addError(tree, "You cannot access fields annotated with @ServerSide in a client code");
    }

    return null;
  }
View Full Code Here

   * Returns the innermost type element enclosing the given element
   * @param elem the enclosed element of a class
   * @return the innermost type element
   */
  public static TypeElement enclosingClass(final Element elem) {
    Element result = elem;
    while (result != null && !result.getKind().isClass() && !result.getKind().isInterface()) {
      /* @Nullable */Element encl = result.getEnclosingElement();
      result = encl;
    }
    return (TypeElement) result;
  }
View Full Code Here

   * {@link javax.lang.model.util.Elements#getPackageOf(Element)}. Returns the element itself if it is a package.
   * @param elem the enclosed element of a package
   * @return the innermost package element
   */
  public static PackageElement enclosingPackage(final Element elem) {
    Element result = elem;
    while (result != null && result.getKind() != ElementKind.PACKAGE) {
      /* @Nullable */Element encl = result.getEnclosingElement();
      result = encl;
    }
    return (PackageElement) result;
  }
View Full Code Here

  private boolean isCallToSuperConstructor(MethodInvocationTree tree) {
    if (!TreeUtils.isSuperCall(tree)) {
      return false;
    }

    Element methodElement = TreeUtils.elementFromUse(tree);
    if (JavaNodes.isStatic(methodElement)) {
      // this is a call of type super.staticMethod(args) -> it should be handled as a simple call to staticMethod
      return false;
    }
View Full Code Here

  /**
   * super(args) -> SuperType.call(this, args)
   */
  private JS callToSuperConstructor(WriterVisitor<JS> visitor, MethodInvocationTree tree, GenerationContext<JS> context) {
    Element methodElement = TreeUtils.elementFromUse(tree);
    TypeElement typeElement = (TypeElement) methodElement.getEnclosingElement();

    String methodName = MethodInvocationWriter.buildMethodName(tree);

    // avoid useless call to super() when the super class is Object
    if (GeneratorConstants.SUPER.equals(methodName) && JavaNodes.sameRawType(typeElement.asType(), Object.class)) {
View Full Code Here

  /**
   * generate the namespace declaration stjs.ns("namespace") if needed
   */
  private void addNamespace(ClassTree tree, GenerationContext<JS> context, List<JS> stmts) {
    Element type = TreeUtils.elementFromDeclaration(tree);
    if (JavaNodes.isInnerType(type)) {
      // this is an inner (anonymous or not) class - no namespace declaration is generated
      return;
    }
    String namespace = JavaNodes.getNamespace(type);
View Full Code Here

  /**
   * @return the node to put in the super class. for intefaces, the super class goes also in the interfaces list
   */
  private JS getSuperClass(ClassTree clazz, GenerationContext<JS> context) {
    Element type = TreeUtils.elementFromDeclaration(clazz);
    if (clazz.getExtendsClause() == null || type.getKind() == ElementKind.INTERFACE) {
      // no super class found
      return context.js().keyword(Keyword.NULL);
    }

    TreeWrapper<Tree, JS> superType = context.getCurrentWrapper().child(clazz.getExtendsClause());
View Full Code Here

      if (!ifaceType.isSyntheticType()) {
        ifaces.add(context.js().name(ifaceType.getTypeName()));
      }
    }

    Element type = TreeUtils.elementFromDeclaration(clazz);
    if (clazz.getExtendsClause() != null && type.getKind() == ElementKind.INTERFACE) {
      TreeWrapper<Tree, JS> superType = context.getCurrentWrapper().child(clazz.getExtendsClause());
      if (!superType.isSyntheticType()) {
        ifaces.add(0, context.js().name(superType.getTypeName()));
      }
    }
View Full Code Here

    return JavascriptKeywords.CONSTRUCTOR + typeName.substring(pos);
  }

  @SuppressWarnings("unused")
  private boolean generareEnum(WriterVisitor<JS> visitor, ClassTree tree, GenerationContext<JS> context, List<JS> stmts) {
    Element type = TreeUtils.elementFromDeclaration(tree);
    if (type.getKind() != ElementKind.ENUM) {
      return false;
    }

    JavaScriptBuilder<JS> js = context.js();

    // add all anum entries
    List<JS> enumEntries = new ArrayList<JS>();
    for (Element member : ElementUtils.getAllFieldsIn((TypeElement) type)) {
      if (member.getKind() == ElementKind.ENUM_CONSTANT) {
        enumEntries.add(js.string(member.getSimpleName().toString()));
      }
    }

    JS enumConstructor = js.functionCall(js.property(js.name(GeneratorConstants.STJS), "enumeration"), enumEntries);

    String typeName = context.getNames().getTypeName(context, type);
    if (typeName.contains(".")) {
      // inner class or namespace
      boolean innerClass = type.getEnclosingElement().getKind() != ElementKind.PACKAGE;
      String leftSide = innerClass ? replaceFullNameWithConstructor(typeName) : typeName;

      stmts.add(js.expressionStatement(js.assignment(AssignOperator.ASSIGN, js.name(leftSide), enumConstructor)));
    } else {
      // regular class
View Full Code Here

TOP

Related Classes of javax.lang.model.element.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.