Java Code Examples for javax.lang.model.element.TypeElement.toString()

The following are Jave code examples for showing how to use toString() of the javax.lang.model.element.TypeElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RxPay   File: ClassEntity.java   Source Code and License Vote up 6 votes
/**
 * @param elementUtils
 * @param typeUtils
 * @param element      current anntated class
 */
public ClassEntity(Elements elementUtils, Types typeUtils, TypeElement element) {
    elementWeakCache = new WeakReference<TypeElement>(element);
    this.classPackageName = elementUtils.getPackageOf(element).getQualifiedName().toString();
    this.modifierSet = element.getModifiers();
    this.className = element.toString();
    annotationMirrors = element.getAnnotationMirrors();
    this.classSimpleName = element.getSimpleName();
    this.classQualifiedName = element.getQualifiedName();
    if ("java.lang.Object".equals(element.getSuperclass().toString())){
        this.superclass = null;
    }else{
        this.superclass = element.getSuperclass().toString();
    }
    List<? extends TypeMirror> interfaces = element.getInterfaces();

    for (TypeMirror anInterface : interfaces){
        this.interfaces.add(typeUtils.asElement(anInterface).toString());
    }
}
 
Example 2
Project: incubator-netbeans   File: APIIsSelfContainedTest.java   Source Code and License Vote up 5 votes
private boolean isAPIClass(TypeElement clazz) {
    String nameS = /*!!!!*/clazz.toString();
    
    for (String s : API_PACKAGES) {
        if (nameS.startsWith(s))
            return true;
    }
    
    return false;
}
 
Example 3
Project: jtsgen   File: TypeScriptAnnotationProcessor.java   Source Code and License Vote up 5 votes
private boolean checkExclusion(TypeElement element) {
    final String typeName=element.toString();
    boolean r= this.processingInfo.getTsModel().getModuleInfo().getExcludes().stream().anyMatch(
            x -> x.matcher(typeName).find()
    );
    if (r) LOG.fine(() -> "TSAP exclusion " + element);
    return r;
}
 
Example 4
Project: easy-plugins   File: Util.java   Source Code and License Vote up 5 votes
private static void checkClassVisibility(Elements eles, TypeElement target, String fromPkg) {
    Set<Modifier> targetMods = target.getModifiers();
    if (!isNestedClass(target)) {
        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    } else {
        Element surround = target.getEnclosingElement();

        if (surround.getKind() != CLASS
                && surround.getKind() != INTERFACE
                // Not sure if that is allowed, but we include it anyways.
                && surround.getKind() != ENUM) {
            throw new IllegalStateException(
                    target.toString() + " is not nested? " + surround.toString());
        }

        TypeElement enclosingType = (TypeElement) surround;

        // The surrounding class must be visible for us to see the nested class
        if (!isElementVisibleFrom(eles, enclosingType, fromPkg)) {
            throw new EasyPluginException(enclosingType.toString()
                    + " is not visible from output package; need for access to " + target.toString());
        }
        // Nested class must be static since we don't have an enclosing instance
        if (!targetMods.contains(Modifier.STATIC)) {
            throw new EasyPluginException(target.toString() + " must be static.");
        }

        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    }
}
 
Example 5
Project: GitHub   File: PresenterBinderClassGenerator.java   Source Code and License Vote up 4 votes
public boolean generate(VariableElement variableElement, List<ClassGeneratingParams> classGeneratingParamsList) {
	final Element enclosingElement = variableElement.getEnclosingElement();

	if (!(enclosingElement instanceof TypeElement)) {
		throw new RuntimeException("Only class fields could be annotated as @InjectPresenter: " + variableElement + " at " + enclosingElement);
	}

	if (mPresentersContainers.contains(enclosingElement)) {
		return false;
	}

	TypeElement presentersContainer = (TypeElement) enclosingElement;

	mPresentersContainers.add(presentersContainer);

	String fullClassName = Util.getFullClassName(presentersContainer);

	ClassGeneratingParams classGeneratingParams = new ClassGeneratingParams();
	classGeneratingParams.setName(fullClassName + MvpProcessor.PRESENTER_BINDER_SUFFIX);

	String parentClassName = presentersContainer.toString();

	final String viewClassName = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);

	String builder = "package " + fullClassName.substring(0, fullClassName.lastIndexOf(".")) + ";\n" +
	                 "\n" +
	                 "import java.util.ArrayList;\n" +
	                 "import java.util.List;\n" +
	                 "\n" +
	                 "import com.arellomobile.mvp.PresenterBinder;\n" +
	                 "import com.arellomobile.mvp.presenter.PresenterField;\n" +
	                 "import com.arellomobile.mvp.MvpPresenter;\n" +
	                 "import com.arellomobile.mvp.presenter.PresenterType;\n" +
	                 "\n" +
	                 "public class " + viewClassName + MvpProcessor.PRESENTER_BINDER_SUFFIX + " extends PresenterBinder<" + parentClassName + "> {\n";

	List<Field> fields = collectFields(presentersContainer);

	List<PresenterProvider> presenterProviders = collectPresenterProviders(presentersContainer);

	List<TagProvider> tagProviders = collectTagProviders(presentersContainer);

	bindProvidersToFields(fields, presenterProviders);

	bindTagProvidersToFields(fields, tagProviders);

	for (Field field : fields) {
		builder = generatePresenterBinderClass(builder, parentClassName, field);
	}

	builder = generateGetPresentersMethod(builder, fields, parentClassName);

	builder += "}\n";

	classGeneratingParams.setBody(builder);
	classGeneratingParamsList.add(classGeneratingParams);

	return true;
}
 
