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

项目: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    文件:HandleEqualsAndHashCode.java   
public IfStatement generateCompareFloatOrDouble(Expression thisRef, Expression otherRef, char[] floatOrDouble, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    /* if (Float.compare(fieldName, other.fieldName) != 0) return false */
    MessageSend floatCompare = new MessageSend();
    floatCompare.sourceStart = pS; floatCompare.sourceEnd = pE;
    setGeneratedBy(floatCompare, source);
    floatCompare.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.LANG, floatOrDouble);
    floatCompare.selector = "compare".toCharArray();
    floatCompare.arguments = new Expression[] {thisRef, otherRef};
    IntLiteral int0 = makeIntLiteral("0".toCharArray(), source);
    EqualExpression ifFloatCompareIsNot0 = new EqualExpression(floatCompare, int0, OperatorIds.NOT_EQUAL);
    ifFloatCompareIsNot0.sourceStart = pS; ifFloatCompareIsNot0.sourceEnd = pE;
    setGeneratedBy(ifFloatCompareIsNot0, source);
    FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
    setGeneratedBy(falseLiteral, source);
    ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
    setGeneratedBy(returnFalse, source);
    IfStatement ifStatement = new IfStatement(ifFloatCompareIsNot0, returnFalse, pS, pE);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目: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    文件: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    文件: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    文件:HandleEqualsAndHashCode.java   
