Java 类org.eclipse.jdt.internal.compiler.ast.Statement 实例源码

项目:lombok-ianchiu    文件:EclipseAST.java   
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
    switch (kind) {
    case COMPILATION_UNIT:
        return buildCompilationUnit((CompilationUnitDeclaration) node);
    case TYPE:
        return buildType((TypeDeclaration) node);
    case FIELD:
        return buildField((FieldDeclaration) node);
    case INITIALIZER:
        return buildInitializer((Initializer) node);
    case METHOD:
        return buildMethod((AbstractMethodDeclaration) node);
    case ARGUMENT:
        return buildLocal((Argument) node, kind);
    case LOCAL:
        return buildLocal((LocalDeclaration) node, kind);
    case STATEMENT:
        return buildStatement((Statement) node);
    case ANNOTATION:
        return buildAnnotation((Annotation) node, false);
    default:
        throw new AssertionError("Did not expect to arrive here: " + kind);
    }
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private MethodDeclaration generateCleanMethod(List<BuilderFieldData> builderFields, EclipseNode builderType, ASTNode source) {
    List<Statement> statements = new ArrayList<Statement>();

    for (BuilderFieldData bfd : builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements);
        }
    }

    FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
    thisUnclean.receiver = new ThisReference(0, 0);
    statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0));
    MethodDeclaration decl = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    decl.selector = CLEAN_METHOD_NAME;
    decl.modifiers = ClassFileConstants.AccPrivate;
    decl.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    decl.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
    decl.statements = statements.toArray(new Statement[0]);
    decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
    return decl;
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
public MethodDeclaration generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = builderMethodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic;
    if (isStatic) out.modifiers |= ClassFileConstants.AccStatic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.typeParameters = copyTypeParams(typeParams, source);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;
}
项目:lombok-ianchiu    文件:HandleNonNull.java   
public char[] returnVarNameIfNullCheck(Statement stat) {
    if (!(stat instanceof IfStatement)) return null;

    /* Check that the if's statement is a throw statement, possibly in a block. */ {
        Statement then = ((IfStatement) stat).thenStatement;
        if (then instanceof Block) {
            Statement[] blockStatements = ((Block) then).statements;
            if (blockStatements == null || blockStatements.length == 0) return null;
            then = blockStatements[0];
        }

        if (!(then instanceof ThrowStatement)) return null;
    }

    /* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
       a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
        Expression cond = ((IfStatement) stat).condition;
        if (!(cond instanceof EqualExpression)) return null;
        EqualExpression bin = (EqualExpression) cond;
        int operatorId = ((bin.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT);
        if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
        if (!(bin.left instanceof SingleNameReference)) return null;
        if (!(bin.right instanceof NullLiteral)) return null;
        return ((SingleNameReference) bin.left).token;
    }
}
项目:lombok-ianchiu    文件:EclipseJavaUtilListSetSingularizer.java   
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaListSetSingularizer.generateMethods(data, builderType, fluent, chain);
        return;
    }

    TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateSingularMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generatePluralMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(returnType, returnStatement, data, builderType);
}
项目:lombok-ianchiu    文件:EclipseJavaUtilListSetSingularizer.java   
private void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
    thisDotField2.receiver = new ThisReference(0, 0);
    md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
    MessageSend clearMsg = new MessageSend();
    clearMsg.receiver = thisDotField2;
    clearMsg.selector = "clear".toCharArray();
    Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsg, 0, 0);
    md.statements = returnStatement != null ? new Statement[] {clearStatement, returnStatement} : new Statement[] {clearStatement};
    md.returnType = returnType;
    injectMethod(builderType, md);
}
项目:lombok-ianchiu    文件:EclipseJavaUtilMapSingularizer.java   
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaMapSingularizer.generateMethods(data, builderType, fluent, chain);
        return;
    }

    TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateSingularMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generatePluralMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(returnType, returnStatement, data, builderType);
}
项目:EasyMPermission    文件:EclipseAST.java   
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
    switch (kind) {
    case COMPILATION_UNIT:
        return buildCompilationUnit((CompilationUnitDeclaration) node);
    case TYPE:
        return buildType((TypeDeclaration) node);
    case FIELD:
        return buildField((FieldDeclaration) node);
    case INITIALIZER:
        return buildInitializer((Initializer) node);
    case METHOD:
        return buildMethod((AbstractMethodDeclaration) node);
    case ARGUMENT:
        return buildLocal((Argument) node, kind);
    case LOCAL:
        return buildLocal((LocalDeclaration) node, kind);
    case STATEMENT:
        return buildStatement((Statement) node);
    case ANNOTATION:
        return buildAnnotation((Annotation) node, false);
    default:
        throw new AssertionError("Did not expect to arrive here: " + kind);
    }
}
项目:EasyMPermission    文件:HandleBuilder.java   
private MethodDeclaration generateCleanMethod(List<BuilderFieldData> builderFields, EclipseNode builderType, ASTNode source) {
    List<Statement> statements = new ArrayList<Statement>();

    for (BuilderFieldData bfd : builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements);
        }
    }

    FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
    thisUnclean.receiver = new ThisReference(0, 0);
    statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0));
    MethodDeclaration decl = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    decl.selector = CLEAN_METHOD_NAME;
    decl.modifiers = ClassFileConstants.AccPrivate;
    decl.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    decl.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
    decl.statements = statements.toArray(new Statement[0]);
    decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
    return decl;
}
项目:EasyMPermission    文件:HandleBuilder.java   
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = builderMethodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.typeParameters = copyTypeParams(typeParams, source);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;
}
项目:EasyMPermission    文件:HandleNonNull.java   
public char[] returnVarNameIfNullCheck(Statement stat) {
    if (!(stat instanceof IfStatement)) return null;

    /* Check that the if's statement is a throw statement, possibly in a block. */ {
        Statement then = ((IfStatement) stat).thenStatement;
        if (then instanceof Block) {
            Statement[] blockStatements = ((Block) then).statements;
            if (blockStatements == null || blockStatements.length == 0) return null;
            then = blockStatements[0];
        }

        if (!(then instanceof ThrowStatement)) return null;
    }

    /* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
       a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
        Expression cond = ((IfStatement) stat).condition;
        if (!(cond instanceof EqualExpression)) return null;
        EqualExpression bin = (EqualExpression) cond;
        int operatorId = ((bin.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT);
        if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
        if (!(bin.left instanceof SingleNameReference)) return null;
        if (!(bin.right instanceof NullLiteral)) return null;
        return ((SingleNameReference) bin.left).token;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:UnresolvedReferenceNameFinder.java   
private void removeLocals(Statement[] statements, int start, int end) {
    if (statements != null) {
        for (int i = 0; i < statements.length; i++) {
            if (statements[i] instanceof LocalDeclaration) {
                LocalDeclaration localDeclaration = (LocalDeclaration) statements[i];
                int j = indexOfFisrtNameAfter(start);
                done : while (j != -1) {
                    int nameStart = this.potentialVariableNameStarts[j];
                    if (start <= nameStart && nameStart <= end) {
                        if (CharOperation.equals(this.potentialVariableNames[j], localDeclaration.name, false)) {
                            removeNameAt(j);
                        }
                    }

                    if (end < nameStart) break done;
                    j = indexOfNextName(j);
                }
            }
        }

    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.LabeledStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(LabeledStatement labeledStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier);
    this.scribe.printNextToken(TerminalTokens.TokenNameCOLON, this.preferences.insert_space_before_colon_in_labeled_statement);
    if (this.preferences.insert_space_after_colon_in_labeled_statement) {
        this.scribe.space();
    }
    if (this.preferences.insert_new_line_after_label) {
        this.scribe.printNewLine();
    }
    final Statement statement = labeledStatement.statement;
    statement.traverse(this, scope);
    if (statement instanceof Expression) {
        this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredInitializer.java   
public RecoveredElement add(Statement statement, int bracketBalanceValue) {

    /* do not consider a statement starting passed the initializer end (if set)
        it must be belonging to an enclosing type */
    if (this.fieldDeclaration.declarationSourceEnd != 0
            && statement.sourceStart > this.fieldDeclaration.declarationSourceEnd){
        resetPendingModifiers();
        if (this.parent == null) return this; // ignore
        return this.parent.add(statement, bracketBalanceValue);
    }
    /* initializer body should have been created */
    Block block = new Block(0);
    block.sourceStart = ((Initializer)this.fieldDeclaration).sourceStart;
    RecoveredElement element = this.add(block, 1);

    if (this.initializerBody != null) {
        this.initializerBody.attachPendingModifiers(
                this.pendingAnnotations,
                this.pendingAnnotationCount,
                this.pendingModifiers,
                this.pendingModifersSourceStart);
    }
    resetPendingModifiers();

    return element.add(statement, bracketBalanceValue);
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredElement.java   
public RecoveredElement add(Statement statement, int bracketBalanceValue) {

    /* default behavior is to delegate recording to parent if any */
    resetPendingModifiers();
    if (this.parent == null) return this; // ignore
    if (this instanceof RecoveredType) {
        TypeDeclaration typeDeclaration = ((RecoveredType) this).typeDeclaration;
        if (typeDeclaration != null && (typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { 
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291040, new X(<SelectOnMessageSend:zoo()>) { ???
            if (statement.sourceStart > typeDeclaration.sourceStart && statement.sourceEnd < typeDeclaration.sourceEnd) {
                return this;
            }
        }
    }
    this.updateSourceEndIfNecessary(previousAvailableLineEnd(statement.sourceStart - 1));
    return this.parent.add(statement, bracketBalanceValue);
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredType.java   
public Statement updatedStatement(int depth, Set knownTypes){

    // ignore closed anonymous type
    if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0 && !this.preserveContent){
        return null;
    }

    TypeDeclaration updatedType = updatedTypeDeclaration(depth + 1, knownTypes);
    if (updatedType != null && (updatedType.bits & ASTNode.IsAnonymousType) != 0){
        /* in presence of an anonymous type, we want the full allocation expression */
        QualifiedAllocationExpression allocation = updatedType.allocation;

        if (allocation.statementEnd == -1) {
            allocation.statementEnd = updatedType.declarationSourceEnd;
        }
        return allocation;
    }
    return updatedType;
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeEnhancedForStatement() {
    // EnhancedForStatement ::= EnhancedForStatementHeader Statement
    // EnhancedForStatementNoShortIf ::= EnhancedForStatementHeader StatementNoShortIf

    //statements
    this.astLengthPtr--;
    Statement statement = (Statement) this.astStack[this.astPtr--];

    // foreach statement is on the ast stack
    ForeachStatement foreachStatement = (ForeachStatement) this.astStack[this.astPtr];
    foreachStatement.action = statement;
    // remember useful empty statement
    if (statement instanceof EmptyStatement) statement.bits |= ASTNode.IsUsefulEmptyStatement;

    foreachStatement.sourceEnd = this.endStatementPosition;
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeStatementIfWithElse() {
    // IfThenElseStatement ::=  'if' '(' Expression ')' StatementNoShortIf 'else' Statement
    // IfThenElseStatementNoShortIf ::=  'if' '(' Expression ')' StatementNoShortIf 'else' StatementNoShortIf

    this.expressionLengthPtr--;

    // optimized {..., Then, Else } ==> {..., If }
    this.astLengthPtr--;

    //optimize the push/pop
    this.astStack[--this.astPtr] =
        new IfStatement(
            this.expressionStack[this.expressionPtr--],
            (Statement) this.astStack[this.astPtr],
            (Statement) this.astStack[this.astPtr + 1],
            this.intStack[this.intPtr--],
            this.endStatementPosition);
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredBlock.java   
public RecoveredElement add(Statement stmt, int bracketBalanceValue, boolean delegatedByParent) {

    if (stmt instanceof LambdaExpression) // lambdas are recovered up to the containing statement anyways.
        return this;

    resetPendingModifiers();

    /* do not consider a nested block starting passed the block end (if set)
        it must be belonging to an enclosing block */
    if (this.blockDeclaration.sourceEnd != 0
            && stmt.sourceStart > this.blockDeclaration.sourceEnd){
        if (delegatedByParent) return this; //ignore
        return this.parent.add(stmt, bracketBalanceValue);
    }

    RecoveredStatement element = new RecoveredStatement(stmt, this, bracketBalanceValue);
    attach(element);
    if (stmt.sourceEnd == 0) return element;
    return this;
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void unreachableCode(Statement statement) {
    int sourceStart = statement.sourceStart;
    int sourceEnd = statement.sourceEnd;
    if (statement instanceof LocalDeclaration) {
        LocalDeclaration declaration = (LocalDeclaration) statement;
        sourceStart = declaration.declarationSourceStart;
        sourceEnd = declaration.declarationSourceEnd;
    } else if (statement instanceof Expression) {
        int statemendEnd = ((Expression) statement).statementEnd;
        if (statemendEnd != -1) sourceEnd = statemendEnd;
    }
    this.handle(
        IProblem.CodeCannotBeReached,
        NoArgument,
        NoArgument,
        sourceStart,
        sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:UnresolvedReferenceNameFinder.java   
private void removeLocals(Statement[] statements, int start, int end) {
    if (statements != null) {
        for (int i = 0; i < statements.length; i++) {
            if (statements[i] instanceof LocalDeclaration) {
                LocalDeclaration localDeclaration = (LocalDeclaration) statements[i];
                int j = indexOfFisrtNameAfter(start);
                done : while (j != -1) {
                    int nameStart = this.potentialVariableNameStarts[j];
                    if (start <= nameStart && nameStart <= end) {
                        if (CharOperation.equals(this.potentialVariableNames[j], localDeclaration.name, false)) {
                            removeNameAt(j);
                        }
                    }

                    if (end < nameStart) break done;
                    j = indexOfNextName(j);
                }
            }
        }

    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.LabeledStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(LabeledStatement labeledStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier);
    this.scribe.printNextToken(TerminalTokens.TokenNameCOLON, this.preferences.insert_space_before_colon_in_labeled_statement);
    if (this.preferences.insert_space_after_colon_in_labeled_statement) {
        this.scribe.space();
    }
    if (this.preferences.insert_new_line_after_label) {
        this.scribe.printNewLine();
    }
    final Statement statement = labeledStatement.statement;
    statement.traverse(this, scope);
    if (statement instanceof Expression) {
        this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredInitializer.java   
public RecoveredElement add(Statement statement, int bracketBalanceValue) {

    /* do not consider a statement starting passed the initializer end (if set)
        it must be belonging to an enclosing type */
    if (this.fieldDeclaration.declarationSourceEnd != 0
            && statement.sourceStart > this.fieldDeclaration.declarationSourceEnd){
        resetPendingModifiers();
        if (this.parent == null) return this; // ignore
        return this.parent.add(statement, bracketBalanceValue);
    }
    /* initializer body should have been created */
    Block block = new Block(0);
    block.sourceStart = ((Initializer)this.fieldDeclaration).sourceStart;
    RecoveredElement element = this.add(block, 1);

    if (this.initializerBody != null) {
        this.initializerBody.attachPendingModifiers(
                this.pendingAnnotations,
                this.pendingAnnotationCount,
                this.pendingModifiers,
                this.pendingModifersSourceStart);
    }
    resetPendingModifiers();

    return element.add(statement, bracketBalanceValue);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredElement.java   
public RecoveredElement add(Statement statement, int bracketBalanceValue) {

    /* default behavior is to delegate recording to parent if any */
    resetPendingModifiers();
    if (this.parent == null) return this; // ignore
    if (this instanceof RecoveredType) {
        TypeDeclaration typeDeclaration = ((RecoveredType) this).typeDeclaration;
        if (typeDeclaration != null && (typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { 
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291040, new X(<SelectOnMessageSend:zoo()>) { ???
            if (statement.sourceStart > typeDeclaration.sourceStart && statement.sourceEnd < typeDeclaration.sourceEnd) {
                return this;
            }
        }
    }
    this.updateSourceEndIfNecessary(previousAvailableLineEnd(statement.sourceStart - 1));
    return this.parent.add(statement, bracketBalanceValue);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredType.java   
public Statement updatedStatement(int depth, Set knownTypes){

    // ignore closed anonymous type
    if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0 && !this.preserveContent){
        return null;
    }

    TypeDeclaration updatedType = updatedTypeDeclaration(depth + 1, knownTypes);
    if (updatedType != null && (updatedType.bits & ASTNode.IsAnonymousType) != 0){
        /* in presence of an anonymous type, we want the full allocation expression */
        QualifiedAllocationExpression allocation = updatedType.allocation;

        if (allocation.statementEnd == -1) {
            allocation.statementEnd = updatedType.declarationSourceEnd;
        }
        return allocation;
    }
    return updatedType;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredBlock.java   
public RecoveredElement add(Statement stmt, int bracketBalanceValue, boolean delegatedByParent) {
    resetPendingModifiers();

    /* do not consider a nested block starting passed the block end (if set)
        it must be belonging to an enclosing block */
    if (this.blockDeclaration.sourceEnd != 0
            && stmt.sourceStart > this.blockDeclaration.sourceEnd){
        if (delegatedByParent) return this; //ignore
        return this.parent.add(stmt, bracketBalanceValue);
    }

    RecoveredStatement element = new RecoveredStatement(stmt, this, bracketBalanceValue);
    attach(element);
    if (stmt.sourceEnd == 0) return element;
    return this;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void unreachableCode(Statement statement) {
    int sourceStart = statement.sourceStart;
    int sourceEnd = statement.sourceEnd;
    if (statement instanceof LocalDeclaration) {
        LocalDeclaration declaration = (LocalDeclaration) statement;
        sourceStart = declaration.declarationSourceStart;
        sourceEnd = declaration.declarationSourceEnd;
    } else if (statement instanceof Expression) {
        int statemendEnd = ((Expression) statement).statementEnd;
        if (statemendEnd != -1) sourceEnd = statemendEnd;
    }
    this.handle(
        IProblem.CodeCannotBeReached,
        NoArgument,
        NoArgument,
        sourceStart,
        sourceEnd);
}
项目:xapi    文件:GwtAstBuilder.java   
@SuppressWarnings("unchecked")
protected <T extends JStatement> List<T> pop(Statement[] statements) {
  if (statements == null) {
    return Collections.emptyList();
  }
  List<T> result = (List<T>) popList(statements.length);
  int i = 0;
  for (ListIterator<T> it = result.listIterator(); it.hasNext(); ++i) {
    Object element = it.next();
    if (element == null) {
      it.remove();
    } else if (element instanceof JExpression) {
      it.set((T) simplify((JExpression) element, (Expression) statements[i]).makeStatement());
    }
  }
  return result;
}
项目:lombok    文件:EclipseAST.java   
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
    switch (kind) {
    case COMPILATION_UNIT:
        return buildCompilationUnit((CompilationUnitDeclaration) node);
    case TYPE:
        return buildType((TypeDeclaration) node);
    case FIELD:
        return buildField((FieldDeclaration) node);
    case INITIALIZER:
        return buildInitializer((Initializer) node);
    case METHOD:
        return buildMethod((AbstractMethodDeclaration) node);
    case ARGUMENT:
        return buildLocal((Argument) node, kind);
    case LOCAL:
        return buildLocal((LocalDeclaration) node, kind);
    case STATEMENT:
        return buildStatement((Statement) node);
    case ANNOTATION:
        return buildAnnotation((Annotation) node, false);
    default:
        throw new AssertionError("Did not expect to arrive here: " + kind);
    }
}
项目:lombok    文件:EclipseHandlerUtil.java   
/**
 * Generates a new statement that checks if the given variable is null, and if so, throws a {@code NullPointerException} with the
 * variable name as message.
 */
public static Statement generateNullCheck(AbstractVariableDeclaration variable, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    if (isPrimitive(variable.type)) return null;
    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{p, p, p});
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] { new StringLiteral(variable.name, pS, pE, 0)};
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
    setGeneratedBy(throwStatement, source);

    SingleNameReference varName = new SingleNameReference(variable.name, p);
    setGeneratedBy(varName, source);
    NullLiteral nullLiteral = new NullLiteral(pS, pE);
    setGeneratedBy(nullLiteral, source);
    EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
    equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
    setGeneratedBy(equalExpression, source);
    IfStatement ifStatement = new IfStatement(equalExpression, throwStatement, 0, 0);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目:lombok-ianchiu    文件:HandleUtilityClass.java   
private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) {
    ASTNode source = sourceNode.get();

    TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get());
    long p = (long) source.sourceStart << 32 | source.sourceEnd;

    ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult);

    constructor.modifiers = ClassFileConstants.AccPrivate;
    constructor.selector = typeDeclaration.name;
    constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper);
    constructor.constructorCall.sourceStart = source.sourceStart;
    constructor.constructorCall.sourceEnd = source.sourceEnd;
    constructor.thrownExceptions = null;
    constructor.typeParameters = null;
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;
    constructor.arguments = null;

    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length];
    Arrays.fill(ps, p);
    exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps);
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] {
            new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0)
    };
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd);
    setGeneratedBy(throwStatement, source);

    constructor.statements = new Statement[] {throwStatement};

    injectMethod(typeNode, constructor);
}
项目:lombok-ianchiu    文件:HandleSneakyThrows.java   
public void handleMethod(EclipseNode annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
    if (method.isAbstract()) {
        annotation.addError("@SneakyThrows can only be used on concrete methods.");
        return;
    }

    if (method.statements == null || method.statements.length == 0) {
        boolean hasConstructorCall = false;
        if (method instanceof ConstructorDeclaration) {
            ExplicitConstructorCall constructorCall = ((ConstructorDeclaration) method).constructorCall;
            hasConstructorCall = constructorCall != null && !constructorCall.isImplicitSuper() && !constructorCall.isImplicitThis();
        }

        if (hasConstructorCall) {
            annotation.addWarning("Calls to sibling / super constructors are always excluded from @SneakyThrows; @SneakyThrows has been ignored because there is no other code in this constructor.");
        } else {
            annotation.addWarning("This method or constructor is empty; @SneakyThrows has been ignored.");
        }

        return;
    }

    Statement[] contents = method.statements;

    for (DeclaredException exception : exceptions) {
        contents = new Statement[] { buildTryCatchBlock(contents, exception, exception.node, method) };
    }

    method.statements = contents;
    annotation.up().rebuild();
}
项目:lombok-ianchiu    文件:HandleCleanup.java   
private void doAssignmentCheck0(EclipseNode node, Statement statement, char[] varName) {
    if (statement instanceof Assignment)
        doAssignmentCheck0(node, ((Assignment)statement).expression, varName);
    else if (statement instanceof LocalDeclaration)
        doAssignmentCheck0(node, ((LocalDeclaration)statement).initialization, varName);
    else if (statement instanceof CastExpression)
        doAssignmentCheck0(node, ((CastExpression)statement).expression, varName);
    else if (statement instanceof SingleNameReference) {
        if (Arrays.equals(((SingleNameReference)statement).token, varName)) {
            EclipseNode problemNode = node.getNodeFor(statement);
            if (problemNode != null) problemNode.addWarning(
                    "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
        }
    }
}
项目:lombok-ianchiu    文件:EclipseGuavaSingularizer.java   
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) {
    TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateSingularMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generatePluralMethod(returnType, returnStatement, data, builderType, fluent);

    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(returnType, returnStatement, data,  builderType);
}
项目:lombok-ianchiu    文件:EclipseGuavaSingularizer.java   
void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    Assignment a = new Assignment(thisDotField, new NullLiteral(0, 0), 0);
    md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
    md.statements = returnStatement != null ? new Statement[] {a, returnStatement} : new Statement[] {a};
    md.returnType = returnType;
    injectMethod(builderType, md);
}
项目:lombok-ianchiu    文件:EclipseGuavaSingularizer.java   
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    LombokImmutableList<String> suffixes = getArgumentSuffixes();
    char[][] names = new char[suffixes.size()][];
    for (int i = 0; i < suffixes.size(); i++) {
        String s = suffixes.get(i);
        char[] n = data.getSingularName();
        names[i] = s.isEmpty() ? n : s.toCharArray();
    }

    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType));

    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    MessageSend thisDotFieldDotAdd = new MessageSend();
    thisDotFieldDotAdd.arguments = new Expression[suffixes.size()];
    for (int i = 0; i < suffixes.size(); i++) {
        thisDotFieldDotAdd.arguments[i] = new SingleNameReference(names[i], 0L);
    }
    thisDotFieldDotAdd.receiver = thisDotField;
    thisDotFieldDotAdd.selector = getAddMethodName().toCharArray();
    statements.add(thisDotFieldDotAdd);
    if (returnStatement != null) statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[statements.size()]);
    md.arguments = new Argument[suffixes.size()];
    for (int i = 0; i < suffixes.size(); i++) {
        TypeReference tr = cloneParamType(i, data.getTypeArgs(), builderType);
        md.arguments[i] = new Argument(names[i], 0, tr, 0);
    }
    md.returnType = returnType;
    md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(getAddMethodName(), new String(data.getSingularName())).toCharArray();

    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
项目:lombok-ianchiu    文件:EclipseGuavaSingularizer.java   
protected Statement createConstructBuilderVarIfNeeded(SingularData data, EclipseNode builderType) {
    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
    thisDotField2.receiver = new ThisReference(0, 0);
    Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL);

    MessageSend createBuilderInvoke = new MessageSend();
    char[][] tokenizedName = makeGuavaTypeName(getSimpleTargetTypeName(data), false);
    createBuilderInvoke.receiver = new QualifiedNameReference(tokenizedName, NULL_POSS, 0, 0);
    createBuilderInvoke.selector = getBuilderMethodName(data);
    return new IfStatement(cond, new Assignment(thisDotField2, createBuilderInvoke, 0), 0, 0);
}
项目:lombok-ianchiu    文件:EclipseJavaUtilListSetSingularizer.java   
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));

    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    MessageSend thisDotFieldDotAdd = new MessageSend();
    thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)};
    thisDotFieldDotAdd.receiver = thisDotField;
    thisDotFieldDotAdd.selector = "add".toCharArray();
    statements.add(thisDotFieldDotAdd);
    if (returnStatement != null) statements.add(returnStatement);

    md.statements = statements.toArray(new Statement[statements.size()]);
    TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
    Argument param = new Argument(data.getSingularName(), 0, paramType, 0);
    md.arguments = new Argument[] {param};
    md.returnType = returnType;
    md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();

    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
