Java Code Examples for org.codehaus.groovy.ast.FieldNode#hasInitialExpression()

The following examples show how to use org.codehaus.groovy.ast.FieldNode#hasInitialExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeInferenceVisitor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void visitField(FieldNode node) {
    if (sameVariableName(leaf, node)) {
        if (node.hasInitialExpression()){
            Expression expression = node.getInitialExpression();
            if (expression instanceof ConstantExpression
                    && !expression.getText().equals("null")) { // NOI18N
                guessedType = ((ConstantExpression) expression).getType();
            } else if (expression instanceof ConstructorCallExpression) {
                guessedType = ((ConstructorCallExpression) expression).getType();
            } else if (expression instanceof MethodCallExpression) {
                int newOffset = ASTUtils.getOffset(doc, expression.getLineNumber(), expression.getColumnNumber());
                AstPath newPath = new AstPath(path.root(), newOffset, doc);
                guessedType = MethodInference.findCallerType(expression, newPath, doc, newOffset);
            }
        }
    }
}
 
Example 2
Source File: SourceURIASTTransformation.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void setScriptURIOnField(final FieldNode fieldNode, final AnnotationNode node) {
    if (fieldNode.hasInitialExpression()) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", fieldNode);
        return;
    }

    URI uri = getSourceURI(node);

    if (uri == null) {
        addError("Unable to get the URI for the source of this class!", fieldNode);
    } else {
        // Set the RHS to '= URI.create("string for this URI")'.
        // That may throw an IllegalArgumentExpression wrapping the URISyntaxException.
        fieldNode.setInitialValueExpression(getExpression(uri));
    }
}
 
Example 3
Source File: AutoFinalASTTransformation.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void processField(FieldNode fNode, ClassCodeVisitorSupport visitor) {
    if (!isEnabled(fNode)) return;
    if (fNode.hasInitialExpression() && fNode.getInitialExpression() instanceof ClosureExpression) {
        visitor.visitField(fNode);
    }
}