Example usage for org.aspectj.org.eclipse.jdt.core.dom AspectDeclaration PERCLAUSE_PROPERTY

List of usage examples for org.aspectj.org.eclipse.jdt.core.dom AspectDeclaration PERCLAUSE_PROPERTY

Introduction

In this page you can find the example usage for org.aspectj.org.eclipse.jdt.core.dom AspectDeclaration PERCLAUSE_PROPERTY.

Prototype

ChildPropertyDescriptor PERCLAUSE_PROPERTY

To view the source code for org.aspectj.org.eclipse.jdt.core.dom AspectDeclaration PERCLAUSE_PROPERTY.

Click Source Link

Usage

From source file:org.eclipse.ajdt.core.dom.rewrite.AjASTRewriteAnalyzer.java

License:Open Source License

public boolean visit(AspectDeclaration node) {
    // ajh02: method added
    if (!hasChildrenChanges(node)) {
        return doVisitUnchangedChildren(node);
    }//  ww w .  ja v a 2s . com
    int apiLevel = node.getAST().apiLevel();

    int pos = rewriteJavadoc(node, AspectDeclaration.JAVADOC_PROPERTY);

    if (apiLevel == JLS2_INTERNAL) {
        rewriteModifiers(node, AspectDeclaration.MODIFIERS_PROPERTY, pos);
    } else {
        rewriteModifiers2(node, AspectDeclaration.MODIFIERS2_PROPERTY, pos);
    }

    boolean isInterface = ((Boolean) getOriginalValue(node, AspectDeclaration.INTERFACE_PROPERTY))
            .booleanValue();
    // modifiers & class/interface
    boolean invertType = isChanged(node, AspectDeclaration.INTERFACE_PROPERTY);
    if (invertType) {
        try {
            int typeToken = isInterface ? ITerminalSymbols.TokenNameinterface : ITerminalSymbols.TokenNameclass;
            getScanner().readToToken(typeToken, node.getStartPosition());

            String str = isInterface ? "class" : "interface"; //$NON-NLS-1$ //$NON-NLS-2$
            int start = getScanner().getCurrentStartOffset();
            int end = getScanner().getCurrentEndOffset();

            doTextReplace(start, end - start, str, getEditGroup(node, AspectDeclaration.INTERFACE_PROPERTY));
        } catch (CoreException e) {
            // ignore
        }
    }

    // name
    pos = rewriteRequiredNode(node, AspectDeclaration.NAME_PROPERTY);
    pos = rewriteRequiredNode(node, AspectDeclaration.PERCLAUSE_PROPERTY);

    if (apiLevel >= AST.JLS3) {
        pos = rewriteOptionalTypeParameters(node, AspectDeclaration.TYPE_PARAMETERS_PROPERTY, pos, "", false, //$NON-NLS-1$
                true);
    }

    // superclass
    if (!isInterface || invertType) {
        ChildPropertyDescriptor superClassProperty = (apiLevel == JLS2_INTERNAL)
                ? AspectDeclaration.SUPERCLASS_PROPERTY
                : AspectDeclaration.SUPERCLASS_TYPE_PROPERTY;

        RewriteEvent superClassEvent = getEvent(node, superClassProperty);

        int changeKind = superClassEvent != null ? superClassEvent.getChangeKind() : RewriteEvent.UNCHANGED;
        switch (changeKind) {
        case RewriteEvent.INSERTED: {
            doTextInsert(pos, " extends ", getEditGroup(superClassEvent)); //$NON-NLS-1$
            doTextInsert(pos, (ASTNode) superClassEvent.getNewValue(), 0, false, getEditGroup(superClassEvent));
            break;
        }
        case RewriteEvent.REMOVED: {
            ASTNode superClass = (ASTNode) superClassEvent.getOriginalValue();
            int endPos = getExtendedEnd(superClass);
            doTextRemoveAndVisit(pos, endPos - pos, superClass, getEditGroup(superClassEvent));
            pos = endPos;
            break;
        }
        case RewriteEvent.REPLACED: {
            ASTNode superClass = (ASTNode) superClassEvent.getOriginalValue();
            SourceRange range = getExtendedRange(superClass);
            int offset = range.getStartPosition();
            int length = range.getLength();
            doTextRemoveAndVisit(offset, length, superClass, getEditGroup(superClassEvent));
            doTextInsert(offset, (ASTNode) superClassEvent.getNewValue(), 0, false,
                    getEditGroup(superClassEvent));
            pos = offset + length;
            break;
        }
        case RewriteEvent.UNCHANGED: {
            pos = doVisit(node, superClassProperty, pos);
        }
        }
    }
    // extended interfaces
    ChildListPropertyDescriptor superInterfaceProperty = (apiLevel == JLS2_INTERNAL)
            ? AspectDeclaration.SUPER_INTERFACES_PROPERTY
            : AspectDeclaration.SUPER_INTERFACE_TYPES_PROPERTY;

    RewriteEvent interfaceEvent = getEvent(node, superInterfaceProperty);
    if (interfaceEvent == null || interfaceEvent.getChangeKind() == RewriteEvent.UNCHANGED) {
        if (invertType) {
            List originalNodes = (List) getOriginalValue(node, superInterfaceProperty);
            if (!originalNodes.isEmpty()) {
                String keyword = isInterface ? " implements " : " extends "; //$NON-NLS-1$ //$NON-NLS-2$
                ASTNode firstNode = (ASTNode) originalNodes.get(0);
                doTextReplace(pos, firstNode.getStartPosition() - pos, keyword,
                        getEditGroup(node, AspectDeclaration.INTERFACE_PROPERTY));
            }
        }
        pos = doVisit(node, superInterfaceProperty, pos);
    } else {
        String keyword = (isInterface == invertType) ? " implements " : " extends "; //$NON-NLS-1$ //$NON-NLS-2$
        if (invertType) {
            List newNodes = (List) interfaceEvent.getNewValue();
            if (!newNodes.isEmpty()) {
                List origNodes = (List) interfaceEvent.getOriginalValue();
                int firstStart = pos;
                if (!origNodes.isEmpty()) {
                    firstStart = ((ASTNode) origNodes.get(0)).getStartPosition();
                }
                doTextReplace(pos, firstStart - pos, keyword,
                        getEditGroup(node, AspectDeclaration.INTERFACE_PROPERTY));
                keyword = ""; //$NON-NLS-1$
                pos = firstStart;
            }
        }
        pos = rewriteNodeList(node, superInterfaceProperty, pos, keyword, ", "); //$NON-NLS-1$
    }

    // type members
    // startPos : find position after left brace of type, be aware that bracket might be missing
    int startIndent = getIndent(node.getStartPosition()) + 1;
    int startPos = getPosAfterLeftBrace(pos);
    rewriteParagraphList(node, AspectDeclaration.BODY_DECLARATIONS_PROPERTY, startPos, startIndent, -1, 2);
    return false;
}