PageRenderTime 35ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/worldguard-legacy/src/main/java/com/sk89q/worldguard/util/report/ShallowObjectReport.java

https://gitlab.com/igserfurtmcschulserver/CustomWorldGuard
Java | 58 lines | 29 code | 11 blank | 18 comment | 4 complexity | b5954d2d7e934adf418e271386cd653e MD5 | raw file
  1. /*
  2. * WorldGuard, a suite of tools for Minecraft
  3. * Copyright (C) sk89q <http://www.sk89q.com>
  4. * Copyright (C) WorldGuard team and contributors
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.sk89q.worldguard.util.report;
  20. import java.lang.reflect.Field;
  21. import java.lang.reflect.Modifier;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import static com.google.common.base.Preconditions.checkNotNull;
  25. public class ShallowObjectReport extends DataReport {
  26. private static final Logger log = Logger.getLogger(ShallowObjectReport.class.getCanonicalName());
  27. public ShallowObjectReport(String title, Object object) {
  28. super(title);
  29. checkNotNull(object, "object");
  30. Class<?> type = object.getClass();
  31. for (Field field : type.getDeclaredFields()) {
  32. if (Modifier.isStatic(field.getModifiers())) {
  33. continue;
  34. }
  35. if (field.getAnnotation(Unreported.class) != null) {
  36. continue;
  37. }
  38. field.setAccessible(true);
  39. try {
  40. Object value = field.get(object);
  41. append(field.getName(), String.valueOf(value));
  42. } catch (IllegalAccessException e) {
  43. log.log(Level.WARNING, "Failed to get value of '" + field.getName() + "' on " + type);
  44. }
  45. }
  46. }
  47. }