Example 6
Project: GitHub   File: ViewStateProviderClassGenerator.java   Source Code and License Vote up 4 votes
@Override
public boolean generate(TypeElement typeElement, List<ClassGeneratingParams> classGeneratingParamsList) {
	String fullPresenterClassName = typeElement.toString();

	mPresenterClassNames.add(fullPresenterClassName);

	final String presenterClassName = fullPresenterClassName.substring(fullPresenterClassName.lastIndexOf(".") + 1);

	String viewState = getViewStateClassFromAnnotationParams(typeElement);
	if (viewState == null) {
		String view = getViewClassFromAnnotationParams(typeElement);
		if (view == null) {
			view = getViewClassFromGeneric(typeElement);
		}

		if (view != null) {
			// Remove generic from view class name
			if (view.contains("<")) {
				view = view.substring(0, view.indexOf("<"));
			}

			TypeElement viewTypeElement = MvpCompiler.getElementUtils().getTypeElement(view);
			if (viewTypeElement == null) {
				throw new IllegalArgumentException("View \"" + view + "\" for " + typeElement + " cannot be found");
			}

			mUsedViews.add(viewTypeElement);
			viewState = Util.getFullClassName(viewTypeElement) + MvpProcessor.VIEW_STATE_SUFFIX;
		}
	}

	String builder = "package " + fullPresenterClassName.substring(0, fullPresenterClassName.lastIndexOf(".")) + ";\n" +
	                 "\n" +
	                 "import com.arellomobile.mvp.ViewStateProvider;\n" +
	                 "import com.arellomobile.mvp.MvpView;\n" +
	                 "import com.arellomobile.mvp.viewstate.MvpViewState;\n" +
	                 "\npublic class " + presenterClassName + MvpProcessor.VIEW_STATE_PROVIDER_SUFFIX + " extends ViewStateProvider {\n" +
	                 "\t\n" +
	                 "\[email protected]\n" +
	                 "\tpublic MvpViewState<? extends MvpView> getViewState() {\n";
	if (viewState == null) {
		builder += "\t\tthrow new RuntimeException(" + fullPresenterClassName + " should has view\");\n";
	} else {
		builder += "\t\treturn new " + viewState + "();\n";
	}
	builder += "\t}\n" +
	           "}";

	ClassGeneratingParams classGeneratingParams = new ClassGeneratingParams();
	classGeneratingParams.setName(fullPresenterClassName + MvpProcessor.VIEW_STATE_PROVIDER_SUFFIX);
	classGeneratingParams.setBody(builder);
	classGeneratingParamsList.add(classGeneratingParams);

	return true;
}
 
Example 7
Project: Hannibai   File: HandleImplGenerator.java   Source Code and License Vote up 4 votes
public HandleImplGenerator(TypeElement element, String classNameSuffix, String superinterface) {
    super(element, classNameSuffix);
    this.mSuperinterface = superinterface;
    this.mSharedPreferencesName = element.toString();
}
 
Example 8
Project: easy-plugins   File: Util.java   Source Code and License Vote up 4 votes
static void checkConcreteType(TypeElement e) {
    Set<Modifier> mods = e.getModifiers();
    if (mods.contains(Modifier.ABSTRACT) || e.getKind().isInterface()) {
        throw new EasyPluginException(e.toString() + " must be concrete to use as a service.");
    }
}