@@ -0,0 +1,71 @@ | |||
/******************************************************************** | |||
* Copyright (c) 2006 Contributors. All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: IBM Corporation - initial API and implementation | |||
* Helen Hawkins - moved into separate class | |||
*******************************************************************/ | |||
package org.aspectj.ajde.internal; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.aspectj.ajde.Ajde; | |||
import org.aspectj.ajde.TaskListManager; | |||
import org.aspectj.bridge.AbortException; | |||
import org.aspectj.bridge.IMessage; | |||
import org.aspectj.bridge.IMessageHandler; | |||
import org.aspectj.bridge.IMessage.Kind; | |||
/** | |||
* IMessageHandler used by Ajde. No messages are stored | |||
* within the handler as it delegates to the TaskListManager. | |||
* By default IMessage.INFO and IMessage.WEAVEINFO messages | |||
* are ignored. | |||
*/ | |||
public class AjdeMessageHandler implements IMessageHandler { | |||
private TaskListManager taskListManager; | |||
private List ignoring; | |||
public AjdeMessageHandler() { | |||
ignoring = new ArrayList(); | |||
ignore(IMessage.INFO); | |||
ignore(IMessage.WEAVEINFO); | |||
this.taskListManager = Ajde.getDefault().getTaskListManager(); | |||
} | |||
public boolean handleMessage(IMessage message) throws AbortException { | |||
IMessage.Kind kind = message.getKind(); | |||
if (kind == IMessage.ABORT) return handleAbort(message); | |||
if (isIgnoring(kind)) { | |||
return true; | |||
} | |||
taskListManager.addSourcelineTask(message); | |||
return true; | |||
} | |||
private boolean handleAbort(IMessage abortMessage) { | |||
throw new AbortException(abortMessage); | |||
} | |||
public void dontIgnore(Kind kind) { | |||
if (null != kind) { | |||
ignoring.remove(kind); | |||
} | |||
} | |||
public boolean isIgnoring(Kind kind) { | |||
return ((null != kind) && (ignoring.contains(kind))); | |||
} | |||
public void ignore(Kind kind) { | |||
if ((null != kind) && (!ignoring.contains(kind))) { | |||
ignoring.add(kind); | |||
} | |||
} | |||
} |
@@ -594,7 +594,7 @@ public class CompilerAdapter { | |||
if (Ajde.getDefault().getMessageHandler() != null) { | |||
this.messageHandler = Ajde.getDefault().getMessageHandler(); | |||
} else { | |||
this.messageHandler = new MessageHandlerAdapter(); | |||
this.messageHandler = new AjdeMessageHandler(); | |||
} | |||
buildManager = new AjBuildManager(messageHandler); | |||
buildManager.environmentSupportsIncrementalCompilation(true); | |||
@@ -603,30 +603,6 @@ public class CompilerAdapter { | |||
} | |||
} | |||
class MessageHandlerAdapter extends MessageHandler { | |||
private TaskListManager taskListManager; | |||
public MessageHandlerAdapter() { | |||
this.taskListManager = Ajde.getDefault().getTaskListManager(); | |||
ignore(IMessage.INFO); | |||
} | |||
public boolean handleMessage(IMessage message) throws AbortException { | |||
IMessage.Kind kind = message.getKind(); | |||
if (kind == IMessage.ABORT) return handleAbort(message); | |||
if (isIgnoring(kind)) { | |||
return true; | |||
} | |||
taskListManager.addSourcelineTask(message); | |||
return true;// return super.handleMessage(message); // also store... | |||
} | |||
private boolean handleAbort(IMessage abortMessage) { | |||
throw new AbortException(abortMessage); | |||
} | |||
} | |||
public void setState(AjState buildState) { | |||
buildManager.setState(buildState); | |||
buildManager.setStructureModel(buildState.getStructureModel()); |
@@ -1461,10 +1461,16 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa | |||
initialiseProject("PR141556"); | |||
build("PR141556"); | |||
IMessageHandler handler = AjdeManager.getMessageHandler(); | |||
assertTrue("expected the handler to be an IMessageHolder but wasn't ", | |||
// the handler used to be an IMessageHolder (extended MessageHandler) | |||
// which stored the messages, consequently we checked that none | |||
// were being stored. Since we no longer stored any messages (fix | |||
// for bug 141564) it was unnecessary to be an IMessageHolder as all the | |||
// IMessageHolder methods in MessageHander used the list of stored | |||
// messages. Therefore, rather than checking that the list of messages | |||
// is empty we can check that we're an IMessageHandler but not an | |||
// IMessageHolder. | |||
assertFalse("expected the handler not to be an IMessageHolder but was ", | |||
handler instanceof IMessageHolder); | |||
IMessage[] msgs = ((IMessageHolder)AjdeManager.getMessageHandler()).getMessages(null,true); | |||
assertTrue("There should be no messages but I found: "+msgs.length,msgs.length==0); | |||
List tasklistMessages = MyTaskListManager.getWarningMessages(); | |||
assertTrue("Should be one message but found "+tasklistMessages.size(),tasklistMessages.size()==1); |