本文整理汇总了Java中javax.lang.model.element.VariableElement.getEnclosingElement方法的典型用法代码示例。如果您正苦于以下问题:Java VariableElement.getEnclosingElement方法的具体用法?Java VariableElement.getEnclosingElement怎么用?Java VariableElement.getEnclosingElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.VariableElement
的用法示例。
在下文中一共展示了VariableElement.getEnclosingElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitVariable
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@Override
public StringBuilder visitVariable(VariableElement e, Boolean p) {
if (p != Boolean.TRUE || e.getEnclosingElement() == null) {
return DEFAULT_VALUE.append(e.getSimpleName());
} else {
return e.getEnclosingElement().accept(this, p).
append(".").
append(e.getSimpleName());
}
}
示例2: visitVariable
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@Override
public Void visitVariable(VariableElement e, Boolean highlightName) {
modifier(e.getModifiers());
result.append(getTypeName(info, e.asType(), true));
result.append(' ');
boldStartCheck(highlightName);
result.append(e.getSimpleName());
boldStopCheck(highlightName);
if (highlightName) {
if (e.getConstantValue() != null) {
result.append(" = ");
result.append(StringEscapeUtils.escapeHtml(e.getConstantValue().toString()));
}
Element enclosing = e.getEnclosingElement();
if (e.getKind() != ElementKind.PARAMETER && e.getKind() != ElementKind.LOCAL_VARIABLE
&& e.getKind() != ElementKind.RESOURCE_VARIABLE && e.getKind() != ElementKind.EXCEPTION_PARAMETER) {
result.append(" in ");
//short typename:
result.append(getTypeName(info, enclosing.asType(), true));
}
}
return null;
}
示例3: generate
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
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;
}
示例4: getDeclaringClassForField
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
public TypeElement getDeclaringClassForField(VariableElement f) {
return (TypeElement) f.getEnclosingElement();
}