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

项目: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    文件:HandleBuilder.java   
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
    TypeDeclaration td = (TypeDeclaration) builderType.get();
    AbstractMethodDeclaration[] existing = td.methods;
    if (existing == null) existing = EMPTY;
    int len = existing.length;
    FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
    char[] name = fd.name;

    for (int i = 0; i < len; i++) {
        if (!(existing[i] instanceof MethodDeclaration)) continue;
        char[] existingName = existing[i].selector;
        if (Arrays.equals(name, existingName)) return;
    }

    String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());

    MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
        sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
    injectMethod(builderType, setter);
}
项目: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);
}
项目: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    文件:HandleBuilder.java   
private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
    TypeDeclaration td = (TypeDeclaration) builderType.get();
    AbstractMethodDeclaration[] existing = td.methods;
    if (existing == null) existing = EMPTY;
    int len = existing.length;
    FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
    char[] name = fd.name;

    for (int i = 0; i < len; i++) {
        if (!(existing[i] instanceof MethodDeclaration)) continue;
        char[] existingName = existing[i].selector;
        if (Arrays.equals(name, existingName)) return;
    }

    String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());

    MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
            sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
    injectMethod(builderType, setter);
}
项目:android-retrolambda-lombok    文件:EcjTreeBuilder.java   
static VariableKind kind(lombok.ast.VariableDefinition node) {
    //TODO rewrite this whole thing.
    lombok.ast.Node parent = node.getParent();
    if (parent instanceof lombok.ast.VariableDeclaration) {
        if (parent.getParent() instanceof lombok.ast.TypeBody ||
            parent.getParent() instanceof lombok.ast.EnumTypeBody) {
            return FIELD;
        } else {
            return LOCAL;
        }
    }
    if (parent instanceof lombok.ast.For || 
        parent instanceof lombok.ast.ForEach){
        return LOCAL;
    }
    if (parent instanceof lombok.ast.Catch ||
        parent instanceof lombok.ast.MethodDeclaration ||
        parent instanceof lombok.ast.ConstructorDeclaration){
        return ARGUMENT;
    }
    return UNSUPPORTED;
}
项目:Eclipse-Postfix-Code-Completion    文件:ClassFile.java   
/**
 * INTERNAL USE-ONLY
 * Generate the byte for problem method infos that correspond to missing abstract methods.
 * http://dev.eclipse.org/bugs/show_bug.cgi?id=3179
 *
 * @param methodDeclarations Array of all missing abstract methods
 */
