Example usage for org.aspectj.bridge IMessage getSourceLocation

List of usage examples for org.aspectj.bridge IMessage getSourceLocation

Introduction

In this page you can find the example usage for org.aspectj.bridge IMessage getSourceLocation.

Prototype

ISourceLocation getSourceLocation();

Source Link

Usage

From source file:de.zalando.mojo.aspectj.MavenMessageHandler.java

License:Open Source License

/**
 * Copies output from the supplied message onto the active Maven Log.
 * If the message type (i.e. {@code message.getKind()}) is listed in the showDetailsForMessageKindList List,
 * the message is prefixed with location details (Class, row/line number etc.) as well.
 * <p/>//w  w  w . j av a  2s  .c om
 * {@inheritDoc}
 */
public boolean handleMessage(final IMessage message) {

    // Compose the message text
    final StringBuilder builder = new StringBuilder(message.getMessage());
    if (isMessageDetailDesired(message)) {

        //
        // The AJC details are typically delivered on the format [fileName]:[lineNumber]
        // (i.e. /src/main/java/Clazz.java:16).
        //
        // Mimic this, and include the context of the message as well,
        // including guarding against NPEs.
        //
        final ISourceLocation sourceLocation = message.getSourceLocation();
        final String sourceFile = sourceLocation == null || sourceLocation.getSourceFile() == null
                ? "<unknown source file>"
                : sourceLocation.getSourceFile().getAbsolutePath();
        final String context = sourceLocation == null || sourceLocation.getContext() == null ? ""
                : sourceLocation.getContext() + "\n";
        final String line = sourceLocation == null ? "<no line information>" : "" + sourceLocation.getLine();

        builder.append("\n\t").append(sourceFile).append(":").append(line).append("\n").append(context);
    }

    final String messageText = builder.toString();

    if (isNotIgnored(message, IMessage.DEBUG) || isNotIgnored(message, IMessage.INFO)
            || isNotIgnored(message, IMessage.TASKTAG)) {

        // The DEBUG, INFO, and TASKTAG ajc message kinds are considered Maven Debug messages.
        log.debug(messageText);

    } else if (isNotIgnored(message, IMessage.WEAVEINFO)) {

        // The WEAVEINFO ajc message kind is considered Maven Info messages.
        log.info(messageText);

    } else if (isNotIgnored(message, IMessage.WARNING)) {

        // The WARNING ajc message kind is considered Maven Warn messages.
        log.warn(messageText);

    } else if (isNotIgnored(message, IMessage.ERROR) || isNotIgnored(message, IMessage.ABORT)
            || isNotIgnored(message, IMessage.FAIL)) {

        // We map ERROR, ABORT, and FAIL ajc message kinds to Maven Error messages.
        log.error(messageText);
    }

    // Delegate to normal handling.
    return super.handleMessage(message);
}

From source file:io.github.whiskeysierra.archer.CompilerMatchers.java

License:Apache License

private static Matcher<IMessage> hasFile(final Class<?> target) {
    return hasFeature("location", (IMessage m) -> m.getSourceLocation().getSourceFile().getAbsolutePath(),
            endsWith(target.getName().replace('.', '/') + ".java"));
}

From source file:org.caesarj.compiler.aspectj.CaesarMessageHandler.java

License:Open Source License

/**
 * Handles the (AspectJ) message, by creating a KOPI-error and report it to
 * the compiler./*from   w  ww.j  a va2 s  . c o  m*/
 */
public boolean handleMessage(IMessage message) throws AbortException {
    if (isIgnoring(message.getKind())) {
        return true;
    }

    ISourceLocation location = message.getSourceLocation();

    if (message.getKind() == IMessage.WARNING) {

        if (location != null) {

            compiler.get()
                    .reportTrouble(new CWarning(
                            new TokenReference(location.getSourceFile().getPath(), location.getSourceFile(),
                                    location.getLine()),
                            new Message(CaesarMessages.ASPECTJ_WARNING, message.getMessage())));
        } else {

            compiler.get().reportTrouble(new CWarning(TokenReference.NO_REF,
                    new Message(CaesarMessages.ASPECTJ_WARNING, message.getMessage())));

        }

        return true;
    }

    if (location != null) {

        compiler.get()
                .reportTrouble(new PositionedError(
                        new TokenReference(location.getSourceFile().getPath(), location.getSourceFile(),
                                location.getLine()),
                        new Message(CaesarMessages.ASPECTJ_ERROR, message.getMessage())));

    } else {

        compiler.get().reportTrouble(new PositionedError(TokenReference.NO_REF,
                new Message(CaesarMessages.ASPECTJ_ERROR, message.getMessage())));

    }

    return true;
}

From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java

License:Open Source License

public boolean handleMessage(IMessage message) {
    IMessage.Kind kind = message.getKind();
    if (kind == IMessage.ABORT || message.getThrown() != null) {
        // an exception has been thrown by AspectJ, therefore
        // want to create an error dialog containing the information
        // and display it to the user
        AJDTErrorHandler.handleInternalError(UIMessages.ajErrorDialogTitle, message.getMessage(),
                message.getThrown());//from   ww  w.  jav  a  2s  .co  m
        return true;
    }
    if (isIgnoring(kind)) {
        return true;
    }
    if (message.getSourceLocation() == null) {
        AJLog.log(AJLog.COMPILER_MESSAGES, message.getMessage()); //$NON-NLS-1$
        problems.add(new ProblemTracker(message.getMessage(), null, message.getKind()));
    } else {
        if (DebugTracing.DEBUG_COMPILER_MESSAGES) {
            // avoid constructing log string if trace is not active
            AJLog.log(AJLog.COMPILER_MESSAGES, "addSourcelineTask message=" //$NON-NLS-1$
                    + message.getMessage() + " file=" //$NON-NLS-1$
                    + message.getSourceLocation().getSourceFile().getPath() + " line=" //$NON-NLS-1$
                    + message.getSourceLocation().getLine());
        } else {
            AJLog.log(AJLog.COMPILER_MESSAGES, message.getMessage());
        }
        problems.add(new ProblemTracker(message.getMessage(), message.getSourceLocation(), message.getKind(),
                message.getDeclared(), message.getExtraSourceLocations(), message.getID(),
                message.getSourceStart(), message.getSourceEnd(), message.getThrown()));
    }
    return true;
}