Example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding resolveTypesFor

List of usage examples for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding resolveTypesFor

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding resolveTypesFor.

Prototype

public MethodBinding resolveTypesFor(MethodBinding method) 

Source Link

Usage

From source file:lombok.eclipse.handlers.ast.EclipseTypeEditor.java

License:Open Source License

private AbstractMethodDeclaration injectMethodImpl(final lombok.ast.AbstractMethodDecl<?> methodDecl) {
    final AbstractMethodDeclaration method = builder.build(methodDecl, MethodDeclaration.class);
    EclipseHandlerUtil.injectMethod(node(), method);

    TypeDeclaration type = get();//from   ww w.java 2s  .  com
    if (type.scope != null && method.scope == null) {
        boolean aboutToBeResolved = false;
        for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
            if ("org.eclipse.jdt.internal.compiler.lookup.ClassScope".equals(elem.getClassName())
                    && "buildFieldsAndMethods".equals(elem.getMethodName())) {
                aboutToBeResolved = true;
                break;
            }
        }
        if (!aboutToBeResolved) {
            MethodScope scope = new MethodScope(type.scope, method,
                    methodDecl.getModifiers().contains(lombok.ast.Modifier.STATIC));
            MethodBinding methodBinding = null;
            try {
                methodBinding = (MethodBinding) Reflection.methodScopeCreateMethodMethod.invoke(scope, method);
            } catch (final Exception e) {
                // See 'Reflection' class for why we ignore this exception.
            }
            if (methodBinding != null) {
                SourceTypeBinding sourceType = type.scope.referenceContext.binding;
                MethodBinding[] methods = sourceType.methods();
                methods = resize(methods, methods.length + 1);
                methods[methods.length - 1] = methodBinding;
                sourceType.setMethods(methods);
                sourceType.resolveTypesFor(methodBinding);
            }
        }
    }
    return method;
}