You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompilerMessagesTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* *******************************************************************
  2. * Copyright (c) 2003 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * AMC 2003 initial version
  11. * ******************************************************************/
  12. package org.aspectj.ajde;
  13. import java.io.IOException;
  14. import java.util.List;
  15. import org.aspectj.bridge.*;
  16. import org.aspectj.bridge.IMessage;
  17. /**
  18. * @author colyer
  19. *
  20. * To change this generated comment go to
  21. * Window>Preferences>Java>Code Generation>Code and Comments
  22. */
  23. public class CompilerMessagesTest extends AjdeTestCase {
  24. private final String CONFIG_FILE_PATH = "../examples/declare-warning/all.lst";
  25. public CompilerMessagesTest(String name) {
  26. super(name);
  27. }
  28. public void testMessages() {
  29. // bug 33474
  30. // The build has happened, what messages did the compiler give, and do they
  31. // contain the information we expect?
  32. List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  33. if (2 != msgs.size()) {
  34. assertTrue("not two messages: " + msgs, false);
  35. }
  36. assertEquals("Two warning messages should be produced",2,msgs.size());
  37. NullIdeTaskListManager.SourceLineTask task =
  38. (NullIdeTaskListManager.SourceLineTask) msgs.get(0);
  39. assertEquals( 8, task.getContainedMessage().getSourceLocation().getLine());
  40. assertEquals( "Please don't call init methods", task.message.getMessage());
  41. try {
  42. String fullyQualifiedFile = task.getContainedMessage().getSourceLocation().getSourceFile().getCanonicalPath();
  43. // this name has a tester specific prefix, followed by the location of the file.
  44. // we can validate the ending.
  45. fullyQualifiedFile = fullyQualifiedFile.replace('\\','/'); // ignore platform differences in slashes
  46. assertTrue( "Fully-qualified source file location returned",
  47. fullyQualifiedFile.endsWith("/examples/declare-warning/apackage/SomeClass.java"));
  48. } catch (IOException ex) {
  49. assertTrue( "Unable to convert source file location: " + task.getContainedMessage().getSourceLocation().getSourceFile(), false);
  50. }
  51. }
  52. public void testDeclareMessageContents() {
  53. List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  54. IMessage msg = (IMessage)((NullIdeTaskListManager.SourceLineTask)msgs.get(1)).getContainedMessage();
  55. assertEquals( "Please don't call setters" , msg.getMessage());
  56. assertEquals("field-set(int apackage.SomeClass.x)", msg.getDetails());
  57. }
  58. /*
  59. * @see TestCase#setUp()
  60. */
  61. protected void setUp() throws Exception {
  62. super.setUp("examples");
  63. doSynchronousBuild(CONFIG_FILE_PATH);
  64. }
  65. /*
  66. * @see AjdeTestCase#tearDown()
  67. */
  68. protected void tearDown() throws Exception {
  69. super.tearDown();
  70. }
  71. }