本文整理匯總了Java中javax.lang.model.util.ElementFilter.fieldsIn方法的典型用法代碼示例。如果您正苦於以下問題:Java ElementFilter.fieldsIn方法的具體用法?Java ElementFilter.fieldsIn怎麽用?Java ElementFilter.fieldsIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.util.ElementFilter
的用法示例。
在下文中一共展示了ElementFilter.fieldsIn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParcelableFieldsOrError
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
* This method returns a list of all non private fields. If any <code>private</code> fields is
* found, the method errors out
*
* @param type element
* @return list of all non-<code>private</code> fields
*/
private List<VariableElement> getParcelableFieldsOrError(TypeElement type) {
List<VariableElement> allFields = ElementFilter.fieldsIn(type.getEnclosedElements());
List<VariableElement> nonPrivateFields = new ArrayList<>();
for (VariableElement field : allFields) {
if (!field.getModifiers().contains(PRIVATE)) {
nonPrivateFields.add(field);
} else {
// return error, PRIVATE fields are not allowed
mErrorReporter.abortWithError("getFieldsError error, PRIVATE fields not allowed", type);
}
}
return nonPrivateFields;
}
示例2: run
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public void run(WorkingCopy copy) throws Exception {
copy.toPhase(JavaSource.Phase.RESOLVED);
TreePath tp = copy.getTreeUtilities().pathFor(offset);
assertTrue(TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind()));
ClassTree ct = (ClassTree)tp.getLeaf();
TypeElement te = (TypeElement)copy.getTrees().getElement(tp);
assertNotNull(te);
List<? extends VariableElement> vars = ElementFilter.fieldsIn(te.getEnclosedElements());
assertEquals(1, vars.size());
GeneratorUtilities utilities = GeneratorUtilities.get(copy);
assertNotNull(utilities);
ClassTree newCt = utilities.insertClassMember(ct, getter
? utilities.createGetter(te, vars.get(0))
: utilities.createSetter(te, vars.get(0)));
copy.rewrite(ct, newCt);
}
示例3: visitClass
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
@Override
public synchronized Void visitClass(ClassTree t, Void v) {
Element el = info.getTrees().getElement(getCurrentPath());
if (el == null) {
return null;
}
TypeElement te = (TypeElement) el;
List<VariableElement> fields = ElementFilter.fieldsIn(te.getEnclosedElements());
enumConsts = new LinkedList<String>();
for (VariableElement field : fields) {
if (field.getKind() == ElementKind.ENUM_CONSTANT) {
String name = field.getSimpleName().toString();
enumConsts.add(name);
}
}
return null;
}
示例4: collectTypedefs
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private void collectTypedefs(TypeElement type, Map<String, TypeMirror> collected) {
for (VariableElement field : ElementFilter.fieldsIn(elements.getAllMembers(type))) {
if (field.getAnnotation(Generator.Typedef.class) != null) {
collected.put(field.getSimpleName().toString(), field.asType());
}
}
}
示例5: findSerialVersionUID
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private Long findSerialVersionUID() {
for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) {
if (field.getSimpleName().contentEquals(SERIAL_VERSION_FIELD_NAME)
&& field.asType().getKind() == TypeKind.LONG) {
return (Long) field.getConstantValue();
}
}
return null;
}
示例6: getField
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement getField(TypeElement clazz, String fieldName) {
for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
if (field.getSimpleName().contentEquals(fieldName)) {
return field;
}
}
return null;
}
示例7: guessField
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement guessField(ExecutableElement getter) {
String name = getter.getSimpleName().toString().substring(3);
String guessFieldName = name.substring(0,1).toLowerCase() + name.substring(1);
TypeElement typeElement = (TypeElement) getter.getEnclosingElement();
for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (variableElement.getSimpleName().contentEquals(guessFieldName)) {
return variableElement;
}
}
Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.WARNING, "Cannot detect the field associated with property: {0}", guessFieldName);
return null;
}
示例8: guessGetter
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
/**
* TODO: actually it's guess setter from setter, need to review if it's a problem of expected
* @param setter
* @return
*/
public static VariableElement guessGetter(ExecutableElement setter) {
String name = setter.getSimpleName().toString().substring(3);
String guessGetterName = "set" + name;
TypeElement typeElement = (TypeElement) setter.getEnclosingElement();
for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (variableElement.getSimpleName().contentEquals(guessGetterName)) {
return variableElement;
}
}
Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.INFO, "Cannot detect setter associated with getter: {0}", guessGetterName);
return null;
}
示例9: doTwoWordFields
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz,
int offset, String cname, boolean padWord) {
boolean first = true;
List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
for (VariableElement field: fields) {
TypeKind tk = field.asType().getKind();
boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE);
if (twoWords && doField(res, field, cname, first && padWord)) {
offset += 8; first = false;
}
}
return offset;
}
示例10: isLegalSei
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
protected boolean isLegalSei(TypeElement interfaceElement) {
for (VariableElement field : ElementFilter.fieldsIn(interfaceElement.getEnclosedElements()))
if (field.getConstantValue() != null) {
builder.processError(WebserviceapMessages.WEBSERVICEAP_SEI_CANNOT_CONTAIN_CONSTANT_VALUES(
interfaceElement.getQualifiedName(), field.getSimpleName()));
return false;
}
return methodsAreLegal(interfaceElement);
}
示例11: write
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
protected void write(OutputStream o, TypeElement clazz) throws Util.Exit {
try {
String cname = mangleClassName(clazz.getQualifiedName().toString());
PrintWriter pw = wrapWriter(o);
fields = ElementFilter.fieldsIn(clazz.getEnclosedElements());
methods = ElementFilter.methodsIn(clazz.getEnclosedElements());
generateDeclsForClass(pw, clazz, cname);
// FIXME check if errors occurred on the PrintWriter and throw exception if so
} catch (TypeSignature.SignatureException e) {
util.error("llni.sigerror", e.getMessage());
}
}
示例12: getValueMember
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public static VariableElement getValueMember(TypeElement type) {
VariableElement member = null;
for (VariableElement field : ElementFilter.fieldsIn(type.getEnclosedElements())) {
if ("value".equals(field.getSimpleName().toString())) {
member = field;
break;
}
}
if (member == null && type.getKind().equals(ElementKind.CLASS))
member = getValueMember(type.getSuperclass());
return member;
}
示例13: getPropertyChangeSupport
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
private VariableTree getPropertyChangeSupport(javax.lang.model.element.TypeElement node, String support) {
TypeElement supportElement = workingCopy.getElements().getTypeElement(support);
if(supportElement != null) {
for (VariableElement el : ElementFilter.fieldsIn(node.getEnclosedElements())) {
if (el.asType().equals(supportElement.asType())) {
return (VariableTree) workingCopy.getTrees().getPath(el).getLeaf();
}
}
}
return null;
}
示例14: getDeclaredField
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
public VariableElement getDeclaredField(TypeElement clazz, String fieldName) {
for (VariableElement fd : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
if (fd.getSimpleName().toString().equals(fieldName))
return fd;
}
return null;
}
示例15: complete
import javax.lang.model.util.ElementFilter; //導入方法依賴的package包/類
@Override
public List<CompletionItem> complete() {
// get type of the enclosing instance
FxInstance inst = (FxInstance)ctx.getElementParent();
TypeElement instType = inst.getJavaType().resolve(ctx.getCompilationInfo());
TypeElement ct = controllerType.resolve(ctx.getCompilationInfo());
if (ct == null) {
return null;
}
List<CompletionItem> items = new ArrayList<CompletionItem>();
for (VariableElement v : ElementFilter.fieldsIn(
ctx.getCompilationInfo().getElements().getAllMembers(ct))) {
if (!FxClassUtils.isFxmlAccessible(v)) {
continue;
}
// do not suggest a variable, whose ID is used elsewhere:
String sn = v.getSimpleName().toString();
if (ctx.getModel().getInstance(sn) != null) {
continue;
}
// check that the instance is assignable to the var
if (ctx.getCompilationInfo().getTypes().isAssignable(instType.asType(), v.asType())) {
ValueItem vi = new ValueItem(
ctx,
v.getSimpleName().toString(),
ICON_RESOURCE
);
vi.setAttribute(ctx.getType() == CompletionContext.Type.PROPERTY_VALUE);
items.add(vi);
}
}
return items;
}