public IfStatement generateCompareFloatOrDouble(Expression thisRef, Expression otherRef, char[] floatOrDouble, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    /* if (Float.compare(fieldName, other.fieldName) != 0) return false */
    MessageSend floatCompare = new MessageSend();
    floatCompare.sourceStart = pS; floatCompare.sourceEnd = pE;
    setGeneratedBy(floatCompare, source);
    floatCompare.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.LANG, floatOrDouble);
    floatCompare.selector = "compare".toCharArray();
    floatCompare.arguments = new Expression[] {thisRef, otherRef};
    IntLiteral int0 = makeIntLiteral("0".toCharArray(), source);
    EqualExpression ifFloatCompareIsNot0 = new EqualExpression(floatCompare, int0, OperatorIds.NOT_EQUAL);
    ifFloatCompareIsNot0.sourceStart = pS; ifFloatCompareIsNot0.sourceEnd = pE;
    setGeneratedBy(ifFloatCompareIsNot0, source);
    FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
    setGeneratedBy(falseLiteral, source);
    ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
    setGeneratedBy(returnFalse, source);
    IfStatement ifStatement = new IfStatement(ifFloatCompareIsNot0, returnFalse, pS, pE);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ReturnStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(ReturnStatement returnStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNamereturn);
    final Expression expression = returnStatement.expression;
    if (expression != null) {
        final int numberOfParens = (expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
        if ((numberOfParens != 0 && this.preferences.insert_space_before_parenthesized_expression_in_return)
                || numberOfParens == 0) {
            this.scribe.space();
        }
        expression.traverse(this, scope);
    }
    /*
     * Print the semi-colon
     */
    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    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ReturnStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(ReturnStatement returnStatement, BlockScope scope) {

    this.scribe.printNextToken(TerminalTokens.TokenNamereturn);
    final Expression expression = returnStatement.expression;
    if (expression != null) {
        final int numberOfParens = (expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
        if ((numberOfParens != 0 && this.preferences.insert_space_before_parenthesized_expression_in_return)
                || numberOfParens == 0) {
            this.scribe.space();
        }
        expression.traverse(this, scope);
    }
    /*
     * Print the semi-colon
     */
    this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon);
    this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
    return false;
}
项目:lombok    文件:HandleEqualsAndHashCode.java   
private IfStatement generateCompareFloatOrDouble(Expression thisRef, Expression otherRef, char[] floatOrDouble, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    /* if (Float.compare(fieldName, other.fieldName) != 0) return false */
    MessageSend floatCompare = new MessageSend();
    floatCompare.sourceStart = pS; floatCompare.sourceEnd = pE;
    setGeneratedBy(floatCompare, source);
    floatCompare.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.LANG, floatOrDouble);
    floatCompare.selector = "compare".toCharArray();
    floatCompare.arguments = new Expression[] {thisRef, otherRef};
    IntLiteral int0 = makeIntLiteral("0".toCharArray(), source);
    EqualExpression ifFloatCompareIsNot0 = new EqualExpression(floatCompare, int0, OperatorIds.NOT_EQUAL);
    ifFloatCompareIsNot0.sourceStart = pS; ifFloatCompareIsNot0.sourceEnd = pE;
    setGeneratedBy(ifFloatCompareIsNot0, source);
    FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
    setGeneratedBy(falseLiteral, source);
    ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
    setGeneratedBy(returnFalse, source);
    IfStatement ifStatement = new IfStatement(ifFloatCompareIsNot0, returnFalse, pS, pE);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目: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);
}
项目:EasyMPermission    文件: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);
}
项目:EasyMPermission    文件: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);
}
项目:EasyMPermission    文件: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);
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeStatementReturn() {
    // ReturnStatement ::= 'return' Expressionopt ';'
    // return pushs a position on this.intStack in case there is no expression

    if (this.expressionLengthStack[this.expressionLengthPtr--] != 0) {
        pushOnAstStack(
            new ReturnStatement(
                this.expressionStack[this.expressionPtr--],
                this.intStack[this.intPtr--],
                this.endStatementPosition)
        );
    } else {
        pushOnAstStack(new ReturnStatement(null, this.intStack[this.intPtr--], this.endStatementPosition));
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
    this.handle(
        IProblem.VoidMethodReturnsValue,
        new String[] {new String(expectedType.readableName())},
        new String[] {new String(expectedType.shortReadableName())},
        returnStatement.sourceStart,
        returnStatement.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
    this.handle(
        IProblem.MethodReturnsVoid,
        NoArgument,
        NoArgument,
        returnStatement.sourceStart,
        returnStatement.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void attemptToReturnNonVoidExpression(ReturnStatement returnStatement, TypeBinding expectedType) {
    this.handle(
        IProblem.VoidMethodReturnsValue,
        new String[] {new String(expectedType.readableName())},
        new String[] {new String(expectedType.shortReadableName())},
        returnStatement.sourceStart,
        returnStatement.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void attemptToReturnVoidValue(ReturnStatement returnStatement) {
    this.handle(
        IProblem.MethodReturnsVoid,
        NoArgument,
        NoArgument,
        returnStatement.sourceStart,
        returnStatement.sourceEnd);
}
项目:xapi    文件:GwtAstBuilder.java   
@Override
public void endVisit(ReturnStatement x, BlockScope scope) {
  try {
    SourceInfo info = makeSourceInfo(x);
    JExpression expression = pop(x.expression);
    push(new JReturnStatement(info, expression));
  } catch (Throwable e) {
    throw translateException(x, e);
  }
}
项目:lombok    文件:HandleRelations.java   
private static MethodDeclaration createGetReferencedKeyMethod(ASTNode source, String relatedFieldName, boolean isOneToOne, TypeReference baseType, TypeReference referenceType, CompilationResult compResult) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    MethodDeclaration getReferencedKey = new MethodDeclaration(compResult);
    setGeneratedBy(getReferencedKey, source);       
    getReferencedKey.modifiers = ClassFileConstants.AccPublic;
    getReferencedKey.annotations = new Annotation[] { makeMarkerAnnotation(TypeConstants.JAVA_LANG_OVERRIDE, source) };
    getReferencedKey.returnType = createTypeReference(Long.class, p);
    setGeneratedBy(getReferencedKey.returnType, source);
    getReferencedKey.returnType.sourceStart = pS; getReferencedKey.returnType.sourceEnd = pE;
    getReferencedKey.arguments = new Argument[] {
            new Argument("item".toCharArray(), 0, (isOneToOne ? baseType : referenceType), ClassFileConstants.AccFinal)
    };
    setGeneratedBy(getReferencedKey.arguments[0], source);
    getReferencedKey.arguments[0].sourceStart = pS; getReferencedKey.arguments[0].sourceEnd = pE;
    getReferencedKey.selector = "getReferencedKey".toCharArray();
    getReferencedKey.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    getReferencedKey.bodyStart = getReferencedKey.declarationSourceStart = getReferencedKey.sourceStart = source.sourceStart;
    getReferencedKey.bodyEnd = getReferencedKey.declarationSourceEnd = getReferencedKey.sourceEnd = source.sourceEnd;

    MessageSend getRelatedFieldName = new MessageSend();
    setGeneratedBy(getRelatedFieldName, source);
    getRelatedFieldName.sourceStart = pS; getRelatedFieldName.sourceEnd = pE;
    getRelatedFieldName.receiver = new SingleNameReference("item".toCharArray(), p);
    setGeneratedBy(getRelatedFieldName.receiver, source);
    getRelatedFieldName.receiver.sourceStart = pS; getRelatedFieldName.receiver.sourceEnd = pE;
    getRelatedFieldName.selector = ("get" + toProperCase(relatedFieldName)).toCharArray();

    ReturnStatement returnStatement = new ReturnStatement(getRelatedFieldName, pS, pE);
    setGeneratedBy(returnStatement, source);

    getReferencedKey.statements = new Statement[] { returnStatement };

    return getReferencedKey;
}
项目:lombok-ianchiu    文件:HandleConstructor.java   
public MethodDeclaration createStaticConstructor(AccessLevel level, String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration constructor = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);

    constructor.modifiers = toEclipseModifier(level) | ClassFileConstants.AccStatic;
    TypeDeclaration typeDecl = (TypeDeclaration) type.get();
    constructor.returnType = EclipseHandlerUtil.namePlusTypeParamsToTypeReference(typeDecl.name, typeDecl.typeParameters, p);
    constructor.annotations = null;
    constructor.selector = name.toCharArray();
    constructor.thrownExceptions = null;
    constructor.typeParameters = copyTypeParams(((TypeDeclaration) type.get()).typeParameters, source);
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;

    List<Argument> params = new ArrayList<Argument>();
    List<Expression> assigns = new ArrayList<Expression>();
    AllocationExpression statement = new AllocationExpression();
    statement.sourceStart = pS; statement.sourceEnd = pE;
    statement.type = copyType(constructor.returnType, source);

    for (EclipseNode fieldNode : fields) {
        FieldDeclaration field = (FieldDeclaration) fieldNode.get();
        long fieldPos = (((long) field.sourceStart) << 32) | field.sourceEnd;
        SingleNameReference nameRef = new SingleNameReference(field.name, fieldPos);
        assigns.add(nameRef);

        Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL);
        parameter.annotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN));
        params.add(parameter);
    }

    statement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]);
    constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
    constructor.statements = new Statement[] { new ReturnStatement(statement, (int) (p >> 32), (int)p) };

    constructor.traverse(new SetGeneratedByVisitor(source), typeDecl.scope);
    return constructor;
}
项目:lombok-ianchiu    文件:HandleGetter.java   
public Statement[] createSimpleGetterBody(ASTNode source, EclipseNode fieldNode) {
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
    Statement returnStatement = new ReturnStatement(fieldRef, field.sourceStart, field.sourceEnd);
    return new Statement[] {returnStatement};
}
项目:lombok-ianchiu    文件:HandleSetter.java   
static MethodDeclaration createSetter(TypeDeclaration parent, EclipseNode fieldNode, String name, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    ASTNode source = sourceNode.get();
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    method.modifiers = modifier;
    if (shouldReturnThis) {
        method.returnType = cloneSelfType(fieldNode, source);
    }

    if (method.returnType == null) {
        method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
        method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
        shouldReturnThis = false;
    }
    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
    param.sourceStart = pS; param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
    NameReference fieldNameRef = new SingleNameReference(field.name, p);
    Assignment assignment = new Assignment(fieldRef, fieldNameRef, (int)p);
    assignment.sourceStart = pS; assignment.sourceEnd = assignment.statementEnd = pE;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

    Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
    List<Statement> statements = new ArrayList<Statement>(5);
    if (nonNulls.length == 0) {
        statements.add(assignment);
    } else {
        Statement nullCheck = generateNullCheck(field, sourceNode);
        if (nullCheck != null) statements.add(nullCheck);
        statements.add(assignment);
    }

    if (shouldReturnThis) {
        ThisReference thisRef = new ThisReference(pS, pE);
        ReturnStatement returnThis = new ReturnStatement(thisRef, pS, pE);
        statements.add(returnThis);
    }
    method.statements = statements.toArray(new Statement[0]);
    param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}
