/eclipse-plugin/plugins/com.google.test.metric.eclipse.core/src/main/java/com/google/test/metric/eclipse/internal/util/TestabilityExplorerMessageRetriever.java

http://testability-explorer.googlecode.com/ · Java · 52 lines · 25 code · 7 blank · 20 comment · 0 complexity · 8f7ca31567ad0a006bcf32f56efd1011 MD5 · raw file

  1. /*
  2. * Copyright 2009 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric.eclipse.internal.util;
  17. import com.google.test.metric.report.issues.IssueSubType;
  18. import com.google.test.metric.report.issues.IssueType;
  19. import java.io.IOException;
  20. import java.util.Properties;
  21. /**
  22. * Helper class which retrieves the suggestions for various issues and their subtypes
  23. * from the Testability Explorer messages bundle.
  24. * @author shyamseshadri@google.com (Shyam Seshadri)
  25. */
  26. public class TestabilityExplorerMessageRetriever {
  27. private final Logger logger = new Logger();
  28. private final Properties properties = new Properties();
  29. public static final String PROPERTY_PREFIX = "report.explain.class.";
  30. public static final String PROPERTY_SUFFIX = ".suggest";
  31. public TestabilityExplorerMessageRetriever() {
  32. try {
  33. properties.load(getClass().getResourceAsStream("/messages.properties"));
  34. } catch (IOException e) {
  35. logger.logException(e);
  36. }
  37. }
  38. public String convertTypeSubTypeToString(IssueType type, IssueSubType subType) {
  39. return type.toString().replace("_", "").toLowerCase() + "." + subType.toString().toLowerCase();
  40. }
  41. public String getSuggestion(IssueType type, IssueSubType subType) {
  42. return properties.getProperty(PROPERTY_PREFIX + convertTypeSubTypeToString(type, subType)
  43. + PROPERTY_SUFFIX);
  44. }
  45. }