public void visitReturnStatement(ReturnStatement statement) { throw new RuntimeParserException("'return' is not allowed in object initializer", statement); } };
public void throwException(String s) { throw new RuntimeParserException(s, currentASTNode); }
public static void assertValidIdentifier(String name, String message, ASTNode node) { int size = name.length(); if (size <= 0) { throw new RuntimeParserException("Invalid " + message + ". Identifier must not be empty", node); } char firstCh = name.charAt(0); if (size == 1 && firstCh == '$') { throw new RuntimeParserException("Invalid " + message + ". Must include a letter but only found: " + name, node); } if (!Character.isJavaIdentifierStart(firstCh)) { throw new RuntimeParserException("Invalid " + message + ". Must start with a letter but was: " + name, node); } for (int i = 1; i < size; i++) { char ch = name.charAt(i); if (!Character.isJavaIdentifierPart(ch)) { throw new RuntimeParserException("Invalid " + message + ". Invalid character at position: " + (i + 1) + " of value: " + ch + " in name: " + name, node); } } } }
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); } };
@Override public void variableNotFinal(Variable var, Expression bexp) { if (var instanceof VariableExpression) { var = ((VariableExpression) var).getAccessedVariable(); } if (var instanceof VariableExpression && isFinal(var.getModifiers())) { throw new RuntimeParserException("The variable [" + var.getName() + "] is declared final but is reassigned", bexp); } if (var instanceof Parameter && isFinal(var.getModifiers())) { throw new RuntimeParserException("The parameter [" + var.getName() + "] is declared final but is reassigned", bexp); } }
public void visitListExpression(ListExpression expression) { for (Expression element : expression.getExpressions()) { if (element instanceof MapEntryExpression) { throw new RuntimeParserException("No map entry allowed at this place", element); } } super.visitListExpression(expression); }
@Override public void variableNotAlwaysInitialized(final VariableExpression var) { if (Modifier.isFinal(var.getAccessedVariable().getModifiers())) throw new RuntimeParserException("The variable [" + var.getName() + "] may be uninitialized", var); } };
private static void checkForDuplicateMethods(ClassNode cn) { Set<String> descriptors = new HashSet<String>(); for (MethodNode mn : cn.getMethods()) { if (mn.isSynthetic()) continue; String mySig = methodDescriptorWithoutReturnType(mn); if (descriptors.contains(mySig)) { if (mn.isScriptBody() || mySig.equals(scriptBodySignatureWithoutReturnType(cn))) { throw new RuntimeParserException("The method " + mn.getText() + " is a duplicate of the one declared for this script's body code", mn); } else { throw new RuntimeParserException("The method " + mn.getText() + " duplicates another method of the same signature", mn); } } descriptors.add(mySig); } }
private static FieldNode checkFieldDoesNotExist(ClassNode node, String fieldName) { FieldNode ret = node.getDeclaredField(fieldName); if (ret != null) { if (isPublic(ret.getModifiers()) && ret.getType().redirect() == ClassHelper.boolean_TYPE) { return ret; } throw new RuntimeParserException("The class " + node.getName() + " cannot declare field '" + fieldName + "' as this" + " field is needed for internal groovy purposes", ret); } return null; }
public void visitConstructorCallExpression(ConstructorCallExpression call) { ClassNode callType = call.getType(); if (callType.isEnum() && !callType.equals(verifier.getClassNode())) { throw new RuntimeParserException("Enum constructor calls are only allowed inside the enum class", call); } }
if (intfMethod != null && ((m.getModifiers() & ACC_SYNTHETIC) == 0) && !m.isPublic() && !m.isStaticConstructor()) { throw new RuntimeParserException("The method " + m.getName() + " should be public as it implements the corresponding method from interface " + intfMethod.getDeclaringClass(), m);
private static FieldNode getMetaClassField(ClassNode node) { FieldNode ret = node.getDeclaredField("metaClass"); if (ret != null) { ClassNode mcFieldType = ret.getType(); if (!mcFieldType.equals(ClassHelper.METACLASS_TYPE)) { throw new RuntimeParserException("The class " + node.getName() + " cannot declare field 'metaClass' of type " + mcFieldType.getName() + " as it needs to be of " + "the type " + ClassHelper.METACLASS_TYPE.getName() + " for internal groovy purposes", ret); } return ret; } ClassNode current = node; while (current != ClassHelper.OBJECT_TYPE) { current = current.getSuperClass(); if (current == null) break; ret = current.getDeclaredField("metaClass"); if (ret == null) continue; if (isPrivate(ret.getModifiers())) continue; return ret; } return null; }
public void visitMethod(MethodNode node) { //GROOVY-3712 - if it's an MOP method, it's an error as they aren't supposed to exist before ACG is invoked if (MopWriter.isMopMethod(node.getName())) { throw new RuntimeParserException("Found unexpected MOP methods in the class node for " + classNode.getName() + "(" + node.getName() + ")", classNode); } this.methodNode = node; adjustTypesIfStaticMainMethod(node); addReturnIfNeeded(node); Statement statement; statement = node.getCode(); if (statement != null) statement.visit(new VerifierCodeVisitor(this)); }
throw new RuntimeParserException("Duplicate interfaces in implements list: " + interfaces, classNode);
private void setPropertyOfSuperClass(ClassNode classNode, PropertyExpression expression, MethodVisitor mv) { String fieldName = expression.getPropertyAsString(); FieldNode fieldNode = classNode.getSuperClass().getField(fieldName); if (null == fieldNode) { throw new RuntimeParserException("Failed to find field[" + fieldName + "] of " + classNode.getName() + "'s super class", expression); } if (fieldNode.isFinal()) { throw new RuntimeParserException("Cannot modify final field[" + fieldName + "] of " + classNode.getName() + "'s super class", expression); } MethodNode setter = findSetterOfSuperClass(classNode, fieldNode); MethodNode getter = findGetterOfSuperClass(classNode, fieldNode); if (fieldNode.isPrivate() && !getterAndSetterExists(setter, getter)) { throw new RuntimeParserException("Cannot access private field[" + fieldName + "] of " + classNode.getName() + "'s super class", expression); } OperandStack operandStack = controller.getOperandStack(); operandStack.doAsType(fieldNode.getType()); mv.visitVarInsn(ALOAD, 0); operandStack.push(classNode); operandStack.swap(); String owner = BytecodeHelper.getClassInternalName(classNode.getSuperClass().getName()); String desc = BytecodeHelper.getTypeDescription(fieldNode.getType()); if (fieldNode.isPublic() || fieldNode.isProtected()) { mv.visitFieldInsn(PUTFIELD, owner, fieldName, desc); } else { mv.visitMethodInsn(INVOKESPECIAL, owner, setter.getName(), BytecodeHelper.getMethodDescriptor(setter), false); } }
if (!isAssignable(mr, testmr)) { if (ignoreError) return null; throw new RuntimeParserException( "The return type of " + overridingMethod.getTypeDescriptor() + throw new RuntimeParserException( "Cannot override final method " + oldMethod.getTypeDescriptor() + throw new RuntimeParserException( "Cannot override method " + oldMethod.getTypeDescriptor() + message = " with old method having a primitive return type and new method not"; throw new RuntimeParserException( "Cannot override method " + oldMethod.getTypeDescriptor() +
throw new RuntimeParserException( "The method with default parameters \"" + method.getTypeDescriptor() + "\" defines a method \"" + newMethod.getTypeDescriptor() +
public void visitReturnStatement(ReturnStatement statement) { throw new RuntimeParserException("'return' is not allowed in object initializer",statement); } };
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); } };
public void visitListExpression(ListExpression expression) { List expressions = expression.getExpressions(); for (Iterator iter = expressions.iterator(); iter.hasNext();) { Object element = iter.next(); if (element instanceof MapEntryExpression) { throw new RuntimeParserException ("no map entry allowed at this place",(Expression) element); } } super.visitListExpression(expression); } }