Example usage for org.eclipse.jdt.internal.compiler.parser Scanner Scanner

List of usage examples for org.eclipse.jdt.internal.compiler.parser Scanner Scanner

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.parser Scanner Scanner.

Prototype

public Scanner() 

Source Link

Usage

From source file:org.caesarj.ui.javamodel.AspectsConvertingParser.java

License:Open Source License

public ArrayList convert(ConversionOptions options) {
    boolean insertThisJoinPointReferences = options.isThisJoinPointReferencesEnabled();
    boolean addReferencesForOrganizeImports = options.isDummyTypeReferencesForOrganizeImportsEnabled();
    boolean isSimulateContextSwitchNecessary = (options.getTargetType() != null);

    scanner = new Scanner();
    scanner.setSource(content);//from  ww  w .  jav  a2s . c o m

    insidePointcutDesignator = false;
    //insideAspect = false;
    insideAspectDeclaration = false;

    // Bug 93248: Count question marks so as to ignore colons that are part of conditional statements      
    int questionMarkCount = 0;

    // Bug 110751: Ignore colons that are part of enhanced "for" loop in Java 5
    boolean insideFor = false;

    replacements.clear();
    typeReferences.clear();
    usedIdentifiers.clear();

    int tok;
    while (true) {

        try {
            tok = scanner.getNextToken();
        } catch (InvalidInputException e) {
            continue;
        }
        if (tok == TokenNameEOF)
            break;

        switch (tok) {
        case TokenNameIdentifier:
            char[] name = scanner.getCurrentIdentifierSource();
            if (CharOperation.equals(ca_cclass, name)) {
                int pos = scanner.getCurrentTokenStartPosition();
                addReplacement(pos, ca_cclass.length, ca_class_);
            } else if (CharOperation.equals(ca_wraps, name)) {
                replaceWrappee();
            } else if (CharOperation.equals(throwing, name))
                consumeRetOrThro();
            else if (CharOperation.equals(returning, name))
                consumeRetOrThro();
            else if (insidePointcutDesignator && Character.isUpperCase(name[0])
                    && (content[scanner.getCurrentTokenStartPosition() - 1] != '.')) {
                typeReferences.add(new String(name));
            }

            if (isSimulateContextSwitchNecessary) {
                usedIdentifiers.add(new String(name));
            }
            break;
        case TokenNameextends:
            eliminateMultipleInheritance();
            break;
        case TokenNamefor:
            insideFor = true;
            break;
        case TokenNameRPAREN:
            insideFor = false;
            break;
        case TokenNameCOLON:
            //if (!insideAspect)
            //   break;
            if (insideFor)
                break;
            if (questionMarkCount > 0) {
                questionMarkCount--;
                break;
            }
            startPointcutDesignator();
            break;

        case TokenNameQUESTION:
            questionMarkCount++;
            break;

        case TokenNameSEMICOLON:
            if (insidePointcutDesignator)
                endPointcutDesignator();
            break;

        case TokenNameLBRACE:
            if (insidePointcutDesignator) {
                endPointcutDesignator();
                //must be start of advice body -> insert tjp reference
                if (insertThisJoinPointReferences && !insideAspectDeclaration)
                    addReplacement(scanner.getCurrentTokenStartPosition() + 1, 0, tjpRefs2);
            }
            insideAspectDeclaration = false;

            break;
        case TokenNameRBRACE:
            if (insidePointcutDesignator) {
                // bug 129367: if we've hit a } here, we must be
                // in the middle of an unterminated pointcut
                endPointcutDesignator();
            }
            break;
        }
    }

    if (insidePointcutDesignator) {
        // bug 129367: if we've hit the end of the buffer, we must
        // be in the middle of an unterminated pointcut
        endPointcutDesignator();
    }

    if (addReferencesForOrganizeImports)
        addReferences();

    if (isSimulateContextSwitchNecessary)
        simulateContextSwitch(options.getCodeCompletePosition(), options.getTargetType());

    applyReplacements();

    //System.out.println(new String(content));
    return replacements;
}