public String toString() { return super.toString() + "[variable: " + variable + (this.isDynamicTyped() ? "" : " type: " + getType()) + "]"; }
public void visitVariableExpression(final VariableExpression expression) { assertExpressionAuthorized(expression); final String type = expression.getType().getName(); if (constantTypesWhiteList != null && !constantTypesWhiteList.contains(type)) { throw new SecurityException("Usage of variables of type [" + type + "] is not allowed"); } if (constantTypesBlackList != null && constantTypesBlackList.contains(type)) { throw new SecurityException("Usage of variables of type [" + type + "] is not allowed"); } }
@Override public void visitVariableExpression(VariableExpression expression) { super.visitVariableExpression(expression); addToCache(expression.getType()); } @Override
private VariableExpression createDataProcessorVariable(Expression varExpr, ASTNode sourcePos) throws InvalidSpecCompileException { if (!(varExpr instanceof VariableExpression)) notAParameterization(sourcePos); VariableExpression typedVarExpr = (VariableExpression)varExpr; verifyDataProcessorVariable(typedVarExpr); VariableExpression result = new VariableExpression(typedVarExpr.getName(), typedVarExpr.getType()); dataProcessorVars.add(result); return result; }
private static ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) { if (!(arg instanceof VariableExpression)) return arg.getType(); VariableExpression vexp = (VariableExpression) arg; String name = vexp.getName(); for (Parameter param : node.getParameters()) { if (param.getName().equals(name)) { return param.getType(); } } return vexp.getType(); }
@Override public void visitDeclarationExpression(DeclarationExpression expression) { if (expression.isMultipleAssignmentDeclaration()) { TupleExpression tExpr = expression.getTupleExpression(); for (Expression nextExpr : tExpr.getExpressions()) { ClassNode declType = nextExpr.getType(); checkGenericsUsage(declType, declType.redirect()); } } else { ClassNode declType = expression.getVariableExpression().getType(); checkGenericsUsage(declType, declType.redirect()); } super.visitDeclarationExpression(expression); }
private void changeBaseScriptTypeFromDeclaration(final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } Expression value = node.getMember("value"); if (value != null) { addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value); return; } ClassNode cNode = de.getDeclaringClass(); ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference(); de.setRightExpression(new VariableExpression("this")); changeBaseScriptType(de, cNode, baseScriptType); }
public ClassNode resolveType(final Expression exp, final ClassNode current) { if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type; OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class); ClassNode type = null; if (meta != null) type = meta.type; if (type != null) return type; if (exp instanceof VariableExpression) { VariableExpression ve = (VariableExpression) exp; if (ve.isClosureSharedVariable()) return ve.getType(); type = ve.getOriginType(); if (ve.getAccessedVariable() instanceof FieldNode) { FieldNode fn = (FieldNode) ve.getAccessedVariable(); if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType(); } } else if (exp instanceof Variable) { Variable v = (Variable) exp; type = v.getOriginType(); } else { type = exp.getType(); } return type.redirect(); } }
private ClassNode checkForTargetType(final Expression expr, final ClassNode type) { BinaryExpression enclosingBinaryExpression = typeCheckingContext.getEnclosingBinaryExpression(); if (enclosingBinaryExpression instanceof DeclarationExpression && isEmptyCollection(expr) && isAssignment(enclosingBinaryExpression.getOperation().getType())) { VariableExpression target = (VariableExpression) enclosingBinaryExpression.getLeftExpression(); return adjustForTargetType(target.getType(), type); } if (currentField != null) { return adjustForTargetType(currentField.getType(), type); } if (currentProperty != null) { return adjustForTargetType(currentProperty.getType(), type); } MethodNode enclosingMethod = typeCheckingContext.getEnclosingMethod(); if (enclosingMethod != null) { return adjustForTargetType(enclosingMethod.getReturnType(), type); } return type; }
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) { if (de.isMultipleAssignmentDeclaration()) { addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de); return; } ClassNode cNode = de.getDeclaringClass(); ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference(); if (baseScriptType.isScript()) { if (!(de.getRightExpression() instanceof EmptyExpression)) { addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de); return; } de.setRightExpression(new VariableExpression("this")); } else { baseScriptType = BASE_SCRIPT_TYPE; } Expression value = node.getMember("value"); if (value != null) { addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value); return; } changeBaseScriptType(source, de, cNode, baseScriptType, node); }
variableName = ve.getName(); fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression()); fieldNode.setSourcePosition(de); cNode.addField(fieldNode); cNode.addMethod(setterName, ACC_PUBLIC | ACC_SYNTHETIC, ClassHelper.VOID_TYPE, params(param(ve.getType(), variableName)), ClassNode.EMPTY_ARRAY, block( stmt(assignX(propX(varX("this"), variableName), varX(variableName))) ));
/** * @return true if this variable is dynamically typed */ public String toString() { return super.toString() + "[variable: " + variable + (this.isDynamicTyped() ? "" : " type: " + getType()) + "]"; }
/** * @return true if this variable is dynamically typed */ public String toString() { return super.toString() + "[variable: " + variable + (this.isDynamicTyped() ? "" : " type: " + getType()) + "]"; }
/** * @return true if this variable is dynamically typed */ public String toString() { return super.toString() + "[variable: " + variable + (this.isDynamicTyped() ? "" : " type: " + getType()) + "]"; }
@Override public void visitVariableExpression(VariableExpression expression) { super.visitVariableExpression(expression); addToCache(expression.getType()); } @Override
private ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) { if (!(arg instanceof VariableExpression)) return arg.getType(); VariableExpression vexp = (VariableExpression) arg; String name = vexp.getName(); Parameter[] params = node.getParameters(); for (int i=0; i<params.length; i++) { if (params[i].getName().equals(name)) { return params[i].getType(); } } return vexp.getType(); }
private ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) { if (!(arg instanceof VariableExpression)) return arg.getType(); VariableExpression vexp = (VariableExpression) arg; String name = vexp.getName(); for (Parameter param : node.getParameters()) { if (param.getName().equals(name)) { return param.getType(); } } return vexp.getType(); }
private ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) { if (!(arg instanceof VariableExpression)) return arg.getType(); VariableExpression vexp = (VariableExpression) arg; String name = vexp.getName(); for (Parameter param : node.getParameters()) { if (param.getName().equals(name)) { return param.getType(); } } return vexp.getType(); }
private ClassNode getConstructorArgumentType(Expression arg, ConstructorNode node) { if (!(arg instanceof VariableExpression)) return arg.getType(); VariableExpression vexp = (VariableExpression) arg; String name = vexp.getName(); Parameter[] params = node.getParameters(); for (int i=0; i<params.length; i++) { if (params[i].getName().equals(name)) { return params[i].getType(); } } return vexp.getType(); }