Example usage for org.eclipse.jdt.core.dom MethodDeclaration setProperty

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration setProperty

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MethodDeclaration setProperty.

Prototype

public final void setProperty(String propertyName, Object data) 

Source Link

Document

Sets the named property of this node to the given value, or to null to clear it.

Usage

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java

License:Open Source License

private static ASTVisitor getInterceptingVisitor(final VisitingContext context,
        final ExecutionFlowDescription flowDescription, final ExecutionFlowFrameVisitor visitor) {
    // check cache
    {// w  ww. j av a  2s. co m
        ASTVisitor interceptingVisitor = m_interceptingVisitors.get(visitor);
        if (interceptingVisitor != null) {
            return interceptingVisitor;
        }
    }
    // create new
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(ExecutionFlowUtils.class.getClassLoader());
    enhancer.setSuperclass(ASTVisitor.class);
    enhancer.setCallback(new MethodInterceptor() {
        public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args, MethodProxy proxy)
                throws Throwable {
            // routing
            Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length == 1) {
                Class<?> parameterType = parameterTypes[0];
                if (method.getName().equals("visit")) {
                    if (parameterType == AnonymousClassDeclaration.class) {
                        visit((AnonymousClassDeclaration) args[0]);
                    }
                } else if (method.getName().equals("endVisit")) {
                    if (parameterType == ClassInstanceCreation.class) {
                        endVisit((ClassInstanceCreation) args[0]);
                    } else if (parameterType == MethodInvocation.class) {
                        endVisit((MethodInvocation) args[0]);
                    } else if (parameterType == ConstructorInvocation.class) {
                        endVisit((ConstructorInvocation) args[0]);
                    }
                }
            }
            // use main visitor
            try {
                return method.invoke(visitor, args);
            } catch (InvocationTargetException e) {
                throw e.getCause();
            }
        }

        private boolean visit(AnonymousClassDeclaration node) {
            return shouldVisitAnonymousClassDeclaration(node);
        }

        private void endVisit(ClassInstanceCreation node) {
            // quick check
            {
                String identifier = flowDescription.geTypeDeclaration().getName().getIdentifier();
                if (!node.toString().contains(identifier)) {
                    return;
                }
            }
            // check for local constructor
            MethodDeclaration methodDeclaration = getLocalConstructorDeclaration(node);
            if (methodDeclaration != null) {
                // redirect execution flow to constructor
                ExecutionFlowUtils.visit(context, flowDescription, visitor,
                        ImmutableList.of(methodDeclaration));
            }
        }

        private void endVisit(MethodInvocation node) {
            // check for local method invocation
            MethodDeclaration methodDeclaration = getLocalMethodDeclaration(node);
            if (methodDeclaration != null) {
                methodDeclaration.setProperty(KEY_FRAME_INVOCATION, node);
                // check for qualified local invocation, for example "appl.open()", so visit it as type
                if (node.getExpression() != null && !(node.getExpression() instanceof ThisExpression)) {
                    ExecutionFlowUtils.visit(context, flowDescription, visitor,
                            ImmutableList.of(methodDeclaration));
                } else {
                    ExecutionFlowUtils.visit(context, flowDescription, visitor, methodDeclaration);
                }
            }
        }

        private void endVisit(ConstructorInvocation node) {
            MethodDeclaration constructor = getConstructor(node);
            constructor.setProperty(KEY_FRAME_INVOCATION, node);
            ExecutionFlowUtils.visit(context, flowDescription, visitor, ImmutableList.of(constructor));
        }
    });
    ASTVisitor interceptingVisitor = (ASTVisitor) enhancer.create();
    m_interceptingVisitors.put(visitor, interceptingVisitor);
    return interceptingVisitor;
}

From source file:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java

License:Open Source License

/**
 * Sets the value associated with {@link Expression} of {@link ReturnStatement} during AST
 * evaluation.//www  .  ja  v  a 2s  . c  o m
 */
private static void setReturnValue(MethodDeclaration methodDeclaration, Object value) {
    methodDeclaration.setProperty(KEY_RETURN_VALUE, value);
}

From source file:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java

License:Open Source License

/**
 * Specifies if {@link ReturnStatement} of given {@link MethodDeclaration} should be evaluated.
 *//*from  ww w . jav a2 s .c  om*/
public static void shouldEvaluateReturnValue(MethodDeclaration methodDeclaration, boolean evaluate) {
    methodDeclaration.setProperty(KEY_EVALUATE_RETURN_VALUE, evaluate ? Boolean.TRUE : null);
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

License:Open Source License

/**
 * When we parse existing {@link MethodDeclaration} we should ensure that it is not added into
 * parsing context, or this will cause duplicate method compilation problem
 *//*  w w w  .jav  a 2 s.  c om*/
private MethodDeclaration parseExistingMethod(MethodDeclaration method) throws Exception {
    method.setProperty(AstParser.KEY_IGNORE_THIS_METHOD, Boolean.TRUE);
    try {
        return (MethodDeclaration) m_parser.parseBodyDeclaration(method.getStartPosition(), "");
    } finally {
        method.setProperty(AstParser.KEY_IGNORE_THIS_METHOD, null);
    }
}

From source file:org.iti.rsbp.extension.rs.gbsp.utils.MethodUtils.java

License:Open Source License

private static MethodDeclaration getMethodDeclaration(List<ICompilationUnit> compilationUnits,
        IMethodBinding declarationBinding) {
    for (ICompilationUnit compilationUnit : compilationUnits) {
        CompilationUnit cu = ParserUtils.parse(compilationUnit);
        MethodDeclaration declarationNode = (MethodDeclaration) cu
                .findDeclaringNode(declarationBinding.getKey());

        if (declarationNode != null) {
            try {
                declarationNode.setProperty(IBindingInformation.ICOMPILATION_PROPERTY, compilationUnit);
            } catch (NullPointerException ex) {
                System.out.println("Eeek!!!");
            }/*from w w w  . ja va2  s  .  c  o  m*/

            return declarationNode;
        }
    }

    return null;
}