Java Code Examples for com.squareup.javapoet.ClassName#packageName()

The following examples show how to use com.squareup.javapoet.ClassName#packageName() . These examples are extracted from open source projects. 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: grouter-android   File: TypeUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String reflectionName(ClassName className) {
        // trivial case: no nested names
//        if (className.names.size() == 2) {
//            String packageName = packageName();
//            if (packageName.isEmpty()) {
//                return className.simpleName();
//            }
//            return packageName + "." + className.simpleName();
//        }
//        // concat top level class name and nested names
//        StringBuilder builder = new StringBuilder();
//        builder.append(className.topLevelClassName());
//        for (String name : className.simpleNames().subList(1, className.simpleNames().size())) {
//            builder.append('$').append(name);
//        }
        return className.packageName() + "." + className.simpleName();
    }
 
Example 2
Source Project: grouter-android   File: TypeUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String reflectionName(ClassName className) {
        // trivial case: no nested names
//        if (className.names.size() == 2) {
//            String packageName = packageName();
//            if (packageName.isEmpty()) {
//                return className.simpleName();
//            }
//            return packageName + "." + className.simpleName();
//        }
//        // concat top level class name and nested names
//        StringBuilder builder = new StringBuilder();
//        builder.append(className.topLevelClassName());
//        for (String name : className.simpleNames().subList(1, className.simpleNames().size())) {
//            builder.append('$').append(name);
//        }
        return className.packageName() + "." + className.simpleName();
    }
 
Example 3
Source Project: dataenum   File: OutputSpecFactory.java    License: Apache License 2.0 5 votes vote down vote up
static ClassName toOutputClassName(ClassName specClassName) throws ParserException {
  String packageName = specClassName.packageName();
  String name = specClassName.simpleName();

  if (!isSpecClassName(specClassName)) {
    throw new ParserException(
        String.format(
            "Bad name for DataEnum interface! Name must end with '%s', found: %s", SUFFIX, name));
  }

  String nameWithoutSuffix = name.substring(0, name.length() - SUFFIX.length());
  return ClassName.get(packageName, nameWithoutSuffix);
}
 
Example 4
public List<ActivityModel> process(RoundEnvironment roundEnv) {
    Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(RouterActivity.class);
    List<ActivityModel> typeModels = new ArrayList<>();
    for (Element element : elements) {
        TypeElement typeElement = (TypeElement) element;
        RouterActivity routerActivity = typeElement.getAnnotation(RouterActivity.class);
        ActivityModel typeModel = new ActivityModel();
        typeModels.add(typeModel);
        typeModel.exported = routerActivity.exported();
        typeModel.name = routerActivity.name();
        typeModel.description = routerActivity.description();
        typeModel.path = routerActivity.value();

        // 设置类名
        ClassName className = (ClassName) ClassName.get(typeElement.asType());
        typeModel.type = className.packageName() + "." + className.simpleName();
        // 设置参数
        List<? extends Element> members = routerProcessor.elementUtils.getAllMembers(typeElement);
        for (Element mb : members) {
            RouterField routerField = mb.getAnnotation(RouterField.class);
            if (routerField == null) {
                continue;
            }
            if (!mb.getEnclosingElement().equals(typeElement)) {
                System.out.println("父类属性");
                continue;
            }
            ParameterModel parameterModel = new ParameterModel();
            parameterModel.queryName = routerField.value();
            TypeName typeName = TypeName.get(mb.asType());
            parameterModel.rawType = typeName.toString();
            parameterModel.type = TypeUtils.getRouterActivityTypeString(typeName);
            parameterModel.name = mb.getSimpleName().toString();
            typeModel.params.add(parameterModel);
        }

    }
    Collections.sort(typeModels);
    return typeModels;
}
 
Example 5
private ClassName findDaggerComponent(TypeMirror typeMirror) {
    final ClassName typeName = (ClassName) TypeName.get(typeMirror);
    final String packageName = typeName.packageName();
    final String className = typeName.simpleName();
    return ClassName.bestGuess(packageName + "." + Constants.DAGGER + className);
}
 
Example 6
private ClassName findComponent(TypeMirror typeMirror) {
    final ClassName typeName = (ClassName) TypeName.get(typeMirror);
    final String packageName = typeName.packageName();
    final String className = typeName.simpleName();
    return ClassName.bestGuess(packageName + "." + className);
}
 
Example 7
Source Project: OkDeepLink   File: ElementUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String getName(ClassName className) {
    return className.packageName()+"."+ className.simpleName();
}
 
