本文整理匯總了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();
}