Java Code Examples for javax.lang.model.util.ElementFilter#fieldsIn()
The following examples show how to use
javax.lang.model.util.ElementFilter#fieldsIn() .
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 File: UseDatabaseGeneratorTest.java From netbeans with Apache License 2.0 | 6 votes |
private static void checkDatasourceField(TypeElement typeElement, String name) { List<VariableElement> elements = ElementFilter.fieldsIn(typeElement.getEnclosedElements()); VariableElement variableElement = elements.get(0); assertTrue(variableElement.getSimpleName().contentEquals(name)); // field name DeclaredType declaredType = (DeclaredType) variableElement.asType(); TypeElement returnTypeElement = (TypeElement) declaredType.asElement(); assertTrue(returnTypeElement.getQualifiedName().contentEquals("javax.sql.DataSource")); // field type AnnotationMirror annotationMirror = variableElement.getAnnotationMirrors().get(0); DeclaredType annotationDeclaredType = annotationMirror.getAnnotationType(); TypeElement annotationTypeElement = (TypeElement) annotationDeclaredType.asElement(); assertTrue(annotationTypeElement.getQualifiedName().contentEquals("javax.annotation.Resource")); // annotation type Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry = annotationMirror.getElementValues().entrySet().iterator().next(); String attributeName = entry.getKey().getSimpleName().toString(); String attributeValue = (String) entry.getValue().getValue(); assertEquals("name", attributeName); // attributes assertEquals(name, attributeValue); }
Example 2
Source File: ScopedBeanAnalyzer.java From netbeans with Apache License 2.0 | 6 votes |
private void checkPublicField( TypeElement scopeElement, Element element, WebBeansModel model, Result result ) { if ( AnnotationUtil.DEPENDENT.contentEquals( scopeElement.getQualifiedName())) { return; } result.requireCdiEnabled(element, model); List<VariableElement> fields = ElementFilter.fieldsIn( element.getEnclosedElements()); for (VariableElement field : fields) { Set<Modifier> modifiers = field.getModifiers(); if ( modifiers.contains(Modifier.PUBLIC ) && (!modifiers.contains(Modifier.STATIC) || !model.isCdi11OrLater())){ result.addError(element, model , NbBundle.getMessage(ScopedBeanAnalyzer.class, "ERR_IcorrectScopeWithPublicField", field.getSimpleName().toString())); return; } } }
Example 3
Source File: RetroFacebookProcessor.java From RetroFacebook with Apache License 2.0 | 6 votes |
private String getSerialVersionUID(TypeElement type) { Types typeUtils = processingEnv.getTypeUtils(); TypeMirror serializable = getTypeMirror(Serializable.class); if (typeUtils.isAssignable(type.asType(), serializable)) { List<VariableElement> fields = ElementFilter.fieldsIn(type.getEnclosedElements()); for (VariableElement field : fields) { if (field.getSimpleName().toString().equals("serialVersionUID")) { Object value = field.getConstantValue(); if (field.getModifiers().containsAll(Arrays.asList(Modifier.STATIC, Modifier.FINAL)) && field.asType().getKind() == TypeKind.LONG && value != null) { return value + "L"; } else { errorReporter.reportError( "serialVersionUID must be a static final long compile-time constant", field); break; } } } } return ""; }
Example 4
Source File: GeneratorUtilitiesTest.java From netbeans with Apache License 2.0 | 6 votes |
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); }
Example 5
Source File: TypeSimplifierTest.java From SimpleWeibo with Apache License 2.0 | 6 votes |
public void testIsCastingUnchecked() { TypeElement erasureClass = typeElementOf("Erasure"); List<VariableElement> fields = ElementFilter.fieldsIn(erasureClass.getEnclosedElements()); for (VariableElement field : fields) { String fieldName = field.getSimpleName().toString(); boolean expectUnchecked; if (fieldName.endsWith("Yes")) { expectUnchecked = true; } else if (fieldName.endsWith("No")) { expectUnchecked = false; } else { throw new AssertionError("Fields in Erasure class must end with Yes or No: " + fieldName); } TypeMirror fieldType = field.asType(); boolean actualUnchecked = TypeSimplifier.isCastingUnchecked(fieldType); assertEquals("Unchecked-cast status for " + fieldType, expectUnchecked, actualUnchecked); } }
Example 6
Source File: JavaSourceParserUtil.java From jeddict with Apache License 2.0 | 5 votes |
/** * #5977 FIX fixed serialVersionUID in output reversed model (class) * * @author georgeeb <[email protected]> * @since Thu, 17 Apr 2014 15:04:13 +0000 */ public static List<VariableElement> getFields(TypeElement typeElement) { if(typeElement==null){ return Collections.<VariableElement>emptyList(); } List<VariableElement> result = new LinkedList<>(); final List<VariableElement> fieldsIn = ElementFilter.fieldsIn(typeElement.getEnclosedElements()); result.addAll(removeSerialVersionUid(fieldsIn)); return result; }
Example 7
Source File: WebServiceVisitor.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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); }
Example 8
Source File: EntityClassInfo.java From netbeans with Apache License 2.0 | 5 votes |
protected void extractFields(DeclaredType originalEntity, TypeElement typeElement, CompilationController controller) { List<VariableElement> fields = ElementFilter.fieldsIn(typeElement.getEnclosedElements()); for (VariableElement field : fields) { Set<Modifier> modifiers = field.getModifiers(); if (modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.TRANSIENT) || modifiers.contains(Modifier.VOLATILE) || modifiers.contains(Modifier.FINAL)) { continue; } FieldInfo fieldInfo = new FieldInfo(); fieldInfo.parseAnnotations(field.getAnnotationMirrors()); if (!fieldInfo.isPersistent()) { continue; } fieldInfos.add(fieldInfo); fieldInfo.setName(field.getSimpleName().toString()); fieldInfo.setType(controller.getTypes(). asMemberOf(originalEntity, field), controller); if (fieldInfo.isId() && idFieldInfo == null ) { idFieldInfo = fieldInfo; } } TypeElement superClass = getJPASuperClass(typeElement, controller); if ( superClass == null ){ return; } extractFields(originalEntity , superClass , controller ); }
Example 9
Source File: ApNavigator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public VariableElement getDeclaredField(TypeElement clazz, String fieldName) { for (VariableElement fd : ElementFilter.fieldsIn(clazz.getEnclosedElements())) { if (fd.getSimpleName().toString().equals(fieldName)) return fd; } return null; }
Example 10
Source File: TypeModeler.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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; }
Example 11
Source File: TypeModeler.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example 12
Source File: MoreTypesTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void testIsConversionFromObjectUnchecked_no() { Elements elements = compilationRule.getElements(); TypeElement notUnchecked = elements.getTypeElement(NotUnchecked.class.getCanonicalName()); for (VariableElement field : ElementFilter.fieldsIn(notUnchecked.getEnclosedElements())) { TypeMirror type = field.asType(); expect .withMessage("Casting to %s is not unchecked", type) .that(MoreTypes.isConversionFromObjectUnchecked(type)) .isFalse(); } }
Example 13
Source File: MoreElementsTest.java From auto with Apache License 2.0 | 4 votes |
@Test public void asVariable() { for (Element variableElement : ElementFilter.fieldsIn(stringElement.getEnclosedElements())) { assertThat(MoreElements.asVariable(variableElement)).isEqualTo(variableElement); } }
Example 14
Source File: EncapsulateFieldUI.java From netbeans with Apache License 2.0 | 4 votes |
@Override public RefactoringUI create(CompilationInfo info, TreePathHandle[] handles, FileObject[] files, NonRecursiveFolder[] packages) { EditorCookie ec = lookup.lookup(EditorCookie.class); if (ec == null) { return create(info, -1, handles); } JEditorPane textC = NbDocument.findRecentEditorPane(ec); if (textC == null) { return create(info, -1, handles); } int startOffset = textC.getSelectionStart(); int endOffset = textC.getSelectionEnd(); if (startOffset == endOffset) { //cursor position return create(info, startOffset, handles[0]); } //editor selection TreePath path = info.getTreeUtilities().pathFor(startOffset); if (path == null) { return null; } TreePath enclosingClass = JavaRefactoringUtils.findEnclosingClass(info, path, true, true, true, true, true); if (enclosingClass == null) { return null; } Element el = info.getTrees().getElement(enclosingClass); if (el == null) { return null; } if (!(el.getKind().isClass() || el.getKind().isInterface())) { el = info.getElementUtilities().enclosingTypeElement(el); } Collection<TreePathHandle> h = new ArrayList<TreePathHandle>(); for (Element e : ElementFilter.fieldsIn(el.getEnclosedElements())) { // SourcePositions sourcePositions = info.getTrees().getSourcePositions(); Tree leaf = info.getTrees().getPath(e).getLeaf(); int[] namespan = info.getTreeUtilities().findNameSpan((VariableTree) leaf); if (namespan != null) { long start = namespan[0]; //sourcePositions.getStartPosition(info.getCompilationUnit(), leaf); long end = namespan[1]; //sourcePositions.getEndPosition(info.getCompilationUnit(), leaf); if ((start <= endOffset && start >= startOffset) || (end <= endOffset && end >= startOffset)) { h.add(TreePathHandle.create(e, info)); } } } if (h.isEmpty()) { return create(info, startOffset, handles[0]); } return create(info, -1, h.toArray(new TreePathHandle[h.size()])); }
Example 15
Source File: LLNI.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
FieldDefsRes fieldDefs(TypeElement clazz, String cname, boolean bottomMost){ FieldDefsRes res; int offset; boolean didTwoWordFields = false; TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass()); if (superclazz != null) { String supername = superclazz.getQualifiedName().toString(); res = new FieldDefsRes(clazz, fieldDefs(superclazz, cname, false), bottomMost); offset = res.parent.byteSize; } else { res = new FieldDefsRes(clazz, null, bottomMost); offset = 0; } List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) { offset = doTwoWordFields(res, clazz, offset, cname, false); didTwoWordFields = true; } TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (!doubleAlign || !twoWords) { if (doField(res, field, cname, false)) offset += 4; } } if (doubleAlign && !didTwoWordFields) { if ((offset % 8) != 0) offset += 4; offset = doTwoWordFields(res, clazz, offset, cname, true); } res.byteSize = offset; return res; }
Example 16
Source File: RefactoringUtils.java From netbeans with Apache License 2.0 | 4 votes |
/** * * @param e * @param info * @param cancel * @return * @deprecated */ @Deprecated public static Collection<ExecutableElement> getOverridingMethods(ExecutableElement e, CompilationInfo info, AtomicBoolean cancel) { Collection<ExecutableElement> result = new ArrayList(); TypeElement parentType = (TypeElement) e.getEnclosingElement(); Set<ElementHandle<TypeElement>> subTypes = getImplementorsAsHandles(info.getClasspathInfo().getClassIndex(), info.getClasspathInfo(), parentType, cancel); for (ElementHandle<TypeElement> subTypeHandle : subTypes) { TypeElement type = subTypeHandle.resolve(info); if (type == null) { // #214462: removed logging, logs show coupling errors continue; // #120577: log info to find out what is going wrong // FileObject file = SourceUtils.getFile(subTypeHandle, info.getClasspathInfo()); // if (file == null) { // //Deleted file // continue; // } else { // throw new NullPointerException("#120577: Cannot resolve " + subTypeHandle + "; file: " + file + " Classpath: " + info.getClasspathInfo()); // } } List<ExecutableElement> methods = new LinkedList<>(ElementFilter.methodsIn(type.getEnclosedElements())); // #253063 - Anonymous classes of enum constants are not returned by index, need to get them manually if(type.getKind() == ElementKind.ENUM) { for (VariableElement variableElement : ElementFilter.fieldsIn(type.getEnclosedElements())) { TreePath varPath = info.getTrees().getPath(variableElement); if(varPath != null && varPath.getLeaf().getKind() == Tree.Kind.VARIABLE) { ExpressionTree initializer = ((VariableTree)varPath.getLeaf()).getInitializer(); if(initializer != null && initializer.getKind() == Tree.Kind.NEW_CLASS) { NewClassTree ncTree = (NewClassTree) initializer; ClassTree classBody = ncTree.getClassBody(); if(classBody != null) { Element anonEl = info.getTrees().getElement(new TreePath(varPath, classBody)); if(anonEl != null) { methods.addAll(ElementFilter.methodsIn(anonEl.getEnclosedElements())); } } } } } } for (ExecutableElement method : methods) { if (info.getElements().overrides(method, e, type)) { result.add(method); } } } return result; }
Example 17
Source File: FieldForUnusedParam.java From netbeans with Apache License 2.0 | 4 votes |
List<ErrorDescription> run(final CompilationInfo info, TreePath treePath, int offset) { cancel.set(false); if (!getTreeKinds().contains(treePath.getLeaf().getKind())) { return null; } if (treePath.getParentPath() == null || treePath.getParentPath().getLeaf().getKind() != Kind.METHOD) { return null; } final Element el = info.getTrees().getElement(treePath); if (el == null || el.getKind() != ElementKind.PARAMETER) { return null; } MethodTree parent = (MethodTree) treePath.getParentPath().getLeaf(); Element parentEl = info.getTrees().getElement(treePath.getParentPath()); if (parentEl == null || parentEl.getKind() != ElementKind.CONSTRUCTOR || parent.getBody() == null) { return null; } VariableTree var = (VariableTree) treePath.getLeaf(); if (var.getName().contentEquals(ERROR)) return null; boolean existing = false; for (VariableElement field : ElementFilter.fieldsIn(parentEl.getEnclosingElement().getEnclosedElements())) { if (cancel.get()) { return null; } if (field.getSimpleName().equals(el.getSimpleName())) { if (!info.getTypes().isAssignable(field.asType(), el.asType())) { return null; } existing = true; break; } } @SuppressWarnings("serial") class Result extends RuntimeException { @Override public synchronized Throwable fillInStackTrace() { return this; } } boolean found = false; try { new CancellableTreePathScanner<Void, Void>(cancel) { @Override public Void visitIdentifier(IdentifierTree node, Void p) { Element e = info.getTrees().getElement(getCurrentPath()); if (el.equals(e)) { throw new Result(); } return super.visitIdentifier(node, p); } }.scan(new TreePath(treePath.getParentPath(), parent.getBody()), null); } catch (Result r) { found = true; } if (cancel.get() || found) { return null; } final VariableTree vt = (VariableTree) treePath.getLeaf(); final String name = vt.getName().toString(); List<Fix> fix = Collections.<Fix>singletonList(new FixImpl(info.getJavaSource(), TreePathHandle.create(treePath, info), isFinalFields(getPreferences(null)), existing, name)); String displayName = NbBundle.getMessage(FieldForUnusedParam.class, "ERR_UnusedParameter", name); ErrorDescription err = ErrorDescriptionFactory.createErrorDescription(Severity.HINT, displayName, fix, info.getFileObject(), offset, offset); return Collections.singletonList(err); }
Example 18
Source File: Analysis.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable private String jsonObjectReaderPath(Element el, boolean includeErrors) { if (!(el instanceof TypeElement)) return null; TypeElement element = (TypeElement)el; boolean isJsonObject = false; for (TypeMirror type : element.getInterfaces()) { if (JsonObject.class.getName().equals(type.toString())) { isJsonObject = true; break; } } if (!isJsonObject) return null; VariableElement jsonReaderField = null; ExecutableElement jsonReaderMethod = null; Element companion = null; for (VariableElement field : ElementFilter.fieldsIn(el.getEnclosedElements())) { //Kotlin uses Companion field with static get method if ("Companion".equals(field.getSimpleName().toString())) { if (field.asType().toString().equals(el.asType().toString() + ".Companion") && field.getModifiers().contains(Modifier.STATIC) && field.getModifiers().contains(Modifier.PUBLIC) && field.getModifiers().contains(Modifier.FINAL)) { companion = types.asElement(field.asType()); } } else if ("JSON_READER".equals(field.getSimpleName().toString())) { jsonReaderField = field; } } String signatureType = "com.dslplatform.json.JsonReader.ReadJsonObject<" + element.getQualifiedName() + ">"; if (!onlyBasicFeatures && companion != null && companion.getModifiers().contains(Modifier.STATIC)) { for (ExecutableElement method : ElementFilter.methodsIn(companion.getEnclosedElements())) { if ("JSON_READER".equals(method.getSimpleName().toString()) || "getJSON_READER".equals(method.getSimpleName().toString())) { jsonReaderMethod = method; } } } String used = jsonReaderMethod != null ? jsonReaderMethod.getSimpleName() + " method" : "JSON_READER field"; if (includeErrors) { if (!el.getModifiers().contains(Modifier.PUBLIC)) { hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but it's not public. " + "Make it public so it can be used for serialization/deserialization.", el, getAnnotation(el, converterType)); } else if (element.getNestingKind().isNested() && !el.getModifiers().contains(Modifier.STATIC)) { hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but it cant be non static nested member. " + "Add static modifier so it can be used for serialization/deserialization.", el, getAnnotation(el, converterType)); } else if (onlyBasicFeatures && (element.getQualifiedName().contentEquals(element.getSimpleName()) || element.getNestingKind().isNested() && element.getModifiers().contains(Modifier.STATIC) && element.getEnclosingElement() instanceof TypeElement && ((TypeElement) element.getEnclosingElement()).getQualifiedName().contentEquals(element.getEnclosingElement().getSimpleName()))) { hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but its defined without a package name and cannot be accessed. " + "Either add package to it or use a different analysis configuration which support classes without packages.", element, getAnnotation(element, converterType)); } else if (jsonReaderField == null && jsonReaderMethod == null) { String allowed = onlyBasicFeatures ? "field" : "field/method"; hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but it doesn't have JSON_READER " + allowed + ". " + "It can't be used for serialization/deserialization this way. " + "You probably want to add public static JSON_READER " + allowed + ".", element, getAnnotation(element, converterType)); } else if (jsonReaderMethod == null && (!jsonReaderField.getModifiers().contains(Modifier.PUBLIC) || !jsonReaderField.getModifiers().contains(Modifier.STATIC)) || jsonReaderMethod != null && (!jsonReaderMethod.getModifiers().contains(Modifier.PUBLIC) || jsonReaderMethod.getModifiers().contains(Modifier.STATIC))) { hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but its " + used + " is not public and static. " + "It can't be used for serialization/deserialization this way. " + "You probably want to change " + used + " so it's public and static.", element, getAnnotation(element, converterType)); } else if (jsonReaderField != null && !signatureType.equals(jsonReaderField.asType().toString()) || jsonReaderMethod != null && !signatureType.equals(jsonReaderMethod.getReturnType().toString())) { hasError = true; messager.printMessage( Diagnostic.Kind.ERROR, "'" + element.getQualifiedName() + "' is 'com.dslplatform.json.JsonObject', but its " + used + " is not of correct type. " + "It can't be used for serialization/deserialization this way. " + "You probably want to change " + used + " to: '" + signatureType + "'", element, getAnnotation(element, converterType)); } } String prefix = companion == null ? "" : "Companion."; return prefix + (jsonReaderMethod != null ? jsonReaderMethod.getSimpleName().toString() + "()" : "JSON_READER"); }
Example 19
Source File: LLNI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
FieldDefsRes fieldDefs(TypeElement clazz, String cname, boolean bottomMost){ FieldDefsRes res; int offset; boolean didTwoWordFields = false; TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass()); if (superclazz != null) { String supername = superclazz.getQualifiedName().toString(); res = new FieldDefsRes(clazz, fieldDefs(superclazz, cname, false), bottomMost); offset = res.parent.byteSize; } else { res = new FieldDefsRes(clazz, null, bottomMost); offset = 0; } List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) { offset = doTwoWordFields(res, clazz, offset, cname, false); didTwoWordFields = true; } TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (!doubleAlign || !twoWords) { if (doField(res, field, cname, false)) offset += 4; } } if (doubleAlign && !didTwoWordFields) { if ((offset % 8) != 0) offset += 4; offset = doTwoWordFields(res, clazz, offset, cname, true); } res.byteSize = offset; return res; }
Example 20
Source File: LLNI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
FieldDefsRes fieldDefs(TypeElement clazz, String cname, boolean bottomMost){ FieldDefsRes res; int offset; boolean didTwoWordFields = false; TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass()); if (superclazz != null) { String supername = superclazz.getQualifiedName().toString(); res = new FieldDefsRes(clazz, fieldDefs(superclazz, cname, false), bottomMost); offset = res.parent.byteSize; } else { res = new FieldDefsRes(clazz, null, bottomMost); offset = 0; } List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) { offset = doTwoWordFields(res, clazz, offset, cname, false); didTwoWordFields = true; } TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (!doubleAlign || !twoWords) { if (doField(res, field, cname, false)) offset += 4; } } if (doubleAlign && !didTwoWordFields) { if ((offset % 8) != 0) offset += 4; offset = doTwoWordFields(res, clazz, offset, cname, true); } res.byteSize = offset; return res; }