/** * @return a map with the messages separated by type (keys are the type) * <p>the values are guaranteed to have size at least equal to 1 */ private Map<Integer, List<IMessage>> getMessagesByType(List<IMessage> l) { HashMap<Integer, List<IMessage>> messagesByType = new HashMap<Integer, List<IMessage>>(); for (IMessage message : l) { List<IMessage> messages = messagesByType.get(message.getType()); if (messages == null) { messages = new ArrayList<IMessage>(); messagesByType.put(message.getType(), messages); } messages.add(message); } return messagesByType; }
/** * @param result * @param message */ private void addToResult(List<IMessage> result, IMessage message) { if (isUnusedImportMessage(message.getType())) { IToken generator = message.getGenerator(); if (generator instanceof SourceToken) { String asAbsoluteImport = generator.getAsAbsoluteImport(); if (asAbsoluteImport.indexOf("__future__.") != -1 || asAbsoluteImport.indexOf("__metaclass__") != -1) { // do not add from __future__ import xxx return; } } } result.add(message); }
/** @return the generated messages. */ public List<IMessage> getMessages() { List<IMessage> result = new ArrayList<IMessage>(); // let's get the messages for (List<IMessage> l : messages.values()) { if (l.size() < 1) { // we need at least one message continue; } Map<Integer, List<IMessage>> messagesByType = getMessagesByType(l); for (int type : messagesByType.keySet()) { l = messagesByType.get(type); // the values are guaranteed to have size at least equal to 1 IMessage message = l.get(0); // messages are grouped by type, and the severity is set by type, so, this is ok... if (message.getSeverity() == IMarker.SEVERITY_INFO) { if (doIgnoreMessageIfJustInformational(message.getType())) { // ok, let's ignore it for real (and don't add it) as those are not likely to be // used anyways for other actions) continue; } } // we add even ignore messages because they might be used later in actions dependent on code // analysis if (l.size() == 1) { // don't add additional info: not being used // addAdditionalInfoToUnusedWildImport(message); addToResult(result, message); } else { // the generator token has many associated messages - the messages may have different // types, // so, we need to get them by types CompositeMessage compositeMessage = new CompositeMessage(message.getType(), message.getGenerator(), prefs); for (IMessage m : l) { compositeMessage.addMessage(m); } // don't add additional info: not being used // addAdditionalInfoToUnusedWildImport(compositeMessage); addToResult(result, compositeMessage); } } } for (IMessage message : independentMessages) { if (message.getSeverity() == IMarker.SEVERITY_INFO) { if (doIgnoreMessageIfJustInformational(message.getType())) { // ok, let's ignore it for real (and don't add it) as those are not likely to be // used anyways for other actions) continue; } // otherwise keep on and add it (needed for some actions) } addToResult(result, message); } return result; }