javax.lang.model.util.SimpleTypeVisitor7 Java Examples

The following examples show how to use javax.lang.model.util.SimpleTypeVisitor7. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: alchemy   Author: DanielSerdyukov   File: RelationRule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void process(Element element) throws Exception {
    final Element enclosingElement = element.getEnclosingElement();
    if (enclosingElement.getAnnotation(Entry.class) == null) {
        throw new ElementException("Class containing @Relation must be annotated with @Entry", enclosingElement);
    }
    element.asType().accept(new SimpleTypeVisitor7<Void, Void>() {
        @Override
        public Void visitDeclared(DeclaredType t, Void unused) {
            final List<? extends TypeMirror> args = t.getTypeArguments();
            if (args.isEmpty()) {
                processOneToOne(element, t.asElement());
            } else {
                processOneToMany(element, (TypeElement) t.asElement(), args.get(0));
            }
            return super.visitDeclared(t, unused);
        }
    }, null);
}
 
Example #2
Source Project: alchemy   Author: DanielSerdyukov   File: RelationRule.java    License: Apache License 2.0 6 votes vote down vote up
private void processOneToMany(Element field, Element collectionType, TypeMirror relation) {
    if (!mTypeUtils.isAssignable(collectionType.asType(), List.class)) {
        throw new ElementException("Relation type must be subclass of List<E>", field);
    }
    relation.accept(new SimpleTypeVisitor7<Void, Void>() {
        @Override
        public Void visitDeclared(DeclaredType t, Void unused) {
            final Element element = t.asElement();
            if (element.getAnnotation(Entry.class) == null) {
                throw new ElementException("Related type must be annotated with @Entry", element);
            }
            final Element enclosingElement = field.getEnclosingElement();
            final TableSpec lTable = mCompileGraph.findTableSpec(enclosingElement);
            final TableSpec rTable = mCompileGraph.findTableSpec(element);
            final ClassName className = makeClassName(field);
            final RelationSpec relationSpec = new RelationSpec(
                    field, className, lTable, rTable, true);
            mCompileGraph.putRelationSpec(enclosingElement, relationSpec);
            return super.visitDeclared(t, unused);
        }
    }, null);
}
 
Example #3
Source Project: appinventor-extensions   Author: mit-cml   File: ComponentProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tracks the superclass and superinterfaces for the given type and if the type inherits from
 * {@link com.google.appinventor.components.runtime.Component} then it adds the class to the
 * componentTypes list. This allows properties, methods, and events to use concrete Component
 * types as parameters and return values.
 *
 * @param type a TypeMirror representing a type on the class path
 */
private void updateComponentTypes(TypeMirror type) {
  if (type.getKind() == TypeKind.DECLARED) {
    type.accept(new SimpleTypeVisitor7<Boolean, Set<String>>(false) {
      @Override
      public Boolean visitDeclared(DeclaredType t, Set<String> types) {
        final String typeName = t.asElement().toString();
        if ("com.google.appinventor.components.runtime.Component".equals(typeName)) {
          return true;
        }
        if (!types.contains(typeName)) {
          types.add(typeName);
          final TypeElement typeElement = (TypeElement) t.asElement();
          if (typeElement.getSuperclass().accept(this, types)) {
            componentTypes.add(typeName);
            return true;
          }
          for (TypeMirror iface : typeElement.getInterfaces()) {
            if (iface.accept(this, types)) {
              componentTypes.add(typeName);
              return true;
            }
          }
        }
        return componentTypes.contains(typeName);
      }
    }, visitedTypes);
  }
}
 
Example #4
Source Project: kripton   Author: xcesco   File: TypeUtility.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Retrieve parametrized type of element (from its parent).
 * </p>
 *
 * @param element
 *            the element
 * @return list of typemirror or empty list
 */
public static List<TypeName> getTypeArguments(TypeElement element) {
	final List<TypeName> result = new ArrayList<>();

	if (element.getKind() == ElementKind.CLASS) {
		if (element.getSuperclass() instanceof DeclaredType) {
			result.addAll(convert(((DeclaredType) element.getSuperclass()).getTypeArguments()));
		}
	} else if (element.getKind() == ElementKind.INTERFACE) {

		List<? extends TypeMirror> interfaces = element.getInterfaces();

		for (TypeMirror item : interfaces) {
			item.accept(new SimpleTypeVisitor7<Void, Void>() {

				@Override
				public Void visitDeclared(DeclaredType t, Void p) {
					result.addAll(convert(t.getTypeArguments()));
					return null;
				}

			}, null);

		}
	}

	return result;
}
 
Example #5
Source Project: Smirk   Author: baoyongzhang   File: TypeNames.java    License: MIT License 4 votes vote down vote up
public TypeName forTypeMirror(TypeMirror mirror) {
    return mirror.accept(new SimpleTypeVisitor7<TypeName, Void>(){

    }, null);
}