Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

check if try statement has catches #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions computation/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def branches(node):
))):
count = 1
elif(isinstance(node, tree.SwitchStatementCase)):
count = len(node.case)
if node.case is not None:
count = len(node.case)
elif(isinstance(node, tree.TryStatement)):
count = len(node.catches)
if node.catches is not None:
count = len(node.catches)
return count

"""Check the name for compound inside the methods (i.e. for local variables)
Expand All @@ -57,9 +59,10 @@ def branches(node):
"""
def compound(node):
flag = False
if (isinstance(node, tree.LocalVariableDeclaration)):
name = node.declarators[0].name
flag = len(re.findall(r'(?:[a-z][A-Z]+)|(?:[_])', name)) != 0
if (isinstance(node, tree.VariableDeclarator)):
found = re.findall(r'(?:[a-z][A-Z]+)|(?:[_])', node.name)
if found is not None:
flag = len(found) != 0
return flag


Expand Down
8 changes: 4 additions & 4 deletions computation/calc_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def test_catch_statements(self):
def test_compound_with_camel_and_snake_cases(self):
for s in ['camelCase', 'CamelCase', 'camelCASE', 'snake_case', 'snake_CASE', 'SNAKE_CASE', 'SNAKE_case']:
code = "int %s = 0;" % (s)
node = self.parser(code).parse_local_variable_declaration_statement()
self.assertEqual(compound(node), 1)
node = self.parser(code).parse_method_or_field_declaraction()
self.assertEqual(compound(node.declarators[0]), 1)

def test_compound_without_camel_and_snake_cases(self):
for s in ['camelcase, CAMELCASE, Camelcase']:
code = "int %s = 0;" % (s)
node = self.parser(code).parse_local_variable_declaration_statement()
self.assertEqual(compound(node), 0)
node = self.parser(code).parse_method_or_field_declaraction()
self.assertEqual(compound(node.declarators[0]), 0)

def expression(self, code):
return self.parser(code).parse_expression()
Expand Down
15 changes: 0 additions & 15 deletions computation/java/names/FirstTest.java

This file was deleted.

19 changes: 19 additions & 0 deletions computation/java/names/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 5
* */
public class Test {
public int thisVariableCounted = 0; // 1
public static final boolean this_variable_not_counted_too; // 2
private double nottaken;

public static void main(String args[]) {
final Test1 compoundNameOne = new Test1(); // 3
boolean COUMPOUND_NAME_TWO = false; // 4
int nottaken = 0;
}

void foo() {
String anotherOneCounted; // 5
int a0$nottakentoo = 0;
}
}