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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.bridge.IMessage;
  21. public class CompilerMessagesTests extends AjdeCoreTestCase {
  22. private TestMessageHandler handler;
  23. private TestCompilerConfiguration compilerConfig;
  24. private String[] files = { "apackage" + File.separator + "InitCatcher.java",
  25. "apackage" + File.separator + "SomeClass.java" };
  26. protected void setUp() throws Exception {
  27. super.setUp();
  28. initialiseProject("declare-warning");
  29. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  30. compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
  31. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  32. doBuild(true);
  33. }
  34. protected void tearDown() throws Exception {
  35. super.tearDown();
  36. handler = null;
  37. compilerConfig = null;
  38. }
  39. public void testMessages() {
  40. // bug 33474
  41. // The build has happened, what messages did the compiler give, and do they
  42. // contain the information we expect?
  43. List msgs = handler.getMessages();
  44. if (2 != msgs.size()) {
  45. assertTrue("not two messages: " + msgs, false);
  46. }
  47. assertEquals("Two warning messages should be produced",2,msgs.size());
  48. TestMessageHandler.TestMessage msg =
  49. (TestMessageHandler.TestMessage) msgs.get(0);
  50. assertEquals( 8, msg.getContainedMessage().getSourceLocation().getLine());
  51. assertEquals( "Please don't call init methods", msg.getContainedMessage().getMessage());
  52. try {
  53. String fullyQualifiedFile = msg.getContainedMessage().getSourceLocation().getSourceFile().getCanonicalPath();
  54. // this name has a tester specific prefix, followed by the location of the file.
  55. // we can validate the ending.
  56. fullyQualifiedFile = fullyQualifiedFile.replace('\\','/'); // ignore platform differences in slashes
  57. assertTrue( "Fully-qualified source file location returned",
  58. fullyQualifiedFile.endsWith("/declare-warning/apackage/SomeClass.java"));
  59. } catch (IOException ex) {
  60. assertTrue( "Unable to convert source file location: " + msg.getContainedMessage().getSourceLocation().getSourceFile(), false);
  61. }
  62. }
  63. public void testDeclareMessageContents() {
  64. List msgs = handler.getMessages();
  65. IMessage msg = ((TestMessageHandler.TestMessage)msgs.get(1)).getContainedMessage();
  66. assertEquals( "Please don't call setters" , msg.getMessage());
  67. assertEquals("field-set(int apackage.SomeClass.x)", msg.getDetails());
  68. }
  69. }