项目:lombok-ianchiu    文件:EclipseJavaUtilListSetSingularizer.java   
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));

    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    MessageSend thisDotFieldDotAddAll = new MessageSend();
    thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
    thisDotFieldDotAddAll.receiver = thisDotField;
    thisDotFieldDotAddAll.selector = "addAll".toCharArray();
    statements.add(thisDotFieldDotAddAll);
    if (returnStatement != null) statements.add(returnStatement);

    md.statements = statements.toArray(new Statement[statements.size()]);

    TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS);
    paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
    Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
    md.arguments = new Argument[] {param};
    md.returnType = returnType;
    md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();

    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
项目:lombok-ianchiu    文件:EclipseJavaUtilMapSingularizer.java   
private void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;

    String pN = new String(data.getPluralName());
    char[] keyFieldName = (pN + "$key").toCharArray();
    char[] valueFieldName = (pN + "$value").toCharArray();

    FieldReference thisDotField = new FieldReference(keyFieldName, 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    FieldReference thisDotField2 = new FieldReference(keyFieldName, 0L);
    thisDotField2.receiver = new ThisReference(0, 0);
    FieldReference thisDotField3 = new FieldReference(valueFieldName, 0L);
    thisDotField3.receiver = new ThisReference(0, 0);
    md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
    MessageSend clearMsg1 = new MessageSend();
    clearMsg1.receiver = thisDotField2;
    clearMsg1.selector = "clear".toCharArray();
    MessageSend clearMsg2 = new MessageSend();
    clearMsg2.receiver = thisDotField3;
    clearMsg2.selector = "clear".toCharArray();
    Block clearMsgs = new Block(2);
    clearMsgs.statements = new Statement[] {clearMsg1, clearMsg2};
    Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsgs, 0, 0);
    md.statements = returnStatement != null ? new Statement[] {clearStatement, returnStatement} : new Statement[] {clearStatement};
    md.returnType = returnType;
    injectMethod(builderType, md);
}