项目:lombok-ianchiu    文件:HandleWither.java   
public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam, boolean makeAbstract ) {
    ASTNode source = sourceNode.get();
    if (name == null) return null;
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    if (makeAbstract) modifier = modifier | ClassFileConstants.AccAbstract | ExtraCompilerModifiers.AccSemicolonBody;
    method.modifiers = modifier;
    method.returnType = cloneSelfType(fieldNode, source);
    if (method.returnType == null) return null;

    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    Argument param = new Argument(field.name, p, copyType(field.type, source), ClassFileConstants.AccFinal);
    param.sourceStart = pS; param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;

    Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);

    if (!makeAbstract) {
        List<Expression> args = new ArrayList<Expression>();
        for (EclipseNode child : fieldNode.up().down()) {
            if (child.getKind() != Kind.FIELD) continue;
            FieldDeclaration childDecl = (FieldDeclaration) child.get();
            // Skip fields that start with $
            if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
            long fieldFlags = childDecl.modifiers;
            // Skip static fields.
            if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
            // Skip initialized final fields.
            if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
            if (child.get() == fieldNode.get()) {
                args.add(new SingleNameReference(field.name, p));
            } else {
                args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
            }
        }

        AllocationExpression constructorCall = new AllocationExpression();
        constructorCall.arguments = args.toArray(new Expression[0]);
        constructorCall.type = cloneSelfType(fieldNode, source);

        Expression identityCheck = new EqualExpression(
                createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
                new SingleNameReference(field.name, p),
                OperatorIds.EQUAL_EQUAL);
        ThisReference thisRef = new ThisReference(pS, pE);
        Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
        Statement returnStatement = new ReturnStatement(conditional, pS, pE);
        method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
        method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

        List<Statement> statements = new ArrayList<Statement>(5);
        if (nonNulls.length > 0) {
            Statement nullCheck = generateNullCheck(field, sourceNode);
            if (nullCheck != null) statements.add(nullCheck);
        }
        statements.add(returnStatement);

        method.statements = statements.toArray(new Statement[0]);
    }
    param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private MethodDeclaration generateToBuilderMethod(String methodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, List<BuilderFieldData> builderFields, boolean fluent, ASTNode source) {
    // return new ThingieBuilder<A, B>().setA(this.a).setB(this.b);

    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = methodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);

    Expression receiver = invoke;
    for (BuilderFieldData bfd : builderFields) {
        char[] setterName = fluent ? bfd.name : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray();
        MessageSend ms = new MessageSend();
        if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) {
            char[] fieldName = bfd.obtainVia == null ? bfd.rawName : bfd.obtainVia.field().toCharArray();
            FieldReference fr = new FieldReference(fieldName, 0);
            fr.receiver = new ThisReference(0, 0);
            ms.arguments = new Expression[] {fr};
        } else {
            String obtainName = bfd.obtainVia.method();
            boolean obtainIsStatic = bfd.obtainVia.isStatic();
            MessageSend obtainExpr = new MessageSend();
            obtainExpr.receiver = obtainIsStatic ? new SingleNameReference(type.getName().toCharArray(), 0) : new ThisReference(0, 0);
            obtainExpr.selector = obtainName.toCharArray();
            if (obtainIsStatic) obtainExpr.arguments = new Expression[] {new ThisReference(0, 0)};
            ms.arguments = new Expression[] {obtainExpr};
        }
        ms.receiver = receiver;
        ms.selector = setterName;
        receiver = ms;
    }

    out.statements = new Statement[] {new ReturnStatement(receiver, pS, pE)};

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;

}
项目:lombok-ianchiu    文件:HandleEqualsAndHashCode.java   
public MethodDeclaration createCanEqual(EclipseNode type, ASTNode source, List<Annotation> onParam) {
    /* protected boolean canEqual(final java.lang.Object other) {
     *     return other instanceof Outer.Inner.MyType;
     * }
     */
    int pS = source.sourceStart; int pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    char[] otherName = "other".toCharArray();

    MethodDeclaration method = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    setGeneratedBy(method, source);
    method.modifiers = toEclipseModifier(AccessLevel.PROTECTED);
    method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
    method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
    setGeneratedBy(method.returnType, source);
    method.selector = "canEqual".toCharArray();
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
    TypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { p, p, p });
    setGeneratedBy(objectRef, source);
    method.arguments = new Argument[] {new Argument(otherName, 0, objectRef, Modifier.FINAL)};
    method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
    if (!onParam.isEmpty()) method.arguments[0].annotations = onParam.toArray(new Annotation[0]);
    setGeneratedBy(method.arguments[0], source);

    SingleNameReference otherRef = new SingleNameReference(otherName, p);
    setGeneratedBy(otherRef, source);

    TypeReference typeReference = createTypeReference(type, p);
    setGeneratedBy(typeReference, source);

    InstanceOfExpression instanceOf = new InstanceOfExpression(otherRef, typeReference);
    instanceOf.sourceStart = pS; instanceOf.sourceEnd = pE;
    setGeneratedBy(instanceOf, source);

    ReturnStatement returnStatement = new ReturnStatement(instanceOf, pS, pE);
    setGeneratedBy(returnStatement, source);

    method.statements = new Statement[] {returnStatement};
    return method;
}
项目:lombok-ianchiu    文件:SetGeneratedByVisitor.java   
@Override public boolean visit(ReturnStatement node, BlockScope scope) {
    fixPositions(setGeneratedBy(node, source));
    return super.visit(node, scope);
}
项目:EasyMPermission    文件:HandleConstructor.java   
public MethodDeclaration createStaticConstructor(AccessLevel level, String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    MethodDeclaration constructor = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);

    constructor.modifiers = toEclipseModifier(level) | ClassFileConstants.AccStatic;
    TypeDeclaration typeDecl = (TypeDeclaration) type.get();
    constructor.returnType = EclipseHandlerUtil.namePlusTypeParamsToTypeReference(typeDecl.name, typeDecl.typeParameters, p);
    constructor.annotations = null;
    constructor.selector = name.toCharArray();
    constructor.thrownExceptions = null;
    constructor.typeParameters = copyTypeParams(((TypeDeclaration)type.get()).typeParameters, source);
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;

    List<Argument> params = new ArrayList<Argument>();
    List<Expression> assigns = new ArrayList<Expression>();
    AllocationExpression statement = new AllocationExpression();
    statement.sourceStart = pS; statement.sourceEnd = pE;
    statement.type = copyType(constructor.returnType, source);

    for (EclipseNode fieldNode : fields) {
        FieldDeclaration field = (FieldDeclaration) fieldNode.get();
        long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd;
        SingleNameReference nameRef = new SingleNameReference(field.name, fieldPos);
        assigns.add(nameRef);

        Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL);
        parameter.annotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN));
        params.add(parameter);
    }

    statement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]);
    constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
    constructor.statements = new Statement[] { new ReturnStatement(statement, (int)(p >> 32), (int)p) };

    constructor.traverse(new SetGeneratedByVisitor(source), typeDecl.scope);
    return constructor;
}
项目:EasyMPermission    文件:HandleGetter.java   
public Statement[] createSimpleGetterBody(ASTNode source, EclipseNode fieldNode) {
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
    Statement returnStatement = new ReturnStatement(fieldRef, field.sourceStart, field.sourceEnd);
    return new Statement[] {returnStatement};
}
项目:EasyMPermission    文件:HandleSetter.java   
static MethodDeclaration createSetter(TypeDeclaration parent, EclipseNode fieldNode, String name, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    ASTNode source = sourceNode.get();
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    method.modifiers = modifier;
    if (shouldReturnThis) {
        method.returnType = cloneSelfType(fieldNode, source);
    }

    if (method.returnType == null) {
        method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
        method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
        shouldReturnThis = false;
    }
    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
    param.sourceStart = pS; param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
    NameReference fieldNameRef = new SingleNameReference(field.name, p);
    Assignment assignment = new Assignment(fieldRef, fieldNameRef, (int)p);
    assignment.sourceStart = pS; assignment.sourceEnd = assignment.statementEnd = pE;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

    Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
    List<Statement> statements = new ArrayList<Statement>(5);
    if (nonNulls.length == 0) {
        statements.add(assignment);
    } else {
        Statement nullCheck = generateNullCheck(field, sourceNode);
        if (nullCheck != null) statements.add(nullCheck);
        statements.add(assignment);
    }

    if (shouldReturnThis) {
        ThisReference thisRef = new ThisReference(pS, pE);
        ReturnStatement returnThis = new ReturnStatement(thisRef, pS, pE);
        statements.add(returnThis);
    }
    method.statements = statements.toArray(new Statement[0]);
    param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}