public void generateMissingAbstractMethods(MethodDeclaration[] methodDeclarations, CompilationResult compilationResult) {
    if (methodDeclarations != null) {
        TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext;
        int typeDeclarationSourceStart = currentDeclaration.sourceStart();
        int typeDeclarationSourceEnd = currentDeclaration.sourceEnd();
        for (int i = 0, max = methodDeclarations.length; i < max; i++) {
            MethodDeclaration methodDeclaration = methodDeclarations[i];
            MethodBinding methodBinding = methodDeclaration.binding;
             String readableName = new String(methodBinding.readableName());
             CategorizedProblem[] problems = compilationResult.problems;
             int problemsCount = compilationResult.problemCount;
            for (int j = 0; j < problemsCount; j++) {
                CategorizedProblem problem = problems[j];
                if (problem != null
                        && problem.getID() == IProblem.AbstractMethodMustBeImplemented
                        && problem.getMessage().indexOf(readableName) != -1
                        && problem.getSourceStart() >= typeDeclarationSourceStart
                        && problem.getSourceEnd() <= typeDeclarationSourceEnd) {
                    // we found a match
                    addMissingAbstractProblemMethod(methodDeclaration, methodBinding, problem, compilationResult);
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredMethod.java   
void attach(TypeParameter[] parameters, int startPos) {
    if(this.methodDeclaration.modifiers != ClassFileConstants.AccDefault) return;

    int lastParameterEnd = parameters[parameters.length - 1].sourceEnd;

    Parser parser = parser();
    Scanner scanner = parser.scanner;
    if(Util.getLineNumber(this.methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr)
            != Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return;

    if(parser.modifiersSourceStart > lastParameterEnd
            && parser.modifiersSourceStart < this.methodDeclaration.declarationSourceStart) return;

    if (this.methodDeclaration instanceof MethodDeclaration) {
        ((MethodDeclaration)this.methodDeclaration).typeParameters = parameters;
        this.methodDeclaration.declarationSourceStart = startPos;
    } else if (this.methodDeclaration instanceof ConstructorDeclaration){
        ((ConstructorDeclaration)this.methodDeclaration).typeParameters = parameters;
        this.methodDeclaration.declarationSourceStart = startPos;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeMethodHeaderDefaultValue() {
    // MethodHeaderDefaultValue ::= DefaultValue
    MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];


    int length = this.expressionLengthStack[this.expressionLengthPtr--];
    if (length == 1) {
        this.intPtr--; // we get rid of the position of the default keyword
        this.intPtr--; // we get rid of the position of the default keyword
        if(md.isAnnotationMethod()) {
            ((AnnotationMethodDeclaration)md).defaultValue = this.expressionStack[this.expressionPtr];
            md.modifiers |=  ClassFileConstants.AccAnnotationDefault;
        }
        this.expressionPtr--;
        this.recordStringLiterals = true;
    }

    if(this.currentElement != null) {
        if(md.isAnnotationMethod()) {
            this.currentElement.updateSourceEndIfNecessary(((AnnotationMethodDeclaration)md).defaultValue.sourceEnd);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeMethodHeaderExtendedDims() {
    // MethodHeaderExtendedDims ::= Dimsopt
    // now we update the returnType of the method
    MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr];
    int extendedDimensions = this.intStack[this.intPtr--];
    if(md.isAnnotationMethod()) {
        ((AnnotationMethodDeclaration)md).extendedDimensions = extendedDimensions;
    }
    if (extendedDimensions != 0) {
        md.sourceEnd = this.endPosition;
        md.returnType = augmentTypeWithAdditionalDimensions(md.returnType, extendedDimensions, getAnnotationsOnDimensions(extendedDimensions), false);
        md.bits |= (md.returnType.bits & ASTNode.HasTypeAnnotations);
        if (this.currentToken == TokenNameLBRACE){
            md.bodyStart = this.endPosition + 1;
        }
        // recovery
        if (this.currentElement != null){
            this.lastCheckPoint = md.bodyStart;
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
public MethodDeclaration convertToMethodDeclaration(ConstructorDeclaration c, CompilationResult compilationResult) {
    MethodDeclaration m = new MethodDeclaration(compilationResult);
    m.typeParameters = c.typeParameters;
    m.sourceStart = c.sourceStart;
    m.sourceEnd = c.sourceEnd;
    m.bodyStart = c.bodyStart;
    m.bodyEnd = c.bodyEnd;
    m.declarationSourceEnd = c.declarationSourceEnd;
    m.declarationSourceStart = c.declarationSourceStart;
    m.selector = c.selector;
    m.statements = c.statements;
    m.modifiers = c.modifiers;
    m.annotations = c.annotations;
    m.arguments = c.arguments;
    m.thrownExceptions = c.thrownExceptions;
    m.explicitDeclarations = c.explicitDeclarations;
    m.returnType = null;
    m.javadoc = c.javadoc;
    m.bits = c.bits;
    return m;
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void invalidAnnotationMemberType(MethodDeclaration methodDecl) {
    this.handle(
        IProblem.InvalidAnnotationMemberType,
        new String[] {
            new String(methodDecl.binding.returnType.readableName()),
            new String(methodDecl.selector),
            new String(methodDecl.binding.declaringClass.readableName()),
        },
        new String[] {
            new String(methodDecl.binding.returnType.shortReadableName()),
            new String(methodDecl.selector),
            new String(methodDecl.binding.declaringClass.shortReadableName()),
        },
        methodDecl.returnType.sourceStart,
        methodDecl.returnType.sourceEnd);

}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void methodCanBeDeclaredStatic(MethodDeclaration methodDecl) {
    int severity = computeSeverity(IProblem.MethodCanBeStatic);
    if (severity == ProblemSeverities.Ignore) return;
    MethodBinding method = methodDecl.binding;
    this.handle(
            IProblem.MethodCanBeStatic,
        new String[] {
            new String(method.declaringClass.readableName()),
            new String(method.selector),
            typesAsString(method, false)
         },
        new String[] {
            new String(method.declaringClass.shortReadableName()),
            new String(method.selector),
            typesAsString(method, true)
         },
        severity,
        methodDecl.sourceStart,
        methodDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void methodCanBePotentiallyDeclaredStatic(MethodDeclaration methodDecl) {
    int severity = computeSeverity(IProblem.MethodCanBePotentiallyStatic);
    if (severity == ProblemSeverities.Ignore) return;
    MethodBinding method = methodDecl.binding;
    this.handle(
            IProblem.MethodCanBePotentiallyStatic,
        new String[] {
            new String(method.declaringClass.readableName()),
            new String(method.selector),
            typesAsString(method, false)
         },
        new String[] {
            new String(method.declaringClass.shortReadableName()),
            new String(method.selector),
            typesAsString(method, true)
         },
        severity,
        methodDecl.sourceStart,
        methodDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void parseErrorUnexpectedEnd(
    int start,
    int end){

    String[] arguments;
    if(this.referenceContext instanceof ConstructorDeclaration) {
        arguments = new String[] {Messages.parser_endOfConstructor};
    } else if(this.referenceContext instanceof MethodDeclaration) {
        arguments = new String[] {Messages.parser_endOfMethod};
    } else if(this.referenceContext instanceof TypeDeclaration) {
        arguments = new String[] {Messages.parser_endOfInitializer};
    } else {
        arguments = new String[] {Messages.parser_endOfFile};
    }
    this.handle(
        IProblem.ParsingErrorUnexpectedEOF,
        arguments,
        arguments,
        start,
        end);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void illegalReturnRedefinition(AbstractMethodDeclaration abstractMethodDecl, MethodBinding inheritedMethod, char[][] nonNullAnnotationName) {
    MethodDeclaration methodDecl = (MethodDeclaration) abstractMethodDecl;
    StringBuffer methodSignature = new StringBuffer();
    methodSignature
        .append(inheritedMethod.declaringClass.readableName())
        .append('.')
        .append(inheritedMethod.readableName());

    StringBuffer shortSignature = new StringBuffer();
    shortSignature
        .append(inheritedMethod.declaringClass.shortReadableName())
        .append('.')
        .append(inheritedMethod.shortReadableName());
    int sourceStart = methodDecl.returnType.sourceStart;
    Annotation[] annotations = methodDecl.annotations;
    Annotation annotation = findAnnotation(annotations, TypeIds.T_ConfiguredAnnotationNullable);
    if (annotation != null) {
        sourceStart = annotation.sourceStart;
    }
    this.handle(
        IProblem.IllegalReturnNullityRedefinition, 
        new String[] { methodSignature.toString(), CharOperation.toString(nonNullAnnotationName)},
        new String[] { shortSignature.toString(), new String(nonNullAnnotationName[nonNullAnnotationName.length-1])},
        sourceStart,
        methodDecl.returnType.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AnnotationDiscoveryVisitor.java   
@Override
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
    Annotation[] annotations = methodDeclaration.annotations;
    if (annotations != null) {
        MethodBinding methodBinding = methodDeclaration.binding;
        if (methodBinding == null) {
            return false;
        }
        ((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
        this.resolveAnnotations(
                methodDeclaration.scope,
                annotations,
                methodBinding);
    }

    Argument[] arguments = methodDeclaration.arguments;
    if (arguments != null) {
        int argumentLength = arguments.length;
        for (int i = 0; i < argumentLength; i++) {
            arguments[i].traverse(this, methodDeclaration.scope);
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ClassFile.java   
/**
 * INTERNAL USE-ONLY
 * Generate the byte for problem method infos that correspond to missing abstract methods.
 * http://dev.eclipse.org/bugs/show_bug.cgi?id=3179
 *
 * @param methodDeclarations Array of all missing abstract methods
 */
public void generateMissingAbstractMethods(MethodDeclaration[] methodDeclarations, CompilationResult compilationResult) {
    if (methodDeclarations != null) {
        TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext;
        int typeDeclarationSourceStart = currentDeclaration.sourceStart();
        int typeDeclarationSourceEnd = currentDeclaration.sourceEnd();
        for (int i = 0, max = methodDeclarations.length; i < max; i++) {
            MethodDeclaration methodDeclaration = methodDeclarations[i];
            MethodBinding methodBinding = methodDeclaration.binding;
             String readableName = new String(methodBinding.readableName());
             CategorizedProblem[] problems = compilationResult.problems;
             int problemsCount = compilationResult.problemCount;
            for (int j = 0; j < problemsCount; j++) {
                CategorizedProblem problem = problems[j];
                if (problem != null
                        && problem.getID() == IProblem.AbstractMethodMustBeImplemented
                        && problem.getMessage().indexOf(readableName) != -1
                        && problem.getSourceStart() >= typeDeclarationSourceStart
                        && problem.getSourceEnd() <= typeDeclarationSourceEnd) {
                    // we found a match
                    addMissingAbstractProblemMethod(methodDeclaration, methodBinding, problem, compilationResult);
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredMethod.java   
void attach(TypeParameter[] parameters, int startPos) {
    if(this.methodDeclaration.modifiers != ClassFileConstants.AccDefault) return;

    int lastParameterEnd = parameters[parameters.length - 1].sourceEnd;

    Parser parser = parser();
    Scanner scanner = parser.scanner;
    if(Util.getLineNumber(this.methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr)
            != Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return;

    if(parser.modifiersSourceStart > lastParameterEnd
            && parser.modifiersSourceStart < this.methodDeclaration.declarationSourceStart) return;

    if (this.methodDeclaration instanceof MethodDeclaration) {
        ((MethodDeclaration)this.methodDeclaration).typeParameters = parameters;
        this.methodDeclaration.declarationSourceStart = startPos;
    } else if (this.methodDeclaration instanceof ConstructorDeclaration){
        ((ConstructorDeclaration)this.methodDeclaration).typeParameters = parameters;
        this.methodDeclaration.declarationSourceStart = startPos;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void invalidAnnotationMemberType(MethodDeclaration methodDecl) {
    this.handle(
        IProblem.InvalidAnnotationMemberType,
        new String[] {
            new String(methodDecl.binding.returnType.readableName()),
            new String(methodDecl.selector),
            new String(methodDecl.binding.declaringClass.readableName()),
        },
        new String[] {
            new String(methodDecl.binding.returnType.shortReadableName()),
            new String(methodDecl.selector),
            new String(methodDecl.binding.declaringClass.shortReadableName()),
        },
        methodDecl.returnType.sourceStart,
        methodDecl.returnType.sourceEnd);

}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void methodCanBeDeclaredStatic(MethodDeclaration methodDecl) {
    int severity = computeSeverity(IProblem.MethodCanBeStatic);
    if (severity == ProblemSeverities.Ignore) return;
    MethodBinding method = methodDecl.binding;
    this.handle(
            IProblem.MethodCanBeStatic,
        new String[] {
            new String(method.declaringClass.readableName()),
            new String(method.selector),
            typesAsString(method, false)
         },
        new String[] {
            new String(method.declaringClass.shortReadableName()),
            new String(method.selector),
            typesAsString(method, true)
         },
        severity,
        methodDecl.sourceStart,
        methodDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void methodCanBePotentiallyDeclaredStatic(MethodDeclaration methodDecl) {
    int severity = computeSeverity(IProblem.MethodCanBePotentiallyStatic);
    if (severity == ProblemSeverities.Ignore) return;
    MethodBinding method = methodDecl.binding;
    this.handle(
            IProblem.MethodCanBePotentiallyStatic,
        new String[] {
            new String(method.declaringClass.readableName()),
            new String(method.selector),
            typesAsString(method, false)
         },
        new String[] {
            new String(method.declaringClass.shortReadableName()),
            new String(method.selector),
            typesAsString(method, true)
         },
        severity,
        methodDecl.sourceStart,
        methodDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void parseErrorUnexpectedEnd(
    int start,
    int end){

    String[] arguments;
    if(this.referenceContext instanceof ConstructorDeclaration) {
        arguments = new String[] {Messages.parser_endOfConstructor};
    } else if(this.referenceContext instanceof MethodDeclaration) {
        arguments = new String[] {Messages.parser_endOfMethod};
    } else if(this.referenceContext instanceof TypeDeclaration) {
        arguments = new String[] {Messages.parser_endOfInitializer};
    } else {
        arguments = new String[] {Messages.parser_endOfFile};
    }
    this.handle(
        IProblem.ParsingErrorUnexpectedEOF,
        arguments,
        arguments,
        start,
        end);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void illegalReturnRedefinition(AbstractMethodDeclaration abstractMethodDecl, MethodBinding inheritedMethod, char[][] nonNullAnnotationName) {
    MethodDeclaration methodDecl = (MethodDeclaration) abstractMethodDecl;
    StringBuffer methodSignature = new StringBuffer();
    methodSignature
        .append(inheritedMethod.declaringClass.readableName())
        .append('.')
        .append(inheritedMethod.readableName());

    StringBuffer shortSignature = new StringBuffer();
    shortSignature
        .append(inheritedMethod.declaringClass.shortReadableName())
        .append('.')
        .append(inheritedMethod.shortReadableName());
    int sourceStart = methodDecl.returnType.sourceStart;
    Annotation[] annotations = methodDecl.annotations;
    Annotation annotation = findAnnotation(annotations, TypeIds.T_ConfiguredAnnotationNullable);
    if (annotation != null) {
        sourceStart = annotation.sourceStart;
    }
    this.handle(
        IProblem.IllegalReturnNullityRedefinition, 
        new String[] { methodSignature.toString(), CharOperation.toString(nonNullAnnotationName)},
        new String[] { shortSignature.toString(), new String(nonNullAnnotationName[nonNullAnnotationName.length-1])},
        sourceStart,
        methodDecl.returnType.sourceEnd);
}
项目:xapi    文件:GwtAstBuilder.java   
@Override
public boolean visit(MethodDeclaration x, ClassScope scope) {
  try {
    JMethod method = typeMap.get(x.binding);
    assert !method.isExternal();
    JMethodBody body = null;
    if (!method.isNative()) {
      body = new JMethodBody(method.getSourceInfo());
      method.setBody(body);
    }
    pushMethodInfo(new MethodInfo(method, body, x.scope));

    // Map user arguments.
    Iterator<JParameter> it = method.getParams().iterator();
    if (x.arguments != null) {
      for (Argument argument : x.arguments) {
        curMethod.locals.put(argument.binding, it.next());
      }
    }
    x.statements = reduceToReachable(x.statements);
    return true;
  } catch (Throwable e) {
    throw translateException(x, e);
  }
}
项目:xapi    文件:GwtAstBuilder.java   
private void processNativeMethod(MethodDeclaration x) {
  JMethod method = curMethod.method;
  JsniMethod jsniMethod = jsniMethods.get(x);
  assert jsniMethod != null;
  SourceInfo info = method.getSourceInfo();
  JsFunction jsFunction = jsniMethod.function();
  JsniMethodBody body = new JsniMethodBody(info);
  method.setBody(body);
  jsFunction.setFromJava(true);
  body.setFunc(jsFunction);
  // Resolve locals, params, and JSNI.
  JsParameterResolver localResolver = new JsParameterResolver(jsFunction);
  localResolver.accept(jsFunction);
  JsniResolver jsniResolver = new JsniResolver(body);
  jsniResolver.accept(jsFunction);
}
项目:lombok-ianchiu    文件:PatchDelegate.java   
private static void generateDelegateMethods(EclipseNode typeNode, List<BindingTuple> methods, DelegateReceiver delegateReceiver) {
    CompilationUnitDeclaration top = (CompilationUnitDeclaration) typeNode.top().get();
    for (BindingTuple pair : methods) {
        EclipseNode annNode = typeNode.getAst().get(pair.responsible);
        MethodDeclaration method = createDelegateMethod(pair.fieldName, typeNode, pair, top.compilationResult, annNode, delegateReceiver);
        if (method != null) { 
            SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(annNode.get());
            method.traverse(visitor, ((TypeDeclaration)typeNode.get()).scope);
            injectMethod(typeNode, method);
        }
    }
}
项目:lombok-ianchiu    文件:HandleSynchronized.java   
@Override public void preHandle(AnnotationValues<Synchronized> annotation, Annotation source, EclipseNode annotationNode) {
    EclipseNode methodNode = annotationNode.up();
    if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) return;
    MethodDeclaration method = (MethodDeclaration)methodNode.get();
    if (method.isAbstract()) return;

    createLockField(annotation, annotationNode, method.isStatic(), false);
}
项目: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    文件: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);
}
项目:EasyMPermission    文件:PatchDelegate.java   
private static void generateDelegateMethods(EclipseNode typeNode, List<BindingTuple> methods, DelegateReceiver delegateReceiver) {
    CompilationUnitDeclaration top = (CompilationUnitDeclaration) typeNode.top().get();
    for (BindingTuple pair : methods) {
        EclipseNode annNode = typeNode.getAst().get(pair.responsible);
        MethodDeclaration method = createDelegateMethod(pair.fieldName, typeNode, pair, top.compilationResult, annNode, delegateReceiver);
        if (method != null) { 
            SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(annNode.get());
            method.traverse(visitor, ((TypeDeclaration)typeNode.get()).scope);
            injectMethod(typeNode, method);
        }
    }
}
项目:EasyMPermission    文件:HandleSynchronized.java   
@Override public void preHandle(AnnotationValues<Synchronized> annotation, Annotation source, EclipseNode annotationNode) {
    EclipseNode methodNode = annotationNode.up();
    if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) return;
    MethodDeclaration method = (MethodDeclaration)methodNode.get();
    if (method.isAbstract()) return;

    createLockField(annotation, annotationNode, method.isStatic(), false);
}
项目:EasyMPermission    文件: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);
}
项目:EasyMPermission    文件: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);
}
项目:Eclipse-Postfix-Code-Completion    文件:AnnotationDiscoveryVisitor.java   
@Override
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
    Annotation[] annotations = methodDeclaration.annotations;
    if (annotations != null) {
        MethodBinding methodBinding = methodDeclaration.binding;
        if (methodBinding == null) {
            return false;
        }
        ((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
        this.resolveAnnotations(
                methodDeclaration.scope,
                annotations,
                methodBinding);
    }

    TypeParameter[] typeParameters = methodDeclaration.typeParameters;
    if (typeParameters != null) {
        int typeParametersLength = typeParameters.length;
        for (int i = 0; i < typeParametersLength; i++) {
            typeParameters[i].traverse(this, methodDeclaration.scope);
        }
    }

    Argument[] arguments = methodDeclaration.arguments;
    if (arguments != null) {
        int argumentLength = arguments.length;
        for (int i = 0; i < argumentLength; i++) {
            arguments[i].traverse(this, methodDeclaration.scope);
        }
    }
    return false;
}