private static ConstructorCallExpression getConstructorCallExpression(ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.isEmpty()) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
@Override public void visitConstructor(ConstructorNode node) { super.visitConstructor(node); Statement code = node.getCode(); Expression cce = getConstructorCall(code); if (cce==null) return; cce.visit(this); }
private void adjustConstructorAndFields(int skipIndex, ClassNode type) { List<ConstructorNode> constructors = type.getDeclaredConstructors(); if (constructors.size() == 1) { ConstructorNode constructor = constructors.get(0); Parameter[] params = constructor.getParameters(); Parameter[] newParams = new Parameter[params.length - 1]; int to = 0; for (int from = 0; from < params.length; from++) { if (from != skipIndex) { newParams[to++] = params[from]; } } type.removeConstructor(constructor); // code doesn't mention the removed param at this point, okay to leave as is addGeneratedConstructor(type, constructor.getModifiers(), newParams, constructor.getExceptions(), constructor.getCode()); type.removeField(variableName); } }
Statement s = node.getCode(); if (s == null) { return;
if ((params.length == 1 || params.length == 2) // 2 is for inner class case && StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(params[params.length - 1].getType(), ClassHelper.MAP_TYPE) && node.getCode() == StaticTypeCheckingVisitor.GENERATED_EMPTY_STATEMENT) { Expression arguments = expr.getArguments(); if (arguments instanceof TupleExpression) {
String stringParameterName = getUniqueVariableName("__str", ctor.getCode()); newP[0] = new Parameter(ClassHelper.STRING_TYPE, stringParameterName); String intParameterName = getUniqueVariableName("__int", ctor.getCode()); newP[1] = new Parameter(ClassHelper.int_TYPE, intParameterName); System.arraycopy(oldP, 0, newP, 2, oldP.length); BlockStatement code = new BlockStatement(); code.addStatement(new ExpressionStatement(cce)); Statement oldCode = ctor.getCode(); if (oldCode != null) code.addStatement(oldCode); ctor.setCode(code);
Statement code = constructorNode.getCode(); BlockStatement block = new BlockStatement(); List<Statement> otherStatements = block.getStatements();
private void addThisReference(ConstructorNode node) { if (!shouldHandleImplicitThisForInnerClass(classNode)) return; Statement code = node.getCode();
public void visitConstructor(ConstructorNode node) { CodeVisitorSupport checkSuper = new CodeVisitorSupport() { boolean firstMethodCall = true; String type=null; public void visitMethodCallExpression(MethodCallExpression call) { if (!firstMethodCall) return; firstMethodCall = false; String name = call.getMethodAsString(); // the name might be null if the method name is a GString for example if (name==null) return; if (!name.equals("super") && !name.equals("this")) return; type=name; call.getArguments().visit(this); type=null; } public void visitVariableExpression(VariableExpression expression) { if (type==null) return; String name = expression.getName(); if (!name.equals("this") && !name.equals("super")) return; throw new RuntimeParserException("cannot reference "+name+" inside of "+type+"(....) before supertype constructor has been called",expression); } }; Statement s = node.getCode(); if (s == null) return; s.visit(checkSuper); }
private ConstructorCallExpression getConstructorCallExpression(ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.size() == 0) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
private ConstructorCallExpression getConstructorCallExpression(ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.size() == 0) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
Statement s = node.getCode();
private ConstructorCallExpression getConstructorCallExpression( ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.size() == 0) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
private ConstructorCallExpression getConstructorCallExpression( ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.size() == 0) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
private ConstructorCallExpression getConstructorCallExpression( ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.size() == 0) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
private ConstructorCallExpression getConstructorCallExpression( ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) { return null; } BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.isEmpty()) { return null; } Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) { return null; } Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) { return null; } return (ConstructorCallExpression) expr; }
private boolean validateConstructors(ClassNode cNode) { if (cNode instanceof InnerClassNode && Modifier.isStatic(cNode.getModifiers())) { List<ConstructorNode> constructors = cNode.getDeclaredConstructors(); if (constructors.size() == 1 && constructors.get(0).getCode() == null) { constructors.remove(0); } } if (cNode.getDeclaredConstructors().size() != 0) { // TODO: allow constructors which only call provided constructor? addError("Explicit constructors not allowed for " + ImmutableASTTransformation.MY_TYPE_NAME + " class: " + cNode.getNameWithoutPackage(), cNode.getDeclaredConstructors().get(0)); } return true; }
Statement s = node.getCode(); if (s == null) { return;
Statement s = node.getCode();
String stringParameterName = getUniqueVariableName("__str",ctor.getCode()); newP[0] = new Parameter(ClassHelper.STRING_TYPE,stringParameterName); String intParameterName = getUniqueVariableName("__int",ctor.getCode()); newP[1] = new Parameter(ClassHelper.int_TYPE,intParameterName); System.arraycopy(oldP, 0, newP, 2, oldP.length); BlockStatement code = new BlockStatement(); code.addStatement(new ExpressionStatement(cce)); Statement oldCode = ctor.getCode(); if (oldCode!=null) code.addStatement(oldCode); ctor.setCode(code);