项目:EasyMPermission    文件:HandleWither.java   
public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
    ASTNode source = sourceNode.get();
    if (name == null) return null;
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    method.modifiers = modifier;
    method.returnType = cloneSelfType(fieldNode, source);
    if (method.returnType == null) return null;

    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
    param.sourceStart = pS; param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;

    List<Expression> args = new ArrayList<Expression>();
    for (EclipseNode child : fieldNode.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        FieldDeclaration childDecl = (FieldDeclaration) child.get();
        // Skip fields that start with $
        if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
        long fieldFlags = childDecl.modifiers;
        // Skip static fields.
        if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
        if (child.get() == fieldNode.get()) {
            args.add(new SingleNameReference(field.name, p));
        } else {
            args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
        }
    }

    AllocationExpression constructorCall = new AllocationExpression();
    constructorCall.arguments = args.toArray(new Expression[0]);
    constructorCall.type = cloneSelfType(fieldNode, source);

    Expression identityCheck = new EqualExpression(
            createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
            new SingleNameReference(field.name, p),
            OperatorIds.EQUAL_EQUAL);
    ThisReference thisRef = new ThisReference(pS, pE);
    Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
    Statement returnStatement = new ReturnStatement(conditional, pS, pE);
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

    Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
    List<Statement> statements = new ArrayList<Statement>(5);
    if (nonNulls.length > 0) {
        Statement nullCheck = generateNullCheck(field, sourceNode);
        if (nullCheck != null) statements.add(nullCheck);
    }
    statements.add(returnStatement);

    method.statements = statements.toArray(new Statement[0]);

    param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}
