import string
import os

##################### Weeding ##########################################
def fileNameCheck(tokens, f):
    fileName = os.path.basename(f).split('.java')[0]

    check = False
    for t in tokens:
        if check:
            if (t.lex != fileName):
                print(t.lex, fileName)
                return ("ERROR: Class or Interface name should be the same as file name.")
            return None
        if t.name == 'INTERFACE' or t.name == 'CLASS':
            check = True
    return None



# node: Node[]
def oneConstructor(node, insideClass):
    success = False
    if not insideClass:
        if node.name == 'classDcl':
            for c in node.children:
                success = oneConstructor(c, True)
                if success:
                    return True
    elif insideClass:
        if node.name == 'constructorDcl':
            return True


# tree: Node[]
def weed(tree):
    # Every class must contain at least one explicit constructor
    if oneConstructor(tree, False) == False:
        print('a class does not have an explicit constructor')