Example 8
Source Project: grouter-android   File: TaskProcessor.java    License: Apache License 2.0 4 votes vote down vote up
public List<TaskModel> process(RoundEnvironment roundEnv) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(RouterTask.class);
        List<TaskModel> typeModels = new ArrayList<>();
        for (Element element : elements) {
            TypeElement typeElement = (TypeElement) element;
            TaskModel typeModel = new TaskModel();
            RouterTask routerTask = element.getAnnotation(RouterTask.class);
            typeModel.returns = routerTask.returns();
            typeModel.name = routerTask.name();
            typeModel.description = routerTask.description();
            // 设置类名
            ClassName className = (ClassName) ClassName.get(typeElement.asType());
            typeModel.type = className.packageName() + "." + className.simpleName();
            // 设置参数
            List<? extends Element> members = routerProcessor.elementUtils.getAllMembers(typeElement);
            for (Element mb : members) {
                RouterField routerField = mb.getAnnotation(RouterField.class);
                if (routerField == null) {
                    continue;
                }
                if (!mb.getEnclosingElement().equals(typeElement)) {
                    System.out.println("父类属性");
                    continue;
                }
//                    System.out.println("getEnclosingElement:"+mb.getEnclosingElement().getSimpleName());
                ParameterModel parameterModel = new ParameterModel();
                parameterModel.queryName = routerField.value();
                TypeName typeName = TypeName.get(mb.asType());
                parameterModel.rawType = typeName.toString();
                parameterModel.type = TypeUtils.getRouterTaskTypeString(typeName);
                parameterModel.name = mb.getSimpleName().toString();
                typeModel.params.add(parameterModel);
            }
            // 设置路径
            RouterTask routerActivity = typeElement.getAnnotation(RouterTask.class);
            typeModel.path = routerActivity.value();
            typeModels.add(typeModel);
        }
        Collections.sort(typeModels);
//        String json = JSON.toJSONString(typeModels, true);
//
//        File dir = new File(routerProcessor.GROUTER_SOURCE_PATH);
//        if (!dir.exists()) {
//            dir.mkdir();
//        }
//        try {
//            dir = new File(dir, "com/grouter");
//            File file = new File(dir, "RouterTask-" + routerProcessor.MODULE_NAME + ".json");
//            FileWriter fileWriter = new FileWriter(file);
//            fileWriter.write(json);
//            fileWriter.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return typeModels;
    }
 
Example 9
Source Project: kripton   File: M2MEntity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Works with @BindDaoMany2Many and @BindDao to extract entity name.
 * @param schema 
 *
 * @param daoElement the dao element
 * @return the m 2 M entity
 */
public static M2MEntity extractEntityManagedByDAO(TypeElement daoElement) {
	ClassName entity1 = null;
	ClassName entity2 = null;
	String prefixId = null;
	String tableName = null;
	String entityName = null;
	PackageElement pkg = null;
	String packageName = null;
	boolean needToCreate = true;
	boolean generatedMethods=true;
	boolean immutable=true;
	
	
	if (daoElement.getAnnotation(BindDaoMany2Many.class) != null) {
		entity1 = TypeUtility.className(AnnotationUtility.extractAsClassName(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_1));
		entity2 = TypeUtility.className(AnnotationUtility.extractAsClassName(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ENTITY_2));
		prefixId = AnnotationUtility.extractAsString(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.ID_NAME);
		tableName = AnnotationUtility.extractAsString(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.TABLE_NAME);
		tableName = AnnotationUtility.extractAsString(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.TABLE_NAME);
		immutable = AnnotationUtility.extractAsBoolean(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.IMMUTABLE);
		
		generatedMethods=AnnotationUtility.extractAsBoolean(daoElement, BindDaoMany2Many.class, AnnotationAttributeType.METHODS);
		
		entityName = entity1.simpleName() + entity2.simpleName();
		pkg = BaseProcessor.elementUtils.getPackageOf(daoElement);
		packageName = pkg.isUnnamed() ? null : pkg.getQualifiedName().toString();
	}

	if (daoElement.getAnnotation(BindDao.class) != null) {
		// we have @BindDao
		String derived = AnnotationUtility.extractAsClassName(daoElement, BindDao.class, AnnotationAttributeType.VALUE);
		ClassName clazz = TypeUtility.className(derived);

		packageName = clazz.packageName();
		entityName = clazz.simpleName();

		String tableTemp = AnnotationUtility.extractAsClassName(daoElement, BindDao.class, AnnotationAttributeType.TABLE_NAME);
		if (StringUtils.hasText(tableTemp)) {
			tableName = tableTemp;
		}

		needToCreate = false;
	}

	M2MEntity entity = new M2MEntity(daoElement, packageName, entityName, TypeUtility.className(daoElement.asType().toString()), entity1, entity2, prefixId, tableName, needToCreate, generatedMethods, immutable);

	return entity;
}