项目:EasyMPermission    文件:HandleEqualsAndHashCode.java   
public MethodDeclaration createCanEqual(EclipseNode type, ASTNode source, List<Annotation> onParam) {
    /* public boolean canEqual(final java.lang.Object other) {
     *     return other instanceof Outer.Inner.MyType;
     * }
     */
    int pS = source.sourceStart; int pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    char[] otherName = "other".toCharArray();

    MethodDeclaration method = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    setGeneratedBy(method, source);
    method.modifiers = toEclipseModifier(AccessLevel.PROTECTED);
    method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
    method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
    setGeneratedBy(method.returnType, source);
    method.selector = "canEqual".toCharArray();
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
    TypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { p, p, p });
    setGeneratedBy(objectRef, source);
    method.arguments = new Argument[] {new Argument(otherName, 0, objectRef, Modifier.FINAL)};
    method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
    if (!onParam.isEmpty()) method.arguments[0].annotations = onParam.toArray(new Annotation[0]);
    setGeneratedBy(method.arguments[0], source);

    SingleNameReference otherRef = new SingleNameReference(otherName, p);
    setGeneratedBy(otherRef, source);

    TypeReference typeReference = createTypeReference(type, p);
    setGeneratedBy(typeReference, source);

    InstanceOfExpression instanceOf = new InstanceOfExpression(otherRef, typeReference);
    instanceOf.sourceStart = pS; instanceOf.sourceEnd = pE;
    setGeneratedBy(instanceOf, source);

    ReturnStatement returnStatement = new ReturnStatement(instanceOf, pS, pE);
    setGeneratedBy(returnStatement, source);

    method.statements = new Statement[] {returnStatement};
    return method;
}
项目:EasyMPermission    文件:SetGeneratedByVisitor.java   
@Override public boolean visit(ReturnStatement node, BlockScope scope) {
    fixPositions(setGeneratedBy(node, source));
    return super.visit(node, scope);
}
项目:Eclipse-Postfix-Code-Completion    文件:SelectionParser.java   
private void buildMoreCompletionContext(Expression expression) {
    ASTNode parentNode = null;

    int kind = topKnownElementKind(SELECTION_OR_ASSIST_PARSER);
    if(kind != 0) {
        int info = topKnownElementInfo(SELECTION_OR_ASSIST_PARSER);
        nextElement : switch (kind) {
            case K_BETWEEN_CASE_AND_COLON :
                if(this.expressionPtr > 0) {
                    SwitchStatement switchStatement = new SwitchStatement();
                    switchStatement.expression = this.expressionStack[this.expressionPtr - 1];
                    if(this.astLengthPtr > -1 && this.astPtr > -1) {
                        int length = this.astLengthStack[this.astLengthPtr];
                        int newAstPtr = this.astPtr - length;
                        ASTNode firstNode = this.astStack[newAstPtr + 1];
                        if(length != 0 && firstNode.sourceStart > switchStatement.expression.sourceEnd) {
                            switchStatement.statements = new Statement[length + 1];
                            System.arraycopy(
                                this.astStack,
                                newAstPtr + 1,
                                switchStatement.statements,
                                0,
                                length);
                        }
                    }
                    CaseStatement caseStatement = new CaseStatement(expression, expression.sourceStart, expression.sourceEnd);
                    if(switchStatement.statements == null) {
                        switchStatement.statements = new Statement[]{caseStatement};
                    } else {
                        switchStatement.statements[switchStatement.statements.length - 1] = caseStatement;
                    }
                    parentNode = switchStatement;
                    this.assistNodeParent = parentNode;
                }
                break nextElement;
            case K_INSIDE_RETURN_STATEMENT :
                if(info == this.bracketDepth) {
                    ReturnStatement returnStatement = new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd);
                    parentNode = returnStatement;
                    this.assistNodeParent = parentNode;
                }
                break nextElement;
            case K_CAST_STATEMENT :
                Expression castType;
                if(this.expressionPtr > 0
                    && ((castType = this.expressionStack[this.expressionPtr-1]) instanceof TypeReference)) {
                    CastExpression cast = new CastExpression(expression, (TypeReference) castType);
                    cast.sourceStart = castType.sourceStart;
                    cast.sourceEnd= expression.sourceEnd;
                    parentNode = cast;
                    this.assistNodeParent = parentNode;
                }
                break nextElement;
        }
    }
    // Do not add assist node/parent into the recovery system if we are inside a lambda. The lambda will be fully recovered including the containing statement and added.
    if (lastIndexOfElement(K_LAMBDA_EXPRESSION_DELIMITER) < 0) {
        if(parentNode != null) {
            this.currentElement = this.currentElement.add((Statement)parentNode, 0);
        } else {
            this.currentElement = this.currentElement.add((Statement)wrapWithExplicitConstructorCallIfNeeded(expression), 0);
            if(this.lastCheckPoint < expression.sourceEnd) {
                this.lastCheckPoint = expression.sourceEnd + 1;
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
private boolean isGuardClause(Block block) {
    return !commentStartsBlock(block.sourceStart, block.sourceEnd)
            && block.statements != null
            && block.statements.length == 1
            && (block.statements[0] instanceof ReturnStatement || block.statements[0] instanceof ThrowStatement);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
    if (this.options.sourceLevel < ClassFileConstants.JDK1_5) { // don't expose type variable names, complain on erased types
        if (actualType instanceof TypeVariableBinding)
            actualType = actualType.erasure();
        if (expectedType instanceof TypeVariableBinding)
            expectedType = expectedType.erasure();
    }
    if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
        if (location instanceof Annotation) {
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376977
            return; // Already reported, don't report a secondary error
        }
        this.handle(
                IProblem.UndefinedType,
                new String[] {new String(actualType.leafComponentType().readableName())},
                new String[] {new String(actualType.leafComponentType().shortReadableName())},
                location.sourceStart,
                location.sourceEnd);
            return;
    }
    if (expectingLocation != null && (expectedType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
        this.handle(
                IProblem.UndefinedType,
                new String[] {new String(expectedType.leafComponentType().readableName())},
                new String[] {new String(expectedType.leafComponentType().shortReadableName())},
                expectingLocation.sourceStart,
                expectingLocation.sourceEnd);
            return;
    }

    char[] actualShortReadableName = actualType.shortReadableName();
    char[] expectedShortReadableName = expectedType.shortReadableName();
    char[] actualReadableName = actualType.readableName();
    char[] expectedReadableName = expectedType.readableName();
    if (CharOperation.equals(actualShortReadableName, expectedShortReadableName)) {
        if (CharOperation.equals(actualReadableName, expectedReadableName)) {
            // if full type names are equal, assume the incompatibility is due to mismatching null annotations:
            actualReadableName = actualType.nullAnnotatedReadableName(this.options, false);
            expectedReadableName = expectedType.nullAnnotatedReadableName(this.options, false);
            actualShortReadableName = actualType.nullAnnotatedReadableName(this.options, true);
            expectedShortReadableName = expectedType.nullAnnotatedReadableName(this.options, true);
        } else {
            actualShortReadableName = actualReadableName;
            expectedShortReadableName = expectedReadableName;
        }
    }
    this.handle(
        expectingLocation instanceof ReturnStatement ? IProblem.ReturnTypeMismatch : IProblem.TypeMismatch,
        new String[] {new String(actualReadableName), new String(expectedReadableName)},
        new String[] {new String(actualShortReadableName), new String(expectedShortReadableName)},
        location.sourceStart,
        location.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
private boolean isGuardClause(Block block) {
    return !commentStartsBlock(block.sourceStart, block.sourceEnd)
            && block.statements != null
            && block.statements.length == 1
            && (block.statements[0] instanceof ReturnStatement || block.statements[0] instanceof ThrowStatement);
}
项目:lombok    文件:HandleConstructor.java   
private MethodDeclaration createStaticConstructor(AccessLevel level, String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    MethodDeclaration constructor = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);

    constructor.modifiers = toEclipseModifier(level) | Modifier.STATIC;
    TypeDeclaration typeDecl = (TypeDeclaration) type.get();
    if (typeDecl.typeParameters != null && typeDecl.typeParameters.length > 0) {
        TypeReference[] refs = new TypeReference[typeDecl.typeParameters.length];
        int idx = 0;
        for (TypeParameter param : typeDecl.typeParameters) {
            TypeReference typeRef = new SingleTypeReference(param.name, (long)param.sourceStart << 32 | param.sourceEnd);
            setGeneratedBy(typeRef, source);
            refs[idx++] = typeRef;
        }
        constructor.returnType = new ParameterizedSingleTypeReference(typeDecl.name, refs, 0, p);
    } else constructor.returnType = new SingleTypeReference(((TypeDeclaration)type.get()).name, p);
    constructor.annotations = null;
    constructor.selector = name.toCharArray();
    constructor.thrownExceptions = null;
    constructor.typeParameters = copyTypeParams(((TypeDeclaration)type.get()).typeParameters, source);
    constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart;
    constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd;

    List<Argument> params = new ArrayList<Argument>();
    List<Expression> assigns = new ArrayList<Expression>();
    AllocationExpression statement = new AllocationExpression();
    statement.sourceStart = pS; statement.sourceEnd = pE;
    statement.type = copyType(constructor.returnType, source);

    for (EclipseNode fieldNode : fields) {
        FieldDeclaration field = (FieldDeclaration) fieldNode.get();
        long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd;
        SingleNameReference nameRef = new SingleNameReference(field.name, fieldPos);
        assigns.add(nameRef);

        Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL);

        Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN));
        if (copiedAnnotations.length != 0) parameter.annotations = copiedAnnotations;
        params.add(parameter);
    }

    statement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]);
    constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
    constructor.statements = new Statement[] { new ReturnStatement(statement, (int)(p >> 32), (int)p) };

    constructor.traverse(new SetGeneratedByVisitor(source), typeDecl.scope);
    return constructor;
}
项目:lombok    文件:HandleWither.java   
private MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, List<Annotation> onMethod, List<Annotation> onParam) {
    if (name == null) return null;
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    method.modifiers = modifier;
    method.returnType = cloneSelfType(fieldNode, source);
    if (method.returnType == null) return null;

    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    if (copiedAnnotations.length != 0) {
        method.annotations = copiedAnnotations;
    }
    Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
    param.sourceStart = pS; param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;

    List<Expression> args = new ArrayList<Expression>();
    for (EclipseNode child : fieldNode.up().down()) {
        if (child.getKind() != Kind.FIELD) continue;
        FieldDeclaration childDecl = (FieldDeclaration) child.get();
        // Skip fields that start with $
        if (childDecl.name != null && childDecl.name.length > 0 && childDecl.name[0] == '$') continue;
        long fieldFlags = childDecl.modifiers;
        // Skip static fields.
        if ((fieldFlags & ClassFileConstants.AccStatic) != 0) continue;
        // Skip initialized final fields.
        if (((fieldFlags & ClassFileConstants.AccFinal) != 0) && childDecl.initialization != null) continue;
        if (child.get() == fieldNode.get()) {
            args.add(new SingleNameReference(field.name, p));
        } else {
            args.add(createFieldAccessor(child, FieldAccess.ALWAYS_FIELD, source));
        }
    }

    AllocationExpression constructorCall = new AllocationExpression();
    constructorCall.arguments = args.toArray(new Expression[0]);
    constructorCall.type = cloneSelfType(fieldNode, source);

    Expression identityCheck = new EqualExpression(
            createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source),
            new SingleNameReference(field.name, p),
            OperatorIds.EQUAL_EQUAL);
    ThisReference thisRef = new ThisReference(pS, pE);
    Expression conditional = new ConditionalExpression(identityCheck, thisRef, constructorCall);
    Statement returnStatement = new ReturnStatement(conditional, pS, pE);
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

    Annotation[] nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN);
    List<Statement> statements = new ArrayList<Statement>(5);
    if (nonNulls.length > 0) {
        Statement nullCheck = generateNullCheck(field, source);
        if (nullCheck != null) statements.add(nullCheck);
    }
    statements.add(returnStatement);

    method.statements = statements.toArray(new Statement[0]);

    Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));
    if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam;

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}
项目:lombok    文件:HandleEqualsAndHashCode.java   
private MethodDeclaration createCanEqual(EclipseNode type, ASTNode source) {
    /* public boolean canEqual(final java.lang.Object other) {
     *     return other instanceof Outer.Inner.MyType;
     * }
     */
    int pS = source.sourceStart; int pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    char[] otherName = "other".toCharArray();

    MethodDeclaration method = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    setGeneratedBy(method, source);
    method.modifiers = toEclipseModifier(AccessLevel.PUBLIC);
    method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
    method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
    setGeneratedBy(method.returnType, source);
    method.selector = "canEqual".toCharArray();
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
    TypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { p, p, p });
    setGeneratedBy(objectRef, source);
    method.arguments = new Argument[] {new Argument(otherName, 0, objectRef, Modifier.FINAL)};
    method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
    setGeneratedBy(method.arguments[0], source);

    SingleNameReference otherRef = new SingleNameReference(otherName, p);
    setGeneratedBy(otherRef, source);

    TypeReference typeReference = createTypeReference(type, p);
    setGeneratedBy(typeReference, source);

    InstanceOfExpression instanceOf = new InstanceOfExpression(otherRef, typeReference);
    instanceOf.sourceStart = pS; instanceOf.sourceEnd = pE;
    setGeneratedBy(instanceOf, source);

    ReturnStatement returnStatement = new ReturnStatement(instanceOf, pS, pE);
    setGeneratedBy(returnStatement, source);

    method.statements = new Statement[] {returnStatement};
    return method;
}