FieldDeclarationWrapper(FieldDeclaration declaration) { this.declaration = declaration; if (declaration.getVariables().size() != 1) { throw new UnsupportedOperationException( "Not yet implemented: multiple variables in one field decl."); } }
@Override public void add(FieldInfo field) { FieldDeclaration fieldDeclaration; if (field instanceof FieldDeclarationWrapper) { val wrapper = (FieldDeclarationWrapper) field; fieldDeclaration = (FieldDeclaration) wrapper.declaration.clone(); fieldDeclaration.setAnnotations(Collections.emptyList()); changeTypeContext(wrapper.getContext(), getContext(), fieldDeclaration); } else { fieldDeclaration = new FieldDeclaration(); val vars = new ArrayList<VariableDeclarator>(); vars.add(new VariableDeclarator(new VariableDeclaratorId("unknown"))); fieldDeclaration.setVariables(vars); new FieldDeclarationWrapper(fieldDeclaration).setAll(field); } addMember(fieldDeclaration); val result = new FieldDeclarationWrapper(fieldDeclaration); if (!field.similar(result)) throw new TransformationException( "After adding to class, didn't match. added: " + field + " result: " + result); }
static void changeTypeContext(ResolutionContext old, ResolutionContext new_, FieldDeclaration f) { f.setType(changeTypeContext(old, new_, f.getType())); }
@Override public List<Annotation> getAnnotations() { return SourceInfo.this.getAnnotationsInternal(declaration.getAnnotations()); }
@Override public void setType(Type type) { declaration.setType(SourceInfo.this.setType(type, declaration.getType())); }
@Override public Type getType() { return getContext().resolve(declaration.getType()); }
@Override public void setAccessFlags(AccessFlags accessFlags) { declaration.setModifiers(accessFlags.access); }
@Override public AccessFlags getAccessFlags() { return new AccessFlags(declaration.getModifiers()); }
@Override public void setName(String name) { declaration.getVariables().get(0).getId().setName(name); }
@Override public String getName() { return declaration.getVariables().get(0).getId().getName(); }