package ca.uwaterloo.joos.weeder;

import ca.uwaterloo.joos.ast.ASTNode;
import ca.uwaterloo.joos.ast.Modifiers.Modifier;
import ca.uwaterloo.joos.ast.decl.ClassDeclaration;
import ca.uwaterloo.joos.ast.decl.MethodDeclaration;
import ca.uwaterloo.joos.ast.visitor.MethodDeclVisitor;

public class MethodDeclChecker extends MethodDeclVisitor {

	public MethodDeclChecker() {

	}

	@Override
	protected void visitMethodDecl(MethodDeclaration node) throws Exception {
		ASTNode astNode = node;
		if (node.getModifiers().getModifiers().contains(Modifier.ABSTRACT)) {
			ClassDeclaration classDeclNode = null;
			while (!(astNode.getParent() instanceof ClassDeclaration)) {
				astNode = astNode.getParent();
			}
			classDeclNode = (ClassDeclaration) astNode.getParent();
			if (!(classDeclNode.getModifiers().getModifiers().contains(Modifier.ABSTRACT))) {
				throw new Exception("class contains abstract Method must be abstract");
			}

		}

	}

}

@@ -484,16 +484,46 @@
 = node;%0A
+%09%09Boolean insideClass = true;%0A
 %09%09if (no
@@ -647,28 +647,16 @@
 (astNode
-.getParent()
  instanc
@@ -688,44 +688,164 @@
 %09%09%09%09
-astNode = astNode.getParent();%0A%09%09%09%7D%0A
+if (astNode.getParent() != null) %7B%0A%09%09%09%09%09astNode = astNode.getParent();%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09insideClass = false;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09if (insideClass) %7B%0A%09
 %09%09%09c
@@ -885,30 +885,19 @@
  astNode
-.getParent()
 ;%0A
+%09
 %09%09%09if (!
@@ -977,16 +977,17 @@
 ) %7B%0A%09%09%09%09
+%09
 throw ne
@@ -1053,17 +1053,27 @@
 t%22);%0A%09%09%09
-%7D
+%09%7D%0A%09%09%09%7D%0A%09%09%09
 %0A%0A%09%09%7D%0A%0A%09

fix the bug in MethodChecker