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.

CompilerMessagesTests.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * AMC 2003 initial version
  11. * Helen Hawkins Converted to new interface (bug 148190)
  12. * ******************************************************************/
  13. package org.aspectj.ajde.core.tests;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import java.util.List;
  17. import org.aspectj.ajde.core.AjdeCoreTestCase;
  18. import org.aspectj.ajde.core.TestCompilerConfiguration;
  19. import org.aspectj.ajde.core.TestMessageHandler;
  20. import org.aspectj.ajde.core.TestMessageHandler.TestMessage;
  21. import org.aspectj.bridge.IMessage;
  22. public class CompilerMessagesTests extends AjdeCoreTestCase {
  23. private TestMessageHandler handler;
  24. private TestCompilerConfiguration compilerConfig;
  25. private String[] files = { "apackage" + File.separator + "InitCatcher.java",
  26. "apackage" + File.separator + "SomeClass.java" };
  27. protected void setUp() throws Exception {
  28. super.setUp();
  29. initialiseProject("declare-warning");
  30. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  31. compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
  32. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  33. doBuild(true);
  34. }
  35. protected void tearDown() throws Exception {
  36. super.tearDown();
  37. handler = null;
  38. compilerConfig = null;
  39. }
  40. public void testMessages() {
  41. // bug 33474
  42. // The build has happened, what messages did the compiler give, and do they
  43. // contain the information we expect?
  44. List<TestMessage> msgs = handler.getMessages();
  45. if (2 != msgs.size()) {
  46. assertTrue("not two messages: " + msgs, false);
  47. }
  48. assertEquals("Two warning messages should be produced",2,msgs.size());
  49. TestMessageHandler.TestMessage msg =
  50. (TestMessageHandler.TestMessage) msgs.get(0);
  51. assertEquals( 8, msg.getContainedMessage().getSourceLocation().getLine());
  52. assertEquals( "Please don't call init methods", msg.getContainedMessage().getMessage());
  53. try {
  54. String fullyQualifiedFile = msg.getContainedMessage().getSourceLocation().getSourceFile().getCanonicalPath();
  55. // this name has a tester specific prefix, followed by the location of the file.
  56. // we can validate the ending.
  57. fullyQualifiedFile = fullyQualifiedFile.replace('\\','/'); // ignore platform differences in slashes
  58. assertTrue( "Fully-qualified source file location returned",
  59. fullyQualifiedFile.endsWith("/declare-warning/apackage/SomeClass.java"));
  60. } catch (IOException ex) {
  61. assertTrue( "Unable to convert source file location: " + msg.getContainedMessage().getSourceLocation().getSourceFile(), false);
  62. }
  63. }
  64. public void testDeclareMessageContents() {
  65. List<TestMessage> msgs = handler.getMessages();
  66. IMessage msg = ((TestMessageHandler.TestMessage)msgs.get(1)).getContainedMessage();
  67. assertEquals( "Please don't call setters" , msg.getMessage());
  68. assertEquals("field-set(int apackage.SomeClass.x)", msg.getDetails());
  69. }
  70. }