From 296a1684a166ee77f63d4eee7a25365f644ec6f2 Mon Sep 17 00:00:00 2001 From: sjfink Date: Mon, 13 Apr 2009 13:58:55 +0000 Subject: [PATCH] switch to WALA code format. No semantic change. git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3440 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../.settings/org.eclipse.jdt.core.prefs | 266 +++++ .../.settings/org.eclipse.jdt.ui.prefs | 10 + .../com/ibm/wala/cast/java/jdt/Activator.java | 70 +- .../jdt/FakeExceptionTypeBinding.java | 51 +- .../java/translator/jdt/JDT2CAstUtils.java | 109 +-- .../translator/jdt/JDTClassLoaderFactory.java | 10 +- .../translator/jdt/JDTIdentityMapper.java | 82 +- .../jdt/JDTJava2CAstTranslator.java | 911 +++++++++--------- .../translator/jdt/JDTSourceLoaderImpl.java | 14 +- .../jdt/JDTSourceModuleTranslator.java | 69 +- .../translator/jdt/JDTTypeDictionary.java | 17 +- 11 files changed, 940 insertions(+), 669 deletions(-) create mode 100644 com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.core.prefs create mode 100644 com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.ui.prefs diff --git a/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.core.prefs b/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..2b96733f7 --- /dev/null +++ b/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,266 @@ +#Mon Apr 13 09:57:37 EDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert +org.eclipse.jdt.core.formatter.comment.line_length=132 +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=132 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=space +org.eclipse.jdt.core.formatter.tabulation.size=2 +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true diff --git a/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.ui.prefs b/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 000000000..abc5b4c01 --- /dev/null +++ b/com.ibm.wala.cast.java.jdt/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,10 @@ +#Mon Apr 13 09:57:37 EDT 2009 +eclipse.preferences.version=1 +formatter_profile=_WALA +formatter_settings_version=11 +org.eclipse.jdt.ui.exception.name=e +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.javadoc=false +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true +org.eclipse.jdt.ui.text.custom_code_templates= diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/jdt/Activator.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/jdt/Activator.java index 182a08115..e8aa8efee 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/jdt/Activator.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/jdt/Activator.java @@ -45,43 +45,45 @@ import org.osgi.framework.BundleContext; */ public class Activator extends Plugin { - // The plug-in ID - public static final String PLUGIN_ID = "com.ibm.wala.cast.java.jdt"; + // The plug-in ID + public static final String PLUGIN_ID = "com.ibm.wala.cast.java.jdt"; - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } + // The shared instance + private static Activator plugin; - /* - * (non-Javadoc) - * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } + /** + * The constructor + */ + public Activator() { + } - /* - * (non-Javadoc) - * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } } diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/FakeExceptionTypeBinding.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/FakeExceptionTypeBinding.java index 471d42b70..a0ff4858e 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/FakeExceptionTypeBinding.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/FakeExceptionTypeBinding.java @@ -48,44 +48,49 @@ import org.eclipse.jdt.core.dom.IVariableBinding; import com.ibm.wala.util.debug.Assertions; /** - * This is a hack to get around the fact that AST.resolveWellKnownTypes() doesn't know - * about some implicitly declared exceptions, such as ArithmeticException (implicitly - * thrown in a division operation) and NullPointerException (implicitly thrown in a field + * This is a hack to get around the fact that AST.resolveWellKnownTypes() doesn't know about some implicitly declared exceptions, + * such as ArithmeticException (implicitly thrown in a division operation) and NullPointerException (implicitly thrown in a field * access). We need to know the lineage of these types to determine possible catch targets. * * @author evan - * + * */ public class FakeExceptionTypeBinding implements ITypeBinding { static public final FakeExceptionTypeBinding arithmetic = new FakeExceptionTypeBinding("Ljava/lang/ArithmeticException;"); + static public final FakeExceptionTypeBinding nullPointer = new FakeExceptionTypeBinding("Ljava/lang/NullPointerException;"); + static public final FakeExceptionTypeBinding classCast = new FakeExceptionTypeBinding("Ljava/lang/ClassCastException;"); + static public final FakeExceptionTypeBinding noClassDef = new FakeExceptionTypeBinding("Ljava/lang/NoClassDefFoundError;"); - static public final FakeExceptionTypeBinding initException = new FakeExceptionTypeBinding("Ljava/lang/ExceptionInInitializerError;"); + + static public final FakeExceptionTypeBinding initException = new FakeExceptionTypeBinding( + "Ljava/lang/ExceptionInInitializerError;"); + static public final FakeExceptionTypeBinding outOfMemory = new FakeExceptionTypeBinding("Ljava/lang/OutOfMemoryError;"); - + private final String exceptionBinaryName; private FakeExceptionTypeBinding(String exceptionBinaryName) { this.exceptionBinaryName = exceptionBinaryName; } - + public boolean isAssignmentCompatible(ITypeBinding variableType) { Assertions.UNREACHABLE("FakeExceptionTypeBinding "); return false; } public boolean equals(Object o) { - if ( o instanceof FakeExceptionTypeBinding ) + if (o instanceof FakeExceptionTypeBinding) return this == o; - if ( o instanceof ITypeBinding ) - return ((ITypeBinding)o).getBinaryName().equals(exceptionBinaryName); + if (o instanceof ITypeBinding) + return ((ITypeBinding) o).getBinaryName().equals(exceptionBinaryName); return false; } // --- rest not needed - + public ITypeBinding createArrayType(int dimension) { Assertions.UNREACHABLE("FakeExceptionTypeBinding createArrayType"); return null; @@ -294,23 +299,17 @@ public class FakeExceptionTypeBinding implements ITypeBinding { public boolean isSubTypeCompatible(ITypeBinding type) { String name = type.getBinaryName(); if (exceptionBinaryName.endsWith("Error;")) { - if ( name.equals("Ljava/lang/Throwable;") || - name.equals("Ljava/lang/Error;") || - name.equals(exceptionBinaryName) ) - { - return true; - } - + if (name.equals("Ljava/lang/Throwable;") || name.equals("Ljava/lang/Error;") || name.equals(exceptionBinaryName)) { + return true; + } + } else { - if ( name.equals("Ljava/lang/Throwable;") || - name.equals("Ljava/lang/Exception;") || - name.equals("Ljava/lang/RuntimeException;") || - name.equals(exceptionBinaryName) ) - { - return true; - } + if (name.equals("Ljava/lang/Throwable;") || name.equals("Ljava/lang/Exception;") + || name.equals("Ljava/lang/RuntimeException;") || name.equals(exceptionBinaryName)) { + return true; + } } - + return false; } diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDT2CAstUtils.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDT2CAstUtils.java index 79251b9e3..c401028f4 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDT2CAstUtils.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDT2CAstUtils.java @@ -62,10 +62,10 @@ import com.ibm.wala.util.debug.Assertions; public class JDT2CAstUtils { public static Collection mapModifiersToQualifiers(int modifiers, boolean isInterface) { Set quals = new LinkedHashSet(); - + if (isInterface) quals.add(CAstQualifier.INTERFACE); - + if ((modifiers & Modifier.ABSTRACT) != 0) quals.add(CAstQualifier.ABSTRACT); if ((modifiers & Modifier.FINAL) != 0) @@ -89,10 +89,10 @@ public class JDT2CAstUtils { quals.add(CAstQualifier.TRANSIENT); if ((modifiers & Modifier.VOLATILE) != 0) quals.add(CAstQualifier.VOLATILE); - + return quals; } - + public static CAstOperator mapAssignOperator(Operator op) { if (op == Assignment.Operator.PLUS_ASSIGN) return CAstOperator.OP_ADD; @@ -131,12 +131,12 @@ public class JDT2CAstUtils { if (operator == InfixExpression.Operator.XOR) return CAstOperator.OP_BIT_XOR; - // TODO: shouldn't get here (conditional and handled differently); however should separate bitwise & logical '&' / '|', maybe. + // TODO: shouldn't get here (conditional and handled differently); however should separate bitwise & logical '&' / '|', maybe. if (operator == InfixExpression.Operator.CONDITIONAL_AND) return CAstOperator.OP_REL_AND; if (operator == InfixExpression.Operator.CONDITIONAL_OR) return CAstOperator.OP_REL_OR; - + if (operator == InfixExpression.Operator.DIVIDE) return CAstOperator.OP_DIV; if (operator == InfixExpression.Operator.EQUALS) @@ -168,8 +168,8 @@ public class JDT2CAstUtils { } /** - * Returns true if type is char, byte, short, int, or long. - * Return false otherwise (including boolean!) + * Returns true if type is char, byte, short, int, or long. Return false otherwise (including boolean!) + * * @param type * @return */ @@ -179,44 +179,44 @@ public class JDT2CAstUtils { } /** - * If isLongOrLess(type), returns Integer(0). - * If a float or double, returns Double(0.0) - * Otherwise (including boolean), returns CAstSymbol.NULL_DEFAULT_VALUE. + * If isLongOrLess(type), returns Integer(0). If a float or double, returns Double(0.0) Otherwise (including boolean), returns + * CAstSymbol.NULL_DEFAULT_VALUE. + * * @param type * @return - */ + */ public static Object defaultValueForType(ITypeBinding type) { - if ( isLongOrLess(type) ) + if (isLongOrLess(type)) return new Integer(0); else if (type.getBinaryName().equals("D") || type.getBinaryName().equals("F")) return new Double(0.0); else return CAstSymbol.NULL_DEFAULT_VALUE; } - + public static ITypeBinding promoteTypes(ITypeBinding t1, ITypeBinding t2, AST ast) { // JLS 5.6.2 ITypeBinding doble = ast.resolveWellKnownType("double"); - if (t1.equals(doble) || t2.equals(doble) ) - return doble; - ITypeBinding flotando = ast.resolveWellKnownType("float"); - if (t1.equals(flotando) || t2.equals(flotando) ) - return flotando; - ITypeBinding largo = ast.resolveWellKnownType("long"); - if (t1.equals(largo) || t2.equals(largo) ) - return largo; - return ast.resolveWellKnownType("int"); + if (t1.equals(doble) || t2.equals(doble)) + return doble; + ITypeBinding flotando = ast.resolveWellKnownType("float"); + if (t1.equals(flotando) || t2.equals(flotando)) + return flotando; + ITypeBinding largo = ast.resolveWellKnownType("long"); + if (t1.equals(largo) || t2.equals(largo)) + return largo; + return ast.resolveWellKnownType("int"); } public static ITypeBinding getDeclaringClassOfNode(ASTNode n) { ASTNode current = n; - while ( current != null ) { - if (current instanceof TypeDeclaration ) - return ((TypeDeclaration)current).resolveBinding(); - else if ( current instanceof AnonymousClassDeclaration ) - return ((AnonymousClassDeclaration)current).resolveBinding(); - else if ( current instanceof EnumDeclaration ) - return ((EnumDeclaration)current).resolveBinding(); + while (current != null) { + if (current instanceof TypeDeclaration) + return ((TypeDeclaration) current).resolveBinding(); + else if (current instanceof AnonymousClassDeclaration) + return ((AnonymousClassDeclaration) current).resolveBinding(); + else if (current instanceof EnumDeclaration) + return ((EnumDeclaration) current).resolveBinding(); current = current.getParent(); } Assertions.UNREACHABLE("Couldn't find declaring class of node"); @@ -230,21 +230,21 @@ public class JDT2CAstUtils { } /** - * If a type variable, return the bound (getTypeVariablesBase()). - * If a parameterized type, return the generic type. + * If a type variable, return the bound (getTypeVariablesBase()). If a parameterized type, return the generic type. + * * @param returnType * @param ast * @return */ public static ITypeBinding getErasedType(ITypeBinding returnType, AST ast) { - if ( returnType.isTypeVariable() || returnType.isCapture() ) + if (returnType.isTypeVariable() || returnType.isCapture()) return getTypesVariablesBase(returnType, ast); return returnType.getTypeDeclaration(); // Things like "Collection" are parameterized types... } - + public static ITypeBinding getTypesVariablesBase(ITypeBinding returnType, AST ast) { Assertions._assert(returnType.isTypeVariable() || returnType.isCapture()); - if ( returnType.getTypeBounds().length > 0 ) + if (returnType.getTypeBounds().length > 0) return returnType.getTypeBounds()[0]; // TODO: why is there more than one bound? else return ast.resolveWellKnownType("java.lang.Object"); @@ -277,26 +277,27 @@ public class JDT2CAstUtils { return null; } - private static void getMethodInClassOrSuperclass(IMethodBinding met, ITypeBinding klass, boolean superclassonly, HashMap overridden) { - if ( !superclassonly ) { - for ( IMethodBinding ourmet: klass.getDeclaredMethods() ) - if ( met.isSubsignature(ourmet) && (met.getModifiers() & Modifier.PRIVATE) == 0) { - overridden.put(ourmet.getMethodDeclaration().getReturnType(),ourmet.getMethodDeclaration()); - break; // there can only be one per class so don't bother looking for more + private static void getMethodInClassOrSuperclass(IMethodBinding met, ITypeBinding klass, boolean superclassonly, + HashMap overridden) { + if (!superclassonly) { + for (IMethodBinding ourmet : klass.getDeclaredMethods()) + if (met.isSubsignature(ourmet) && (met.getModifiers() & Modifier.PRIVATE) == 0) { + overridden.put(ourmet.getMethodDeclaration().getReturnType(), ourmet.getMethodDeclaration()); + break; // there can only be one per class so don't bother looking for more } } - - for ( ITypeBinding iface: klass.getInterfaces() ) + + for (ITypeBinding iface : klass.getInterfaces()) getMethodInClassOrSuperclass(met, iface, false, overridden); - + ITypeBinding superclass = klass.getSuperclass(); - if ( superclass != null ) + if (superclass != null) getMethodInClassOrSuperclass(met, superclass, false, overridden); } public static Collection getOverriddenMethod(IMethodBinding met) { - HashMap overridden = new HashMap(); - if ( met == null ) + HashMap overridden = new HashMap(); + if (met == null) return null; getMethodInClassOrSuperclass(met, met.getDeclaringClass(), true, overridden); if (overridden.size() == 0) @@ -305,18 +306,18 @@ public class JDT2CAstUtils { } public static boolean sameSignatureAndReturnType(IMethodBinding met1, IMethodBinding met2) { - if ( !met1.getReturnType().isEqualTo(met2.getReturnType()) ) + if (!met1.getReturnType().isEqualTo(met2.getReturnType())) return false; - + ITypeBinding[] params1 = met1.getParameterTypes(); ITypeBinding[] params2 = met2.getParameterTypes(); - if ( params1.length != params2.length ) + if (params1.length != params2.length) return false; - - for ( int i = 0; i < params1.length; i++ ) - if ( ! params1[i].isEqualTo(params2[i]) ) + + for (int i = 0; i < params1.length; i++) + if (!params1[i].isEqualTo(params2[i])) return false; - + return true; } diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTClassLoaderFactory.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTClassLoaderFactory.java index 3ff5a33fa..92be27659 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTClassLoaderFactory.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTClassLoaderFactory.java @@ -50,11 +50,11 @@ import com.ibm.wala.types.ClassLoaderReference; public class JDTClassLoaderFactory extends ClassLoaderFactoryImpl { -// /** -// * A map from ClassLoaderReference to IRTranslatorExtension, so that source files -// * in different languages are processed by the right kind of IRTranslatorExtension. -// */ -// that's nice, but there's only one kind of IRTransatorExtension. + // /** + // * A map from ClassLoaderReference to IRTranslatorExtension, so that source files + // * in different languages are processed by the right kind of IRTranslatorExtension. + // */ + // that's nice, but there's only one kind of IRTransatorExtension. public JDTClassLoaderFactory(SetOfClasses exclusions) { super(exclusions); diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTIdentityMapper.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTIdentityMapper.java index 34d233060..17c867283 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTIdentityMapper.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTIdentityMapper.java @@ -35,7 +35,7 @@ * IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ -package com.ibm.wala.cast.java.translator.jdt; +package com.ibm.wala.cast.java.translator.jdt; import java.util.Map; @@ -56,21 +56,24 @@ import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.strings.Atom; /** - * Class responsible for mapping JDT type system objects representing types, methods and fields to the corresponding - * WALA TypeReferences, MethodReferences and FieldReferences. Used during translation and by clients to help correlate - * WALA analysis results to the various AST nodes. + * Class responsible for mapping JDT type system objects representing types, methods and fields to the corresponding WALA + * TypeReferences, MethodReferences and FieldReferences. Used during translation and by clients to help correlate WALA analysis + * results to the various AST nodes. * - * In English: keeps a hashtable of WALA "type references", "field references", etc. which describe types, fields, etc. - * Creates these from their JDT equivalents and keeps the hashtable linking the two representations. + * In English: keeps a hashtable of WALA "type references", "field references", etc. which describe types, fields, etc. Creates + * these from their JDT equivalents and keeps the hashtable linking the two representations. * * @author rfuhrer */ public class JDTIdentityMapper { - private final Map fTypeMap = HashMapFactory.make(); - private final Map fFieldMap= HashMapFactory.make(); - private final Map fMethodMap= HashMapFactory.make(); + private final Map fTypeMap = HashMapFactory.make(); + + private final Map fFieldMap = HashMapFactory.make(); + + private final Map fMethodMap = HashMapFactory.make(); private final ClassLoaderReference fClassLoaderRef; // TAGALONG + private final AST fAst; public JDTIdentityMapper(ClassLoaderReference clr, AST ast) { @@ -98,16 +101,15 @@ public class JDTIdentityMapper { } /** - * Translates the given Polyglot type to a name suitable for use in a DOMO TypeReference (i.e. a bytecode-compliant - * type name). + * Translates the given Polyglot type to a name suitable for use in a DOMO TypeReference (i.e. a bytecode-compliant type name). */ public String typeToTypeID(ITypeBinding type) { if (type.isPrimitive()) return type.getBinaryName(); else if (type.isArray()) // arrays' binary names in JDT are like "[Ljava.lang.String;" - return type.getBinaryName().replace('.', '/').replace(";",""); - else if ( type.isLocal() || type.isAnonymous() ) + return type.getBinaryName().replace('.', '/').replace(";", ""); + else if (type.isLocal() || type.isAnonymous()) return anonLocalTypeToTypeID(type); else if (type.isClass() || type.isEnum() || type.isInterface()) // in polyglot interfaces are classes too. not in JDT // class binary names in JDT are like "java.lang.String" @@ -115,38 +117,36 @@ public class JDTIdentityMapper { else if (type.isTypeVariable()) { return typeToTypeID(JDT2CAstUtils.getTypesVariablesBase(type, fAst)); } - Assertions.UNREACHABLE("typeToTypeID() encountered the type " + type - + " that is neither primitive, array, nor class!"); + Assertions.UNREACHABLE("typeToTypeID() encountered the type " + type + " that is neither primitive, array, nor class!"); return null; } - + public String anonLocalTypeToTypeID(ITypeBinding type) { - String outerTypeID= typeToTypeID(type.getDeclaringClass()); + String outerTypeID = typeToTypeID(type.getDeclaringClass()); String metSelectorName; IMethodBinding metBinding = type.getDeclaringMethod(); - if ( metBinding == null ) // anonymous class declared in initializer or static initializer (rare case...) + if (metBinding == null) // anonymous class declared in initializer or static initializer (rare case...) metSelectorName = ""; else metSelectorName = getMethodRef(metBinding).getSelector().toString(); - - String shortName= (type.isAnonymous()) ? JDT2CAstUtils.anonTypeName(type) : type.getName(); - + + String shortName = (type.isAnonymous()) ? JDT2CAstUtils.anonTypeName(type) : type.getName(); + return outerTypeID + '/' + metSelectorName + '/' + shortName; } - // FIELDS - + public FieldReference getFieldRef(IVariableBinding field) { if (!fFieldMap.containsKey(field.getKey())) { // create one - ITypeBinding targetType= field.getDeclaringClass(); - TypeReference targetTypeRef= TypeReference.findOrCreate(fClassLoaderRef, typeToTypeID(targetType)); - ITypeBinding fieldType= field.getType(); - TypeReference fieldTypeRef= TypeReference.findOrCreate(fClassLoaderRef, typeToTypeID(fieldType)); - Atom fieldName= Atom.findOrCreateUnicodeAtom(field.getName()); - FieldReference ref= FieldReference.findOrCreate(targetTypeRef, fieldName, fieldTypeRef); + ITypeBinding targetType = field.getDeclaringClass(); + TypeReference targetTypeRef = TypeReference.findOrCreate(fClassLoaderRef, typeToTypeID(targetType)); + ITypeBinding fieldType = field.getType(); + TypeReference fieldTypeRef = TypeReference.findOrCreate(fClassLoaderRef, typeToTypeID(fieldType)); + Atom fieldName = Atom.findOrCreateUnicodeAtom(field.getName()); + FieldReference ref = FieldReference.findOrCreate(targetTypeRef, fieldName, fieldTypeRef); fFieldMap.put(field.getKey(), ref); return ref; @@ -157,8 +157,8 @@ public class JDTIdentityMapper { public MethodReference fakeMethodRefNoArgs(String key, String typeID, String metName, String returnTypeID) { if (!fMethodMap.containsKey(key)) { // create one - TypeName ownerType= TypeName.string2TypeName(typeID); - TypeReference ownerTypeRef= TypeReference.findOrCreate(fClassLoaderRef, ownerType); + TypeName ownerType = TypeName.string2TypeName(typeID); + TypeReference ownerTypeRef = TypeReference.findOrCreate(fClassLoaderRef, ownerType); // FAKE SELECTOR Atom name = Atom.findOrCreateUnicodeAtom(metName); @@ -174,13 +174,13 @@ public class JDTIdentityMapper { } return fMethodMap.get(key); } - - // METHODS + + // METHODS public MethodReference getMethodRef(IMethodBinding met) { if (!fMethodMap.containsKey(met.getKey())) { // create one - TypeName ownerType= TypeName.string2TypeName(typeToTypeID(met.getDeclaringClass())); - TypeReference ownerTypeRef= TypeReference.findOrCreate(fClassLoaderRef, ownerType); + TypeName ownerType = TypeName.string2TypeName(typeToTypeID(met.getDeclaringClass())); + TypeReference ownerTypeRef = TypeReference.findOrCreate(fClassLoaderRef, ownerType); MethodReference ref = MethodReference.findOrCreate(ownerTypeRef, selectorForMethod(met)); fMethodMap.put(met.getKey(), ref); @@ -188,7 +188,7 @@ public class JDTIdentityMapper { } return fMethodMap.get(met.getKey()); } - + private Selector selectorForMethod(IMethodBinding met) { // TODO: have to handle default constructors? // TODO: generics... @@ -198,21 +198,21 @@ public class JDTIdentityMapper { ITypeBinding[] formalTypes = met.getParameterTypes(); int length = formalTypes.length; - + // ENUMS: hidden name and ID in constructor - if ( met.isConstructor() && met.getDeclaringClass().isEnum() ) + if (met.isConstructor() && met.getDeclaringClass().isEnum()) length += 2; - + // Descriptor prefers null to an empty array if (length > 0) { argTypeNames = new TypeName[length]; int i = 0; - if ( met.isConstructor() && met.getDeclaringClass().isEnum() ) { + if (met.isConstructor() && met.getDeclaringClass().isEnum()) { argTypeNames[0] = TypeName.string2TypeName(typeToTypeID(fAst.resolveWellKnownType("java.lang.String"))); argTypeNames[1] = TypeName.string2TypeName(typeToTypeID(fAst.resolveWellKnownType("int"))); i = 2; } - for (ITypeBinding argType: formalTypes) + for (ITypeBinding argType : formalTypes) argTypeNames[i++] = TypeName.string2TypeName(typeToTypeID(argType)); } diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java index 45e3870c3..237f9d30d 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java @@ -194,11 +194,11 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { protected ITypeBinding fRuntimeExcType; protected ITypeBinding NoClassDefFoundError; - + protected ITypeBinding ExceptionInInitializerError; - + protected ITypeBinding OutOfMemoryError; - + private String fullPath; private CompilationUnit cu; @@ -227,10 +227,10 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { NoClassDefFoundError = FakeExceptionTypeBinding.noClassDef; ExceptionInInitializerError = FakeExceptionTypeBinding.initException; OutOfMemoryError = FakeExceptionTypeBinding.outOfMemory; - + fRuntimeExcType = ast.resolveWellKnownType("java.lang.RuntimeException"); assert fRuntimeExcType != null; - + List declEntities = new ArrayList(); for (Iterator iter = cu.types().iterator(); iter.hasNext();) { @@ -341,22 +341,23 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } private CAstEntity visit(TypeDeclaration n, WalkContext context) { - return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), n.getName().getIdentifier(), n.getModifiers(), n - .isInterface(), context); + return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), n.getName().getIdentifier(), n.getModifiers(), + n.isInterface(), context); } /** * * @param n * @param bodyDecls - * @param enumConstants + * @param enumConstants * @param typeBinding * @param name Used in creating default constructor, and passed into new ClassEntity() * @param context * @return */ - private CAstEntity createClassDeclaration(ASTNode n, List/* */bodyDecls, List/*EnumConstantDeclaration*/ enumConstants, - ITypeBinding typeBinding, String name, int modifiers, boolean isInterface, WalkContext context) { + private CAstEntity createClassDeclaration(ASTNode n, List/* */bodyDecls, + List/* EnumConstantDeclaration */enumConstants, ITypeBinding typeBinding, String name, int modifiers, boolean isInterface, + WalkContext context) { final List memberEntities = new ArrayList(); // find and collect all initializers (type Initializer) and field initializers (type VariableDeclarationFragment). @@ -365,13 +366,13 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { ArrayList inits = new ArrayList(); ArrayList staticInits = new ArrayList(); - if ( enumConstants != null ) { - for ( Object decl: enumConstants ) { + if (enumConstants != null) { + for (Object decl : enumConstants) { EnumConstantDeclaration ecd = (EnumConstantDeclaration) decl; - staticInits.add(ecd); // always (implicitly) static,final (actually, no modifiers allowed) + staticInits.add(ecd); // always (implicitly) static,final (actually, no modifiers allowed) } } - + for (Object decl : bodyDecls) { if (decl instanceof Initializer) { Initializer initializer = (Initializer) decl; @@ -379,7 +380,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { (isStatic ? staticInits : inits).add(initializer); } else if (decl instanceof FieldDeclaration) { FieldDeclaration fd = (FieldDeclaration) decl; - + for (Object f : fd.fragments()) { VariableDeclarationFragment frag = (VariableDeclarationFragment) f; if (frag.getInitializer() != null) { @@ -391,12 +392,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } // process entities. initializers will be folded in here. - if ( enumConstants != null ) { - for ( Object decl: enumConstants ) { - memberEntities.add(visit((EnumConstantDeclaration)decl,context)); + if (enumConstants != null) { + for (Object decl : enumConstants) { + memberEntities.add(visit((EnumConstantDeclaration) decl, context)); } } - + for (Object d : bodyDecls) { BodyDeclaration decl = (BodyDeclaration) d; if (decl instanceof FieldDeclaration) { @@ -404,24 +405,23 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { Collection quals = JDT2CAstUtils.mapModifiersToQualifiers(fieldDecl.getModifiers(), false); for (Object f : fieldDecl.fragments()) { VariableDeclarationFragment fieldFrag = (VariableDeclarationFragment) f; - memberEntities.add(new FieldEntity(fieldFrag.getName().getIdentifier(), - fieldFrag.resolveBinding().getType(), quals, + memberEntities.add(new FieldEntity(fieldFrag.getName().getIdentifier(), fieldFrag.resolveBinding().getType(), quals, makePosition(fieldFrag.getStartPosition(), fieldFrag.getStartPosition() + fieldFrag.getLength()))); } } else if (decl instanceof Initializer) { // Initializers are inserted into constructors when making constructors. } else if (decl instanceof MethodDeclaration) { MethodDeclaration metDecl = (MethodDeclaration) decl; - - if ( typeBinding.isEnum() && metDecl.isConstructor() ) + + if (typeBinding.isEnum() && metDecl.isConstructor()) memberEntities.add(createEnumConstructorWithParameters(metDecl.resolveBinding(), metDecl, context, inits, metDecl)); else { memberEntities.add(visit(metDecl, typeBinding, context, inits)); - ///////////////// Java 1.5 "overridden with subtype" thing (covariant return type) /////////// + // /////////////// Java 1.5 "overridden with subtype" thing (covariant return type) /////////// Collection overriddenMets = JDT2CAstUtils.getOverriddenMethod(metDecl.resolveBinding()); - if ( overriddenMets != null ) { - for (IMethodBinding overridden: overriddenMets ) + if (overriddenMets != null) { + for (IMethodBinding overridden : overriddenMets) if (!JDT2CAstUtils.sameSignatureAndReturnType(metDecl.resolveBinding(), overridden)) memberEntities.add(makeSyntheticCovariantRedirect(metDecl, metDecl.resolveBinding(), overridden, context)); } @@ -439,18 +439,18 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { for (Object m : typeBinding.getDeclaredMethods()) { IMethodBinding met = (IMethodBinding) m; if (met.isDefaultConstructor()) { - if ( typeBinding.isEnum() ) + if (typeBinding.isEnum()) memberEntities.add(createEnumConstructorWithParameters(met, n, context, inits, null)); - else if ( met.getParameterTypes().length > 0) + else if (met.getParameterTypes().length > 0) memberEntities.add(createDefaultConstructorWithParameters(met, n, context, inits)); else memberEntities.add(createDefaultConstructor(name, typeBinding, context, inits, n)); } } - if ( typeBinding.isEnum() && !typeBinding.isAnonymous() ) + if (typeBinding.isEnum() && !typeBinding.isAnonymous()) doEnumHiddenEntities(typeBinding, staticInits, memberEntities, context); - + // collect static inits if (!staticInits.isEmpty()) { Map childEntities = HashMapFactory.make(); @@ -469,8 +469,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } private CAstEntity visit(AnonymousClassDeclaration n, WalkContext context) { - return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), JDT2CAstUtils.anonTypeName(n.resolveBinding()), - 0 /* no modifiers */, false, context); + return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), + JDT2CAstUtils.anonTypeName(n.resolveBinding()), 0 /* no modifiers */, false, context); } private CAstNode visit(TypeDeclarationStatement n, WalkContext context) { @@ -495,9 +495,9 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { * @param n for positioning. */ @SuppressWarnings("unchecked") - /** - * Make a constructor with parameters that calls super(...) with parameters. - * Used for anonymous classes with arguments to a constructor, like new Foo(arg1,arg2) { } + /* + * Make a constructor with parameters that calls super(...) with parameters. Used for anonymous classes with arguments to a + * constructor, like new Foo(arg1,arg2) { } */ private CAstEntity createDefaultConstructorWithParameters(IMethodBinding ctor, ASTNode n, WalkContext oldContext, ArrayList inits) { @@ -505,7 +505,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { ITypeBinding newType = ctor.getDeclaringClass(); ITypeBinding superType = newType.getSuperclass(); IMethodBinding superCtor = null; - + for (IMethodBinding m : superType.getDeclaredMethods()) if (m.isConstructor() && Arrays.equals(m.getParameterTypes(), ctor.getParameterTypes())) superCtor = m; @@ -525,7 +525,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { String[] fakeArguments = new String[superCtor.getParameterTypes().length + 1]; ArrayList paramTypes = new ArrayList(superCtor.getParameterTypes().length); for (int i = 0; i < fakeArguments.length; i++) - fakeArguments[i] = (i == 0) ? "this" : ("argument" + i); // TODO: change to invalid name and don't use singlevariabledeclaration below + fakeArguments[i] = (i == 0) ? "this" : ("argument" + i); // TODO: change to invalid name and don't use + // singlevariabledeclaration below for (int i = 1; i < fakeArguments.length; i++) { // the name SingleVariableDeclaration svd = ast.newSingleVariableDeclaration(); @@ -583,11 +584,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } /** - * Setup constructor body. Here we add the initializer code (both initalizer blocks and initializers in field declarations). - * We may also need to add an implicit super() call. + * Setup constructor body. Here we add the initializer code (both initalizer blocks and initializers in field declarations). We + * may also need to add an implicit super() call. + * * @param n * @param classBinding Used so we can use this with fake MethodDeclaration nodes, as in the case of creating a default - * constructor. + * constructor. * @param context * @param inits * @return @@ -610,14 +612,14 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { bodyNodes[idx++] = origStatements.get(0); for (ASTNode init : inits) bodyNodes[idx++] = visitFieldInitNode(init, context); // visit each in this constructor's context, ensuring - // proper handling of exceptions (we can't just reuse the - // CAstNodes) + // proper handling of exceptions (we can't just reuse the + // CAstNodes) for (int i = 1; i < origStatements.size(); i++) bodyNodes[idx++] = origStatements.get(i); return makeNode(context, fFactory, n.getBody(), CAstNode.BLOCK_STMT, bodyNodes); // QUESTION: why no LOCAL_SCOPE? - // that's the way it is in - // polyglot. + // that's the way it is in + // polyglot. } else if (firstStatement instanceof ConstructorInvocation) { return visitNode(n.getBody(), context); // has this(...) call; initializers will be set somewhere else. } else { @@ -636,10 +638,10 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // why don't we handle exceptions like in visit(ConstructorInvocation) ? (these two things are same in polyglot // implementation) - CAstNode superCall = makeNode(context, fFactory, n.getBody(), CAstNode.CALL, makeNode(context, fFactory, n.getBody(), CAstNode.SUPER), fFactory - .makeConstant(callSiteRef)); + CAstNode superCall = makeNode(context, fFactory, n.getBody(), CAstNode.CALL, makeNode(context, fFactory, n.getBody(), + CAstNode.SUPER), fFactory.makeConstant(callSiteRef)); Object mapper = new Object(); // dummy used for mapping this node in CFG - handleThrowsFromCall(defaultSuperCtor,mapper,context); + handleThrowsFromCall(defaultSuperCtor, mapper, context); context.cfg().map(mapper, superCall); ArrayList origStatements = createBlock(n.getBody(), context); @@ -657,14 +659,14 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { /** * Make a "fake" function (it doesn't exist in source code but it does in bytecode) for covariant return types. - * @param overriding - * Declaration of the overriding method. - * @param overridden - * Binding of the overridden method, in a a superclass or implemented interface. + * + * @param overriding Declaration of the overriding method. + * @param overridden Binding of the overridden method, in a a superclass or implemented interface. * @param oldContext * @return */ - private CAstEntity makeSyntheticCovariantRedirect(MethodDeclaration overriding, IMethodBinding overridingBinding, IMethodBinding overridden, WalkContext oldContext) { + private CAstEntity makeSyntheticCovariantRedirect(MethodDeclaration overriding, IMethodBinding overridingBinding, + IMethodBinding overridden, WalkContext oldContext) { // SuperClass foo(A, B, C...) // SubClass foo(A,B,C...) // @@ -678,49 +680,47 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { calltarget = makeNode(context, fFactory, null, CAstNode.THIS); else calltarget = makeNode(context, fFactory, null, CAstNode.VOID); - + ITypeBinding paramTypes[] = overridden.getParameterTypes(); - + ArrayList arguments = new ArrayList(); int i = 0; - for ( Object o: overriding.parameters() ) { + for (Object o : overriding.parameters()) { SingleVariableDeclaration svd = (SingleVariableDeclaration) o; CAstNode varNode = makeNode(context, fFactory, null, CAstNode.VAR, fFactory.makeConstant(svd.getName().getIdentifier())); ITypeBinding fromType = JDT2CAstUtils.getErasedType(paramTypes[i], ast); ITypeBinding toType = JDT2CAstUtils.getErasedType(overridingBinding.getParameterTypes()[i], ast); - if ( fromType.equals(toType) ) + if (fromType.equals(toType)) arguments.add(varNode); else arguments.add(createCast(null, varNode, fromType, toType, context)); - // add cast if necessary. Should only + // add cast if necessary. Should only i++; } CAstNode callnode = createMethodInvocation(null, overridingBinding, calltarget, arguments, context); - CAstNode mdast = makeNode(context, fFactory, null, CAstNode.LOCAL_SCOPE, - makeNode(context, fFactory, null, CAstNode.BLOCK_STMT, - makeNode(context, fFactory, null, CAstNode.RETURN, callnode))); + CAstNode mdast = makeNode(context, fFactory, null, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, null, CAstNode.BLOCK_STMT, + makeNode(context, fFactory, null, CAstNode.RETURN, callnode))); // make parameters to new synthetic method // use RETURN TYPE of overridden, everything else from overriding (including parameter names) - ArrayList paramCAstTypes= new ArrayList(overridden.getParameterTypes().length); - for ( ITypeBinding paramType: overridden.getParameterTypes() ) + ArrayList paramCAstTypes = new ArrayList(overridden.getParameterTypes().length); + for (ITypeBinding paramType : overridden.getParameterTypes()) paramCAstTypes.add(fTypeDict.getCAstTypeFor(paramType)); - return new ProcedureEntity(mdast, overriding, overridingBinding.getDeclaringClass(), memberEntities, context, paramCAstTypes, overridden.getReturnType()); + return new ProcedureEntity(mdast, overriding, overridingBinding.getDeclaringClass(), memberEntities, context, paramCAstTypes, + overridden.getReturnType()); } - + /** - * @param inits Instance intializers & field initializers. Only used if method is a constructor, in which case the - * initializers will be inserted in. + * @param inits Instance intializers & field initializers. Only used if method is a constructor, in which case the initializers + * will be inserted in. */ private CAstEntity visit(MethodDeclaration n, ITypeBinding classBinding, WalkContext oldContext, ArrayList inits) { // pass in memberEntities to the context, later visit(New) etc. may add classes final Map memberEntities = new LinkedHashMap(); final MethodContext context = new MethodContext(oldContext, memberEntities); // LEFTOUT: in polyglot there is a - // class context in between method and - // root - - + // class context in between method and + // root CAstNode mdast; @@ -787,7 +787,6 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { this(mdast, decl, type, entities, context, null, null, decl.getModifiers()); } - // static init private ProcedureEntity(CAstNode mdast, ITypeBinding type, Map entities, MethodContext context) { this(mdast, null, type, entities, context, null, null, 0); @@ -795,9 +794,9 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private ProcedureEntity(CAstNode mdast, MethodDeclaration decl, ITypeBinding type, Map entities, MethodContext context, ArrayList parameterTypes, ITypeBinding returnType) { - this(mdast,decl,type,entities,context,parameterTypes,returnType,decl.getModifiers()); + this(mdast, decl, type, entities, context, parameterTypes, returnType, decl.getModifiers()); } - + private ProcedureEntity(CAstNode mdast, MethodDeclaration decl, ITypeBinding type, Map entities, MethodContext context, ArrayList parameterTypes, ITypeBinding returnType, int modifiers) { // TypeSystem system, CodeInstance pd, String[] argumentNames, @@ -916,9 +915,9 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { @SuppressWarnings("deprecation") public CAstType getReturnType() { - if ( fReturnType != null ) + if (fReturnType != null) return fTypeDict.getCAstTypeFor(fReturnType); - Type type = fDecl==null ? null : (ast.apiLevel() == 2 ? fDecl.getReturnType() : fDecl.getReturnType2()); + Type type = fDecl == null ? null : (ast.apiLevel() == 2 ? fDecl.getReturnType() : fDecl.getReturnType2()); if (type == null) return fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("void")); else @@ -999,8 +998,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { return assNode; // their naming, not mine - } else if ( node instanceof EnumConstantDeclaration ) { - return createEnumConstantDeclarationInit((EnumConstantDeclaration)node, context); + } else if (node instanceof EnumConstantDeclaration) { + return createEnumConstantDeclarationInit((EnumConstantDeclaration) node, context); } else { Assertions.UNREACHABLE("invalid init node gathered by createClassDeclaration"); return null; @@ -1009,10 +1008,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { protected final class FieldEntity implements CAstEntity { private final ITypeBinding type; - private final String name; - private final Collection quals; - private final JdtPosition position; + private final String name; + + private final Collection quals; + + private final JdtPosition position; private FieldEntity(String name, ITypeBinding type, Collection quals, JdtPosition position) { super(); @@ -1073,7 +1074,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } public CAstSourcePositionMap.Position getPosition() { - return position; + return position; } public CAstNodeTypeMap getNodeTypeMap() { @@ -1172,10 +1173,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } private CAstNode visit(ClassInstanceCreation n, WalkContext context) { - return createClassInstanceCreation(n, n.arguments(), n.resolveConstructorBinding(), n.getExpression(), n.getAnonymousClassDeclaration(), context); + return createClassInstanceCreation(n, n.arguments(), n.resolveConstructorBinding(), n.getExpression(), n + .getAnonymousClassDeclaration(), context); } - - private CAstNode createClassInstanceCreation(ASTNode nn, List/*Expression or CAstNode*/ arguments, IMethodBinding ctorBinding, Expression qual, AnonymousClassDeclaration anonDecl, WalkContext context) { + + private CAstNode createClassInstanceCreation(ASTNode nn, List/* Expression or CAstNode */arguments, IMethodBinding ctorBinding, + Expression qual, AnonymousClassDeclaration anonDecl, WalkContext context) { // a new instruction is actually two things: a NEW object and a CALL to a constructor CAstNode newNode; CAstNode callNode; @@ -1184,8 +1187,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // GENERICS getMethodDeclaration() ctorBinding = ctorBinding.getMethodDeclaration(); // unlike polyglot, this will - // point to a default - // constructor in the anon class + // point to a default + // constructor in the anon class MethodReference ctorRef = fIdentityMapper.getMethodRef(ctorBinding); // ////////////// PART I: make the NEW expression /////////////////////////////////////////////////////// @@ -1197,18 +1200,18 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // in JavaCAst2IRTranslator.doNewObject CAstNode qualNode = null; - if (qual == null && newType.getDeclaringClass() != null && - ((newType.getModifiers() & Modifier.STATIC) == 0) && !newType.isLocal()) { + if (qual == null && newType.getDeclaringClass() != null && ((newType.getModifiers() & Modifier.STATIC) == 0) + && !newType.isLocal()) { // "new X()" expanded into "new this.X()" or "new MyClass.this.X" // check isLocal because anonymous classes and local classes are not included. ITypeBinding plainThisType = JDT2CAstUtils.getDeclaringClassOfNode(nn); // type of "this" - ITypeBinding implicitThisType = findClosestEnclosingClassSubclassOf(plainThisType, - newType.getDeclaringClass(), ((newType.getModifiers() & Modifier.PRIVATE) != 0)); + ITypeBinding implicitThisType = findClosestEnclosingClassSubclassOf(plainThisType, newType.getDeclaringClass(), ((newType + .getModifiers() & Modifier.PRIVATE) != 0)); if (implicitThisType.isEqualTo(plainThisType)) qualNode = makeNode(context, fFactory, nn, CAstNode.THIS); // "new this.X()" else - qualNode = makeNode(context, fFactory, nn, CAstNode.THIS, fFactory - .makeConstant(fIdentityMapper.getTypeRef(implicitThisType))); // "new Bla.this.X()" + qualNode = makeNode(context, fFactory, nn, CAstNode.THIS, fFactory.makeConstant(fIdentityMapper + .getTypeRef(implicitThisType))); // "new Bla.this.X()" } else if (qual != null) qualNode = visitNode(qual, context); @@ -1217,16 +1220,14 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { else newNode = makeNode(context, fFactory, nn, CAstNode.NEW, fFactory.makeConstant(newTypeRef)); - ITypeBinding[] newExceptions = new ITypeBinding[]{ - NoClassDefFoundError, ExceptionInInitializerError, OutOfMemoryError - }; - context.cfg().map(newNode, newNode); - for(ITypeBinding exp : newExceptions) { - for (Pair catchTarget : context.getCatchTargets(exp)) { - context.cfg().add(newNode, catchTarget.snd, catchTarget.fst); - } + ITypeBinding[] newExceptions = new ITypeBinding[] { NoClassDefFoundError, ExceptionInInitializerError, OutOfMemoryError }; + context.cfg().map(newNode, newNode); + for (ITypeBinding exp : newExceptions) { + for (Pair catchTarget : context.getCatchTargets(exp)) { + context.cfg().add(newNode, catchTarget.snd, catchTarget.fst); + } } - + // ANONYMOUS CLASSES // ctor already points to right place, so should type ref, so all we have to do is make the entity if (anonDecl != null) @@ -1250,7 +1251,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // rest of args for (Iterator iter = arguments.iterator(); iter.hasNext();) { Object arg = iter.next(); - argNodes[idx++] = (arg instanceof CAstNode) ? ((CAstNode)arg) : visitNode((Expression) arg, context); + argNodes[idx++] = (arg instanceof CAstNode) ? ((CAstNode) arg) : visitNode((Expression) arg, context); } callNode = makeNode(context, fFactory, nn, CAstNode.CALL, argNodes); context.cfg().map(nn, callNode); @@ -1265,16 +1266,15 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // 3) access this temporary variable. Since the value of the block is the last thing in the block, the resultant // value will be the variable return makeNode(context, fFactory, nn, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, nn, CAstNode.BLOCK_EXPR, makeNode( - context, fFactory, nn, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpName, true)), newNode), callNode, - makeNode(context, fFactory, nn, CAstNode.VAR, fFactory.makeConstant(tmpName)))); + context, fFactory, nn, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpName, true)), newNode), + callNode, makeNode(context, fFactory, nn, CAstNode.VAR, fFactory.makeConstant(tmpName)))); } /** * * @param met - * @param mappedAstNode - * An AST node or object mapped in the CFG: we will call context.cfg().add() on it. - * Caller must worry about mapping it with context.cfg().map(). + * @param mappedAstNode An AST node or object mapped in the CFG: we will call context.cfg().add() on it. Caller must worry about + * mapping it with context.cfg().map(). * @param context */ private void handleThrowsFromCall(IMethodBinding met, Object mappedAstNode, WalkContext context) { @@ -1316,7 +1316,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // in which case we replace the EMPTY with a VOID // of course, "this" has no side effects either. target = visitNode(n.getExpression(), context); - if (target.getKind() == CAstNode.EMPTY || target.getKind() == CAstNode.THIS ) + if (target.getKind() == CAstNode.EMPTY || target.getKind() == CAstNode.THIS) return createMethodInvocation(n, binding, makeNode(context, fFactory, null, CAstNode.VOID), n.arguments(), context); else return makeNode(context, fFactory, n, CAstNode.BLOCK_EXPR, target, createMethodInvocation(n, binding, makeNode(context, @@ -1353,17 +1353,17 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // TODO: maybe not exactly right... what if it's a capture? we may have to cast it down a little bit. if (binding.getReturnType().isTypeVariable()) { // GENERICS: add a cast - ITypeBinding realtype = JDT2CAstUtils.getErasedType(n.resolveMethodBinding().getReturnType(),ast); - ITypeBinding fromtype = JDT2CAstUtils.getTypesVariablesBase(binding.getReturnType(),ast); - if ( ! realtype.isEqualTo(fromtype) ) + ITypeBinding realtype = JDT2CAstUtils.getErasedType(n.resolveMethodBinding().getReturnType(), ast); + ITypeBinding fromtype = JDT2CAstUtils.getTypesVariablesBase(binding.getReturnType(), ast); + if (!realtype.isEqualTo(fromtype)) return createCast(n, node, fromtype, realtype, context); } return node; } } - private CAstNode createMethodInvocation(ASTNode pos, IMethodBinding methodBinding, CAstNode target, List/* Expression or CAstNode */arguments, - WalkContext context) { + private CAstNode createMethodInvocation(ASTNode pos, IMethodBinding methodBinding, CAstNode target, + List/* Expression or CAstNode */arguments, WalkContext context) { // MethodMethodInstance methodInstance = n.methodInstance(); boolean isStatic = (methodBinding.getModifiers() & Modifier.STATIC) != 0; ITypeBinding methodOwner = methodBinding.getDeclaringClass(); @@ -1395,13 +1395,13 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { dispatchType = IInvokeInstruction.Dispatch.VIRTUAL; // pass 0 for dummyPC: Just want to wrap the kind of call; the "rear end" won't care about anything else... CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(methodBinding), dispatchType); - + children[1] = fFactory.makeConstant(callSiteRef); populateArguments(children, methodBinding, arguments, context); - + Object fakeCfgMap = new Object(); - + handleThrowsFromCall(methodBinding, fakeCfgMap, context); CAstNode result = makeNode(context, fFactory, pos, CAstNode.CALL, children); @@ -1410,54 +1410,57 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } /** - * Populate children, starting at index 2, for the invocation of methodBinding. - * If varargs are used this function will collapse the proper arguments into an array. + * Populate children, starting at index 2, for the invocation of methodBinding. If varargs are used this function will collapse + * the proper arguments into an array. + * + * If the number of actuals equals the number of formals and the function is varargs, we have to check the type of the last + * argument to see if we should "box" it in an array. If the arguments[arguments.length-1] is not an Expression, we cannot get the + * type, so we do not box it. (Making covariant varargs functions require this behavior) * - * If the number of actuals equals the number of formals and the function is varargs, - * we have to check the type of the last argument to see if we should "box" it in an array. - * If the arguments[arguments.length-1] is not an Expression, we cannot get the type, so we do - * not box it. (Making covariant varargs functions require this behavior) - * * @param children * @param methodBinding * @param arguments * @param context */ - private void populateArguments(CAstNode[] children, IMethodBinding methodBinding, List/*CAstNode or Expression*/ arguments, WalkContext context) { + private void populateArguments(CAstNode[] children, IMethodBinding methodBinding, List/* CAstNode or Expression */arguments, + WalkContext context) { int nFormals = methodBinding.getParameterTypes().length; Assertions._assert(children.length == nFormals + 2); int nActuals = arguments.size(); ITypeBinding lastArgType = null; - if ( nActuals > 0 && arguments.get(nActuals-1) instanceof Expression ) - lastArgType = ((Expression)arguments.get(nActuals-1)).resolveTypeBinding(); + if (nActuals > 0 && arguments.get(nActuals - 1) instanceof Expression) + lastArgType = ((Expression) arguments.get(nActuals - 1)).resolveTypeBinding(); // if the # of actuals equals the # of formals, AND the function is varargs, we have to check // to see if the lastArgType is subtype compatible with the type of last parameter (which will be an array). // If it is, we pass this array in directly. Otherwise this it is wrapped in an array init. - // Example: 'void foo(int... x)' can be run via 'foo(5)' or 'foo(new int[] { 5, 6 })' -- both have one argument so we must check the type - - if ( nActuals == nFormals && (!methodBinding.isVarargs() || - lastArgType == null || lastArgType.isSubTypeCompatible(methodBinding.getParameterTypes()[nFormals-1])) ) { + // Example: 'void foo(int... x)' can be run via 'foo(5)' or 'foo(new int[] { 5, 6 })' -- both have one argument so we must check + // the type + + if (nActuals == nFormals + && (!methodBinding.isVarargs() || lastArgType == null || lastArgType + .isSubTypeCompatible(methodBinding.getParameterTypes()[nFormals - 1]))) { int i = 2; for (Object arg : arguments) - children[i++] = ( arg instanceof CAstNode ) ? ((CAstNode) arg) : visitNode((Expression)arg, context); + children[i++] = (arg instanceof CAstNode) ? ((CAstNode) arg) : visitNode((Expression) arg, context); } else { - Assertions._assert(nActuals >= (nFormals-1) && methodBinding.isVarargs(), "Invalid number of parameters for constructor call"); - for ( int i = 0; i < nFormals-1; i++ ) { + Assertions._assert(nActuals >= (nFormals - 1) && methodBinding.isVarargs(), + "Invalid number of parameters for constructor call"); + for (int i = 0; i < nFormals - 1; i++) { Object arg = arguments.get(i); - children[i+2] = ( arg instanceof CAstNode ) ? ((CAstNode) arg) : visitNode((Expression)arg, context); + children[i + 2] = (arg instanceof CAstNode) ? ((CAstNode) arg) : visitNode((Expression) arg, context); } - + CAstNode subargs[] = new CAstNode[nActuals - nFormals + 2]; // nodes for args and one extra for NEW expression - TypeReference newTypeRef = fIdentityMapper.getTypeRef(methodBinding.getParameterTypes()[nFormals-1]); - subargs[0] = makeNode(context, fFactory, null, CAstNode.NEW, fFactory.makeConstant(newTypeRef), - fFactory.makeConstant(subargs.length-1)); - for ( int j = 1; j < subargs.length; j++ ) { - Object arg = arguments.get(j+nFormals-2); - subargs[j] = ( arg instanceof CAstNode ) ? ((CAstNode) arg) : visitNode((Expression)arg, context); + TypeReference newTypeRef = fIdentityMapper.getTypeRef(methodBinding.getParameterTypes()[nFormals - 1]); + subargs[0] = makeNode(context, fFactory, null, CAstNode.NEW, fFactory.makeConstant(newTypeRef), fFactory + .makeConstant(subargs.length - 1)); + for (int j = 1; j < subargs.length; j++) { + Object arg = arguments.get(j + nFormals - 2); + subargs[j] = (arg instanceof CAstNode) ? ((CAstNode) arg) : visitNode((Expression) arg, context); } - children[nFormals+1] = makeNode(context, fFactory, (ASTNode)null, CAstNode.ARRAY_LITERAL, subargs); + children[nFormals + 1] = makeNode(context, fFactory, (ASTNode) null, CAstNode.ARRAY_LITERAL, subargs); } } @@ -1471,18 +1474,18 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private CAstNode visit(Assignment n, WalkContext context) { if (n.getOperator() == Assignment.Operator.ASSIGN) - return makeNode(context, fFactory, n, CAstNode.ASSIGN, - visitNode(n.getLeftHandSide(), new AssignmentContext(context)), + return makeNode(context, fFactory, n, CAstNode.ASSIGN, visitNode(n.getLeftHandSide(), new AssignmentContext(context)), visitNode(n.getRightHandSide(), context)); else { CAstNode left = visitNode(n.getLeftHandSide(), context); // GENERICs lvalue for pre op hack - if ( left.getKind() == CAstNode.CAST ) { + if (left.getKind() == CAstNode.CAST) { return doFunkyGenericAssignPreOpHack(n, context); } - + // +=, %=, &=, etc. - CAstNode result = makeNode(context, fFactory, n, CAstNode.ASSIGN_PRE_OP, left, visitNode(n.getRightHandSide(), context), JDT2CAstUtils.mapAssignOperator(n.getOperator())); + CAstNode result = makeNode(context, fFactory, n, CAstNode.ASSIGN_PRE_OP, left, visitNode(n.getRightHandSide(), context), + JDT2CAstUtils.mapAssignOperator(n.getOperator())); // integer division by zero if (JDT2CAstUtils.isLongOrLess(n.resolveTypeBinding()) @@ -1502,13 +1505,16 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { /** * Consider the case: - *
String real_oneheyya = (((returnObjectWithSideEffects().y))+="hey")+"ya"
- * where field 'y' is parameterized to type string. then += is not defined for type 'object'. - * This function is a hack that expands the code into an assignment and binary operation. * - * @param leftCast - * this is the left cast in the original expression. We throw most of it away, although we use - * the "Cast from" and "cast to" + *
+   * String real_oneheyya = (((returnObjectWithSideEffects().y))+="hey")+"ya"
+   * 
+ * + * where field 'y' is parameterized to type string. then += is not defined for type 'object'. This function is a hack that expands + * the code into an assignment and binary operation. + * + * @param leftCast this is the left cast in the original expression. We throw most of it away, although we use the "Cast from" and + * "cast to" * @param left * @param context * @return @@ -1516,50 +1522,50 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private CAstNode doFunkyGenericAssignPreOpHack(Assignment assign, WalkContext context) { Expression left = assign.getLeftHandSide(); Expression right = assign.getRightHandSide(); - + // consider the case: // String real_oneheyya = (((returnObjectWithSideEffects().y))+="hey")+"ya"; // this is going to be a MAJOR pain... // where field 'y' is parameterized to type string. then += is not defined for type 'object'. we want to transform // it kind of like this, except we have to define temp. // String real_oneheyya = (String)((temp=cg2WithSideEffects()).y = (String)temp.y + "hey")+"ya"; - // ---------------------------------------------------------------- + // ---------------------------------------------------------------- // // we are responsible for underlined portion - // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) + // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, + // left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) // yeah, I know, it's cheating, LOCAL SCOPE / DECL STMT inside an expression ... will it work? - + while (left instanceof ParenthesizedExpression) - left = ((ParenthesizedExpression)left).getExpression(); + left = ((ParenthesizedExpression) left).getExpression(); Assertions._assert(left instanceof FieldAccess, "Cast in assign pre-op but no field access?!"); - + FieldAccess field = (FieldAccess) left; InfixExpression.Operator infixop = JDT2CAstUtils.mapAssignOperatorToInfixOperator(assign.getOperator()); - + // DECL_STMT: temp = ...; final String tmpName = "temp generic preop hack"; // illegal Java identifier CAstNode exprNode = visitNode(field.getExpression(), context); - CAstNode tmpDeclNode = makeNode(context, fFactory, left, CAstNode.DECL_STMT, - fFactory.makeConstant(new InternalCAstSymbol(tmpName, true)), - exprNode); + CAstNode tmpDeclNode = makeNode(context, fFactory, left, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol( + tmpName, true)), exprNode); // need two object refndoes "temp.y" - CAstNode obref1 = createFieldAccess(makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName)), - field.getName().getIdentifier(), field.resolveFieldBinding(), left, new AssignmentContext(context)); + CAstNode obref1 = createFieldAccess(makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName)), field + .getName().getIdentifier(), field.resolveFieldBinding(), left, new AssignmentContext(context)); - CAstNode obref2 = createFieldAccess(makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName)), - field.getName().getIdentifier(), field.resolveFieldBinding(), left, context); - ITypeBinding realtype = JDT2CAstUtils.getErasedType(field.resolveFieldBinding().getType(),ast); - ITypeBinding fromtype = JDT2CAstUtils.getTypesVariablesBase(field.resolveFieldBinding().getVariableDeclaration().getType(),ast); - CAstNode castedObref = obref2;//createCast(left, obref2, fromtype, realtype, context); + CAstNode obref2 = createFieldAccess(makeNode(context, fFactory, left, CAstNode.VAR, fFactory.makeConstant(tmpName)), field + .getName().getIdentifier(), field.resolveFieldBinding(), left, context); + ITypeBinding realtype = JDT2CAstUtils.getErasedType(field.resolveFieldBinding().getType(), ast); + ITypeBinding fromtype = JDT2CAstUtils + .getTypesVariablesBase(field.resolveFieldBinding().getVariableDeclaration().getType(), ast); + CAstNode castedObref = obref2;// createCast(left, obref2, fromtype, realtype, context); // put it all together - // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) - CAstNode result = makeNode(context, fFactory, assign, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, assign, CAstNode.BLOCK_EXPR, - tmpDeclNode, - makeNode(context, fFactory, assign, CAstNode.ASSIGN, - obref1, - createInfixExpression(infixop, realtype, left.getStartPosition(), left.getLength(), castedObref, right, context)))); - + // CAST(LOCAL SCOPE(BLOCK EXPR(DECL STMT(temp, + // left.target),ASSIGN(OBJECT_REF(temp,y),BINARY_EXPR(CAST(OBJECT_REF(Temp,y)),RIGHT))))) + CAstNode result = makeNode(context, fFactory, assign, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, assign, + CAstNode.BLOCK_EXPR, tmpDeclNode, makeNode(context, fFactory, assign, CAstNode.ASSIGN, obref1, createInfixExpression( + infixop, realtype, left.getStartPosition(), left.getLength(), castedObref, right, context)))); + return createCast(assign, result, fromtype, realtype, context); } @@ -1587,7 +1593,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { String typeName = fIdentityMapper.typeToTypeID(n.resolveTypeBinding()); return makeNode(context, fFactory, n, CAstNode.TYPE_LITERAL_EXPR, fFactory.makeConstant(typeName)); } - + private CAstNode visit(NumberLiteral n, WalkContext context) { return fFactory.makeConstant(n.resolveConstantExpressionValue()); } @@ -1608,7 +1614,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { IVariableBinding binding = (IVariableBinding) n.resolveBinding(); binding = binding.getVariableDeclaration(); // ignore weird generic stuff - + // TODO: enum constants if (binding.isField()) { // enum constants ... @@ -1619,8 +1625,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { if ((binding.getModifiers() & Modifier.STATIC) != 0) { // "foo = 5" -> "MyClass.foo = 5" or "SomeEnclosingClass.foo" = 5 targetNode = makeNode(context, fFactory, null, CAstNode.EMPTY); // we will get type from binding. no side - // effects in evaluating a class name, so NOP - // here. + // effects in evaluating a class name, so NOP + // here. } else { ITypeBinding typeOfThis = JDT2CAstUtils.getDeclaringClassOfNode(n); @@ -1654,13 +1660,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } /** - * Sees if a field defined in owningTypeRef is contained & accessible to a type of typeOfThis. That is, if - * owningTypeRef == typeOfThis or typeOfThis is a subtype and isPrivate is false. If this is not that case, looks in - * the enclosing class of typeOfThis and tries again, and its enclosing class, ... + * Sees if a field defined in owningTypeRef is contained & accessible to a type of typeOfThis. That is, if owningTypeRef == + * typeOfThis or typeOfThis is a subtype and isPrivate is false. If this is not that case, looks in the enclosing class of + * typeOfThis and tries again, and its enclosing class, ... * - * Essentially if we have a field/method referenced only by name and we know its type (owningTypeRef), this function - * will return owningTypeRef or the subtype that the field is accessed thru, for expanding "f = 5" into - * "TheClass.this.f = 5". + * Essentially if we have a field/method referenced only by name and we know its type (owningTypeRef), this function will return + * owningTypeRef or the subtype that the field is accessed thru, for expanding "f = 5" into "TheClass.this.f = 5". * * @param typeOfThis * @param owningTypeRef @@ -1669,11 +1674,11 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { */ private ITypeBinding findClosestEnclosingClassSubclassOf(ITypeBinding typeOfThis, ITypeBinding owningType, boolean isPrivate) { // GENERICS - if ( owningType.isParameterizedType() ) + if (owningType.isParameterizedType()) owningType = owningType.getTypeDeclaration(); - if ( typeOfThis.isParameterizedType() ) + if (typeOfThis.isParameterizedType()) typeOfThis = typeOfThis.getTypeDeclaration(); -// typeOfThis.getTypeDeclaration() + // typeOfThis.getTypeDeclaration() ITypeBinding current = typeOfThis; while (current != null) { @@ -1687,14 +1692,15 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { current = current.getDeclaringClass(); } - + Assertions.UNREACHABLE("Couldn't find field in class or enclosing class or superclasses of these"); return null; } /** - * Process a field access. Semantics differ for static and instance fields. Fields can throw null pointer exceptions - * so we must connect proper exceptional edges in the CFG. + * Process a field access. Semantics differ for static and instance fields. Fields can throw null pointer exceptions so we must + * connect proper exceptional edges in the CFG. + * * @param n * @param context * @return @@ -1705,22 +1711,23 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } /** - * Used by visit(FieldAccess) and visit(SimpleName) -- implicit "this" / static field access. things from 'this' - * cannot throw an exception. maybe handle this in here as a special case? i don't know... or check if targetNode is - * THIS, that should even work for this.x = 5 and (this).x = 5 - * @param target Used to evaluate the field access. In the case of static field accesses, this is included in the - * first part of a block -- thus it is evaluated for any side effects but thrown away. + * Used by visit(FieldAccess) and visit(SimpleName) -- implicit "this" / static field access. things from 'this' cannot throw an + * exception. maybe handle this in here as a special case? i don't know... or check if targetNode is THIS, that should even work + * for this.x = 5 and (this).x = 5 + * + * @param target Used to evaluate the field access. In the case of static field accesses, this is included in the first part of a + * block -- thus it is evaluated for any side effects but thrown away. * @param fieldName Name of the field. * @param fieldBinding This is used to determine the field's class. * @param positioningNode Used only for making a JdtPosition. * @param context * @return */ - private CAstNode createFieldAccess(CAstNode targetNode, String fieldName, IVariableBinding possiblyParameterizedBinding, ASTNode positioningNode, - WalkContext context) { - + private CAstNode createFieldAccess(CAstNode targetNode, String fieldName, IVariableBinding possiblyParameterizedBinding, + ASTNode positioningNode, WalkContext context) { + IVariableBinding fieldBinding = possiblyParameterizedBinding.getVariableDeclaration(); - + ITypeBinding targetType = fieldBinding.getDeclaringClass(); if (targetType == null) { // array @@ -1729,7 +1736,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } Assertions._assert(fieldBinding.isField(), "Field binding is not a field?!"); // we can probably safely delete this - // check + // check // translate JDT field ref to WALA field ref FieldReference fieldRef = fIdentityMapper.getFieldRef(fieldBinding); @@ -1757,7 +1764,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { .makeConstant(fieldRef)); if (targetNode.getKind() != CAstNode.THIS) { // this.x will never throw a null pointer exception, because this - // can never be null + // can never be null Collection excTargets = context.getCatchTargets(fNullPointerExcType); if (!excTargets.isEmpty()) { // connect NPE exception edge to relevant catch targets @@ -1774,17 +1781,17 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { context.cfg().map(refNode, refNode); } - if (fieldBinding.getConstantValue() != null ) { + if (fieldBinding.getConstantValue() != null) { // don't have to worry about generics, a constant of generic type can only be null return makeNode(context, fFactory, positioningNode, CAstNode.BLOCK_EXPR, refNode, - // evaluating 'refNode' can have side effects, so we must still evaluate it! + // evaluating 'refNode' can have side effects, so we must still evaluate it! fFactory.makeConstant(fieldBinding.getConstantValue())); } else { - if (fieldBinding.getType().isTypeVariable() && !context.needLValue() ) { + if (fieldBinding.getType().isTypeVariable() && !context.needLValue()) { // GENERICS: add a cast - ITypeBinding realtype = JDT2CAstUtils.getErasedType(possiblyParameterizedBinding.getType(),ast); - ITypeBinding fromtype = JDT2CAstUtils.getTypesVariablesBase(fieldBinding.getType(),ast); - if ( ! realtype.isEqualTo(fromtype) ) + ITypeBinding realtype = JDT2CAstUtils.getErasedType(possiblyParameterizedBinding.getType(), ast); + ITypeBinding fromtype = JDT2CAstUtils.getTypesVariablesBase(fieldBinding.getType(), ast); + if (!realtype.isEqualTo(fromtype)) return createCast(positioningNode, refNode, fromtype, realtype, context); } return refNode; @@ -1803,10 +1810,11 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } /** - * QualifiedNames may be: 1) static of non-static field accesses -- we handle this case here 2) type names used in the - * context of: a) field access (QualifiedName) b) method invocation c) qualifier of "this" in these cases we get the - * binding info in each of these three functions and use them there, thus we return an EMPTY (no-op) here. 3) package - * names used in the context of a QualifiedName class we return a EMPTY (no-op) here. + * QualifiedNames may be: 1) static of non-static field accesses -- we handle this case here 2) type names used in the context of: + * a) field access (QualifiedName) b) method invocation c) qualifier of "this" in these cases we get the binding info in each of + * these three functions and use them there, thus we return an EMPTY (no-op) here. 3) package names used in the context of a + * QualifiedName class we return a EMPTY (no-op) here. + * * @param n * @param context * @return @@ -1835,23 +1843,24 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { CAstNode leftNode = visitNode(left, context); int leftLength = n.getLeftOperand().getLength(); - CAstNode result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, leftNode, n.getRightOperand(), context); + CAstNode result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, leftNode, + n.getRightOperand(), context); if (n.hasExtendedOperands()) { // keep on adding operands on the right side - leftLength = n.getRightOperand().getStartPosition()+n.getRightOperand().getLength() - leftStartPosition; + leftLength = n.getRightOperand().getStartPosition() + n.getRightOperand().getLength() - leftStartPosition; for (Object o : n.extendedOperands()) { Expression operand = (Expression) o; result = createInfixExpression(n.getOperator(), leftType, leftStartPosition, leftLength, result, operand, context); - + if (leftType.isPrimitive() && operand.resolveTypeBinding().isPrimitive()) leftType = JDT2CAstUtils.promoteTypes(leftType, operand.resolveTypeBinding(), ast); // TODO: boxing else leftType = operand.resolveTypeBinding(); - + // leftStartPosition doesn't change, beginning is always the first operand - leftLength = operand.getStartPosition()+operand.getLength() - leftStartPosition; + leftLength = operand.getStartPosition() + operand.getLength() - leftStartPosition; } } @@ -1865,8 +1874,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { int start = leftStartPosition; int end = right.getStartPosition() + right.getLength(); JdtPosition pos = makePosition(start, end); - JdtPosition rightPos = makePosition(leftStartPosition, leftStartPosition+leftLength); - JdtPosition leftPos = makePosition(right.getStartPosition(), right.getStartPosition()+right.getLength()); + JdtPosition rightPos = makePosition(leftStartPosition, leftStartPosition + leftLength); + JdtPosition leftPos = makePosition(right.getStartPosition(), right.getStartPosition() + right.getLength()); if (op == InfixExpression.Operator.CONDITIONAL_AND) { return makeNode(context, fFactory, pos, CAstNode.IF_EXPR, leftNode, rightNode, fFactory.makeConstant(false)); @@ -1959,7 +1968,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { children[1] = fFactory.makeConstant(callSiteRef); populateArguments(children, ctorBinding, arguments, context); - + handleThrowsFromCall(ctorBinding, callerNode, context); CAstNode result = makeNode(context, fFactory, callerNode, CAstNode.CALL, children); @@ -1987,7 +1996,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private CAstNode createCast(ASTNode pos, CAstNode argNode, ITypeBinding castedFrom, ITypeBinding castedTo, WalkContext context) { Object cfgMapDummy = new Object(); // safer as 'pos' may be used for another purpose (i.e., this could be an implicit cast) - + // null can go into anything (e.g. in "((Foobar) null)" null can be assumed to be of type Foobar already) if (castedFrom.isNullType()) castedFrom = castedTo; @@ -2054,7 +2063,6 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { return makeNode(context, fFactory, n, CAstNode.ASSERT, visitNode(n.getExpression(), context)); } - // //////////////// // LOOPS -- special handling of for and continue // //////////////// @@ -2072,18 +2080,16 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { context.getLabelMap().put(stmt, n.getLabel().getIdentifier()); CAstNode result; - if (! (n.getBody() instanceof EmptyStatement)) { + if (!(n.getBody() instanceof EmptyStatement)) { WalkContext child = new BreakContext(context, n.getLabel().getIdentifier(), breakTarget); - result = - makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, - makeNode(context, fFactory, n, CAstNode.LABEL_STMT, fFactory.makeConstant(n.getLabel().getIdentifier()), visitNode(n.getBody(), child)), - visitNode(breakTarget, context)); + result = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, makeNode(context, fFactory, n, CAstNode.LABEL_STMT, fFactory + .makeConstant(n.getLabel().getIdentifier()), visitNode(n.getBody(), child)), visitNode(breakTarget, context)); } else { - result = - makeNode(context, fFactory, n, CAstNode.LABEL_STMT, fFactory.makeConstant(n.getLabel().getIdentifier()), visitNode(n.getBody(), context)); + result = makeNode(context, fFactory, n, CAstNode.LABEL_STMT, fFactory.makeConstant(n.getLabel().getIdentifier()), visitNode(n + .getBody(), context)); } - + context.cfg().map(n, result); if (n.getParent() != null) @@ -2101,7 +2107,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { labeled.setBody(ast.newEmptyStatement()); labeled.setSourceRange(loop.getStartPosition(), loop.getLength()); labeled.setLabel(ast.newSimpleName(name)); // we don't have to worry about namespace conflicts as it is only - // definedwithin + // definedwithin return labeled; } @@ -2147,10 +2153,10 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // TODO: enums Expression expr = n.getExpression(); Object constant = (expr == null) ? new Integer(0) : expr.resolveConstantExpressionValue(); // default case label of - // "0" (what polyglot - // does). we also set - // SWITCH_DEFAULT - // somewhere else + // "0" (what polyglot + // does). we also set + // SWITCH_DEFAULT + // somewhere else // polyglot converts all labels to longs. why? who knows... if (constant instanceof Character) constant = new Long(((Character) constant).charValue()); @@ -2161,11 +2167,11 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { else if (constant instanceof Short) constant = new Long(((Short) constant).longValue()); - if ( constant != null ) { + if (constant != null) { return fFactory.makeConstant(constant); - } else if ( expr instanceof SimpleName ) { + } else if (expr instanceof SimpleName) { // enum constant - return visit((SimpleName)expr, context); + return visit((SimpleName) expr, context); } else { Assertions.UNREACHABLE("null constant for non-enum switch case!"); return null; @@ -2183,7 +2189,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition()); CAstNode breakAst = visitNode(breakTarget, context); String loopLabel = (String) context.getLabelMap().get(n); // set by labeled statement (if there is one before this - // switch statement) + // switch statement) WalkContext childContext = new BreakContext(context, loopLabel, breakTarget); Expression cond = n.getExpression(); List/* */cases = n.statements(); @@ -2269,34 +2275,33 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { /** * Expands the form: for ( [final] Type var: iterable ) { ... } Into something equivalent to: for ( Iterator iter = - * iterable.iter(); iter.hasNext(); ) { [final] Type var = (Type) iter.next(); ... } Or, in the case of an array: for ( - * int idx = 0; i < iterable.length; i++ ) { [final] Type var = iterable[idx]; ... } Except that the expression - * "iterable" is only evaluate once (or is it?) + * iterable.iter(); iter.hasNext(); ) { [final] Type var = (Type) iter.next(); ... } Or, in the case of an array: for ( int idx = + * 0; i < iterable.length; i++ ) { [final] Type var = iterable[idx]; ... } Except that the expression "iterable" is only evaluate + * once (or is it?) * * @param n * @param context * @return */ private CAstNode visit(EnhancedForStatement n, WalkContext context) { - if ( n.getExpression().resolveTypeBinding().isArray() ) + if (n.getExpression().resolveTypeBinding().isArray()) return makeArrayEnhancedForLoop(n, context); else - return makeIteratorEnhancedForLoop(n,context); - } - + return makeIteratorEnhancedForLoop(n, context); + } + private CAstNode makeIteratorEnhancedForLoop(EnhancedForStatement n, WalkContext context) { // case 1: iterator CAstNode exprNode = visitNode(n.getExpression(), context); SingleVariableDeclaration svd = n.getParameter(); Statement body = n.getBody(); - + // expand into: - + // typical for loop: // { [inits]; while (cond) { [body]; [label continueTarget]; iters } [label breakTarget] // BLOCK(BLOCK(init1,init2,...),LOOP(cond,BLOCK(bodyblock,continuetarget,BLOCK(iter1,iter2,...))),breaktarget - - + // in our case: // the only init is "Iterator iter = iterable.iter()" // cond is "iter.hasNext()" @@ -2305,164 +2310,147 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // continuetarget and breaktarget are the same as in a regular for loop // BLOCK(iterassign,LOOP(cond,BLOCK(paramassign,bodyblock,continuetarget)),breaktarget) - final String tmpName = "iter tmp"; // this is an illegal Java identifier, we will use this variable to hold the "invisible" iterator - + final String tmpName = "iter tmp"; // this is an illegal Java identifier, we will use this variable to hold the "invisible" + // iterator + /*-------- make "iter = iterator.iter()" ---------*/ // make a fake method ref - MethodReference iterMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/lang/Iterable;.iterator()Ljava/util/Iterator;","Ljava/lang/Iterable","iterator","Ljava/util/Iterator"); - CAstNode iterCallSiteRef = fFactory.makeConstant(CallSiteReference.make(0, iterMethodRef, IInvokeInstruction.Dispatch.INTERFACE)); + MethodReference iterMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/lang/Iterable;.iterator()Ljava/util/Iterator;", + "Ljava/lang/Iterable", "iterator", "Ljava/util/Iterator"); + CAstNode iterCallSiteRef = fFactory.makeConstant(CallSiteReference + .make(0, iterMethodRef, IInvokeInstruction.Dispatch.INTERFACE)); // Iterable.iter() throws no exceptions. - + CAstNode iterCallNode = makeNode(context, fFactory, n, CAstNode.CALL, exprNode, iterCallSiteRef); // handle runtimeexception - Object o1 = new Object(); // dummy object used for mapping / exceptions + Object o1 = new Object(); // dummy object used for mapping / exceptions for (Pair catchTarget : context.getCatchTargets(fRuntimeExcType)) context.cfg().add(o1, catchTarget.snd, catchTarget.fst); context.cfg().map(o1, iterCallNode); // TODO: this might not work, lots of calls in this one statement. - CAstNode iterAssignNode = makeNode( - context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpName, true)), iterCallNode); + CAstNode iterAssignNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol( + tmpName, true)), iterCallNode); // MATCHUP: wrap in a block - iterAssignNode = makeNode ( context, fFactory, n, CAstNode.BLOCK_STMT, iterAssignNode); - + iterAssignNode = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, iterAssignNode); + // TODO: TOTEST: using this and Iterable.hasNext() explicitly in same file. - + /*---------- cond: iter.hasNext(); -----------*/ - MethodReference hasNextMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/util/Iterator;.hasNext()Z","Ljava/util/Iterator","hasNext","Z"); - CAstNode iterVar = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpName)); - CAstNode hasNextCallSiteRef = fFactory.makeConstant(CallSiteReference.make(0, hasNextMethodRef, IInvokeInstruction.Dispatch.INTERFACE)); + MethodReference hasNextMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/util/Iterator;.hasNext()Z", + "Ljava/util/Iterator", "hasNext", "Z"); + CAstNode iterVar = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpName)); + CAstNode hasNextCallSiteRef = fFactory.makeConstant(CallSiteReference.make(0, hasNextMethodRef, + IInvokeInstruction.Dispatch.INTERFACE)); // throws no exceptions. CAstNode hasNextCallNode = makeNode(context, fFactory, n, CAstNode.CALL, iterVar, hasNextCallSiteRef); // handle runtimeexception - Object o2 = new Object(); // dummy object used for mapping / exceptions + Object o2 = new Object(); // dummy object used for mapping / exceptions for (Pair catchTarget : context.getCatchTargets(fRuntimeExcType)) context.cfg().add(o2, catchTarget.snd, catchTarget.fst); context.cfg().map(o2, hasNextCallNode); // TODO: this might not work, lots of calls in this one statement. /*---------- paramassign: var = (Type) iter.next() ---------*/ - MethodReference nextMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/util/Iterator;.next()TE;","Ljava/util/Iterator","next","Ljava/lang/Object"); - CAstNode nextCallSiteRef = fFactory.makeConstant(CallSiteReference.make(0, nextMethodRef, IInvokeInstruction.Dispatch.INTERFACE)); + MethodReference nextMethodRef = fIdentityMapper.fakeMethodRefNoArgs("Ljava/util/Iterator;.next()TE;", "Ljava/util/Iterator", + "next", "Ljava/lang/Object"); + CAstNode nextCallSiteRef = fFactory.makeConstant(CallSiteReference + .make(0, nextMethodRef, IInvokeInstruction.Dispatch.INTERFACE)); // throws no exceptions. - CAstNode iterVar2 = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpName)); + CAstNode iterVar2 = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpName)); CAstNode nextCallNode = makeNode(context, fFactory, n, CAstNode.CALL, iterVar2, nextCallSiteRef); for (Pair catchTarget : context.getCatchTargets(fRuntimeExcType)) context.cfg().add(svd, catchTarget.snd, catchTarget.fst); context.cfg().map(svd, nextCallNode); - + // TODO: another cfg edge associated with svd! is this okay? prolly not... associate it with the cast, somehow... - CAstNode castedNode = createCast(svd, nextCallNode, ast.resolveWellKnownType("java.lang.Object"), svd.resolveBinding().getType(), context); + CAstNode castedNode = createCast(svd, nextCallNode, ast.resolveWellKnownType("java.lang.Object"), svd.resolveBinding() + .getType(), context); Object defaultValue = JDT2CAstUtils.defaultValueForType(svd.resolveBinding().getType()); - CAstNode nextAssignNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(svd.getName().getIdentifier(), - (svd.getModifiers() & Modifier.FINAL) != 0, defaultValue)), castedNode); + CAstNode nextAssignNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(svd + .getName().getIdentifier(), (svd.getModifiers() & Modifier.FINAL) != 0, defaultValue)), castedNode); - /*----------- put it all together ----------*/ ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition()); ASTNode continueTarget = makeBreakOrContinueTarget(n, "continueLabel" + n.getStartPosition()); String loopLabel = (String) context.getLabelMap().get(n); WalkContext loopContext = new LoopContext(context, loopLabel, breakTarget, continueTarget); - + // LOCAL_SCOPE(BLOCK(iterassign,LOOP(cond,BLOCK(BLOCK(paramassign,bodyblock),continuetarget,BLOCK())),breaktarget)) - return makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE,makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, - iterAssignNode, - makeNode(context, fFactory, n, CAstNode.LOOP, - hasNextCallNode, - makeNode(context, fFactory, n, CAstNode.BLOCK_STMT,makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, - makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, - nextAssignNode, - visitNode(body, loopContext))), - visitNode(continueTarget, context), - makeNode(context, fFactory, n, CAstNode.BLOCK_STMT))), - visitNode(breakTarget, context))); + return makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, iterAssignNode, + makeNode(context, fFactory, n, CAstNode.LOOP, hasNextCallNode, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, + makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, + nextAssignNode, visitNode(body, loopContext))), visitNode(continueTarget, context), makeNode(context, fFactory, n, + CAstNode.BLOCK_STMT))), visitNode(breakTarget, context))); } - + private CAstNode makeArrayEnhancedForLoop(EnhancedForStatement n, WalkContext context) { // ********* BEFORE: // for ( String x: doSomething() ) { ... } // ********* AFTER: // { - // String tmparray[] = doSomething(); - // for ( int tmpindex = 0; i < tmparray.length; tmpindex++ ) { - // String x = tmparray[tmpindex]; - // ... - // } + // String tmparray[] = doSomething(); + // for ( int tmpindex = 0; i < tmparray.length; tmpindex++ ) { + // String x = tmparray[tmpindex]; + // ... // } - // simplest: + // } + // simplest: // LOCAL_SCOPE(BLOCK(arrayDecl,indexDecl,LOOP(cond,BLOCK(nextAssign,bodyblock,continuetarget,iter)),breaktarget)) - // match up exactly: + // match up exactly: // LOCAL_SCOPE(BLOCK(arrayDecl,LOCAL_SCOPE(BLOCK(BLOCK(indexDecl),LOOP(cond,BLOCK(LOCAL_SCOPE(BLOCK(nextAssign,bodyblock)),continuetarget,BLOCK(iter))),breaktarget)))) - + /*------ arrayDecl --------- String tmparray[] = doSomething() ------*/ final String tmpArrayName = "for temp array"; // illegal java identifier CAstNode exprNode = visitNode(n.getExpression(), context); - CAstNode arrayDeclNode = makeNode( - context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpArrayName, true)), exprNode); - + CAstNode arrayDeclNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol( + tmpArrayName, true)), exprNode); + /*------ indexDecl --------- int tmpindex = 0 ------*/ final String tmpIndexName = "for temp index"; - CAstNode indexDeclNode = makeNode( - context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol(tmpIndexName, true)), - fFactory.makeConstant(new Integer(0))); + CAstNode indexDeclNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new InternalCAstSymbol( + tmpIndexName, true)), fFactory.makeConstant(new Integer(0))); /*------ cond ------------- tmpindex < tmparray.length ------*/ - CAstNode tmpArrayLengthNode = makeNode(context, fFactory, n, CAstNode.ARRAY_LENGTH, - makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpArrayName))); - CAstNode condNode = makeNode(context, fFactory, n, CAstNode.BINARY_EXPR, - CAstOperator.OP_LT, - makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpIndexName)), - tmpArrayLengthNode); - + CAstNode tmpArrayLengthNode = makeNode(context, fFactory, n, CAstNode.ARRAY_LENGTH, makeNode(context, fFactory, n, + CAstNode.VAR, fFactory.makeConstant(tmpArrayName))); + CAstNode condNode = makeNode(context, fFactory, n, CAstNode.BINARY_EXPR, CAstOperator.OP_LT, makeNode(context, fFactory, n, + CAstNode.VAR, fFactory.makeConstant(tmpIndexName)), tmpArrayLengthNode); + /*------ tmpIndexInc -------- tmpindex++ ------*/ - CAstNode tmpArrayIncNode = makeNode(context, fFactory, n, CAstNode.ASSIGN_POST_OP, - makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpIndexName)), - fFactory.makeConstant(1), - CAstOperator.OP_ADD); + CAstNode tmpArrayIncNode = makeNode(context, fFactory, n, CAstNode.ASSIGN_POST_OP, makeNode(context, fFactory, n, CAstNode.VAR, + fFactory.makeConstant(tmpIndexName)), fFactory.makeConstant(1), CAstOperator.OP_ADD); /*------ tmpArrayAccess ----- String x = tmparray[tmpindex] ------*/ - CAstNode tmpArrayAccessNode = makeNode(context, fFactory, n, CAstNode.ARRAY_REF, - makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpArrayName)), - fFactory.makeConstant(fIdentityMapper.getTypeRef(n.getExpression().resolveTypeBinding().getComponentType())), - makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpIndexName))); + CAstNode tmpArrayAccessNode = makeNode(context, fFactory, n, CAstNode.ARRAY_REF, makeNode(context, fFactory, n, CAstNode.VAR, + fFactory.makeConstant(tmpArrayName)), fFactory.makeConstant(fIdentityMapper.getTypeRef(n.getExpression() + .resolveTypeBinding().getComponentType())), makeNode(context, fFactory, n, CAstNode.VAR, fFactory + .makeConstant(tmpIndexName))); SingleVariableDeclaration svd = n.getParameter(); Object defaultValue = JDT2CAstUtils.defaultValueForType(svd.resolveBinding().getType()); - CAstNode nextAssignNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(svd.getName().getIdentifier(), - (svd.getModifiers() & Modifier.FINAL) != 0, defaultValue)), tmpArrayAccessNode); + CAstNode nextAssignNode = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(svd + .getName().getIdentifier(), (svd.getModifiers() & Modifier.FINAL) != 0, defaultValue)), tmpArrayAccessNode); // LOCAL_SCOPE(BLOCK(arrayDecl,LOCAL_SCOPE(BLOCK(BLOCK(indexDecl),LOOP(cond,BLOCK(LOCAL_SCOPE(BLOCK(nextAssign,bodyblock)),continuetarget,BLOCK(iter))),breaktarget)))) // more complicated than it has to be, but it matches up exactly with the Java expansion above. - + ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition()); ASTNode continueTarget = makeBreakOrContinueTarget(n, "continueLabel" + n.getStartPosition()); String loopLabel = (String) context.getLabelMap().get(n); WalkContext loopContext = new LoopContext(context, loopLabel, breakTarget, continueTarget); - - return makeNode(context,fFactory,n,CAstNode.LOCAL_SCOPE,makeNode(context,fFactory,n,CAstNode.BLOCK_STMT, - arrayDeclNode, - makeNode(context,fFactory,n,CAstNode.LOCAL_SCOPE,makeNode(context,fFactory,n,CAstNode.BLOCK_STMT, - makeNode(context,fFactory,n,CAstNode.BLOCK_STMT,indexDeclNode), - makeNode(context,fFactory,n,CAstNode.LOOP, - condNode, - makeNode(context,fFactory,n,CAstNode.BLOCK_STMT, - makeNode(context,fFactory,n,CAstNode.LOCAL_SCOPE,makeNode(context,fFactory,n,CAstNode.BLOCK_STMT, - nextAssignNode, - visitNode(n.getBody(),loopContext) - )), - visitNode(continueTarget,context), - makeNode(context,fFactory,n,CAstNode.BLOCK_STMT,tmpArrayIncNode) - ) - ), - visitNode(breakTarget,context) - )) - )); - - - + + return makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, + makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, arrayDeclNode, makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, + makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, indexDeclNode), + makeNode(context, fFactory, n, CAstNode.LOOP, condNode, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, + makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, + nextAssignNode, visitNode(n.getBody(), loopContext))), visitNode(continueTarget, context), makeNode( + context, fFactory, n, CAstNode.BLOCK_STMT, tmpArrayIncNode))), visitNode(breakTarget, context))))); + } - + private CAstNode visit(ForStatement n, WalkContext context) { ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition()); ASTNode continueTarget = makeBreakOrContinueTarget(n, "continueLabel" + n.getStartPosition()); @@ -2487,10 +2475,10 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { CAstNode itersBlock = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, iters); // { [inits]; while (cond) { [body]; [label continueTarget]; iters } [label breakTarget] - return makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, - makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, initsBlock, makeNode(context, fFactory, n, CAstNode.LOOP, visitNode( - n.getExpression(), context), makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, visitNode(n.getBody(), loopContext), - visitNode(continueTarget, context), itersBlock)), visitNode(breakTarget, context))); + return makeNode(context, fFactory, n, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, initsBlock, + makeNode(context, fFactory, n, CAstNode.LOOP, visitNode(n.getExpression(), context), makeNode(context, fFactory, n, + CAstNode.BLOCK_STMT, visitNode(n.getBody(), loopContext), visitNode(continueTarget, context), itersBlock)), visitNode( + breakTarget, context))); } @@ -2595,21 +2583,21 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { String exprName = fFactory.makeUnique(); CAstNode declStmt = makeNode(context, fFactory, n, CAstNode.DECL_STMT, fFactory .makeConstant(new CAstSymbolImpl(exprName, true)), exprNode); - + CAstNode monitorEnterNode = makeNode(context, fFactory, n, CAstNode.MONITOR_ENTER, makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(exprName))); context.cfg().map(monitorEnterNode, monitorEnterNode); for (Pair catchTarget : context.getCatchTargets(fNullPointerExcType)) - context.cfg().add(monitorEnterNode, catchTarget.snd, catchTarget.fst); + context.cfg().add(monitorEnterNode, catchTarget.snd, catchTarget.fst); CAstNode bodyNodes = visitNode(n.getBody(), context); - + CAstNode monitorExitNode = makeNode(context, fFactory, n, CAstNode.MONITOR_EXIT, makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(exprName))); context.cfg().map(monitorExitNode, monitorExitNode); for (Pair catchTarget : context.getCatchTargets(fNullPointerExcType)) - context.cfg().add(monitorExitNode, catchTarget.snd, catchTarget.fst); - + context.cfg().add(monitorExitNode, catchTarget.snd, catchTarget.fst); + CAstNode tryBody = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, monitorEnterNode, bodyNodes); CAstNode bigBody = makeNode(context, fFactory, n, CAstNode.UNWIND, tryBody, monitorExitNode); @@ -2622,6 +2610,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { /** * Giant switch statement. + * * @param n * @return */ @@ -2629,7 +2618,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // handling of compilationunit in translate() if (n instanceof TypeDeclaration) { return visit((TypeDeclaration) n, context); - } else if ( n instanceof EnumDeclaration ) { + } else if (n instanceof EnumDeclaration) { return visit((EnumDeclaration) n, context); // TODO: enumdeclaration and annotationtypedeclaration } @@ -2639,6 +2628,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { /** * Giant switch statement, part deux + * * @param body * @param context * @return @@ -2753,13 +2743,12 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } private void visitNodeOrNodes(ASTNode n, WalkContext context, Collection coll) { - if ( n instanceof VariableDeclarationStatement ) - coll.addAll(visit((VariableDeclarationStatement)n,context)); + if (n instanceof VariableDeclarationStatement) + coll.addAll(visit((VariableDeclarationStatement) n, context)); else - coll.add(visitNode(n,context)); + coll.add(visitNode(n, context)); } - // ///////////////////////////////////////// // SPECIALIZED CASTENTITYs AND CASTNODEs // // ///////////////////////////////////////// @@ -2848,8 +2837,8 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // //////////////////////////////// /** - * Contains things needed by in the visit() of some nodes to process the nodes. For example, pos() contains the source - * position mapping which each node registers + * Contains things needed by in the visit() of some nodes to process the nodes. For example, pos() contains the source position + * mapping which each node registers */ public static interface WalkContext { // LEFTOUT: plenty of stuff @@ -2868,13 +2857,13 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { public ASTNode getContinueFor(String label); public ASTNode getBreakFor(String label); - + public boolean needLValue(); } /** - * Default context functions. When one context doesn't handle something, it the next one up does. For example, there - * is only one source pos. mapping per MethodContext, so loop contexts delegate it up. + * Default context functions. When one context doesn't handle something, it the next one up does. For example, there is only one + * source pos. mapping per MethodContext, so loop contexts delegate it up. */ public static class DelegatingContext implements WalkContext { protected WalkContext parent; @@ -2979,7 +2968,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { return true; } } - + private static class TryCatchContext extends DelegatingContext { Collection> fCatchNodes = new ArrayList>(); @@ -3096,7 +3085,7 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { CAstControlFlowMap.EXCEPTION_TO_EXIT)); return result; } - + public boolean needLValue() { return false; } @@ -3232,9 +3221,9 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { } } - /////////////////////////////////////////////////////////////////// - //// ENUM TRANSFORMATION ////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// + // ///////////////////////////////////////////////////////////////// + // // ENUM TRANSFORMATION ////////////////////////////////////////// + // ///////////////////////////////////////////////////////////////// private static final ArrayList enumQuals = new ArrayList(3); static { @@ -3242,21 +3231,22 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { enumQuals.add(CAstQualifier.STATIC); enumQuals.add(CAstQualifier.FINAL); } - + /** * Only called from createClassDeclaration. + * * @param decl * @param context * @return */ private CAstEntity visit(EnumConstantDeclaration decl, WalkContext context) { - return new FieldEntity(decl.getName().getIdentifier(), - decl.resolveVariable().getType(), enumQuals, - makePosition(decl.getStartPosition(), decl.getStartPosition() + decl.getLength())); + return new FieldEntity(decl.getName().getIdentifier(), decl.resolveVariable().getType(), enumQuals, makePosition(decl + .getStartPosition(), decl.getStartPosition() + decl.getLength())); } /** * Called only from visitFieldInitNode(node,context) + * * @param node * @param context * @return @@ -3264,28 +3254,29 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { @SuppressWarnings("unchecked") private CAstNode createEnumConstantDeclarationInit(EnumConstantDeclaration node, WalkContext context) { String hiddenVariableName = (String) node.getProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclName"); - if ( hiddenVariableName == null ) { + if (hiddenVariableName == null) { FieldReference fieldRef = fIdentityMapper.getFieldRef(node.resolveVariable()); // We use null to indicate an OBJECT_REF to a static field - CAstNode lhsNode = makeNode(context, fFactory, node, CAstNode.OBJECT_REF, makeNode(context, fFactory, null, CAstNode.VOID), fFactory.makeConstant(fieldRef)); + CAstNode lhsNode = makeNode(context, fFactory, node, CAstNode.OBJECT_REF, makeNode(context, fFactory, null, CAstNode.VOID), + fFactory.makeConstant(fieldRef)); // CONSTRUCT ARGUMENTS & "new MyEnum(...)" statement ArrayList arguments = new ArrayList(); arguments.add(fFactory.makeConstant(node.getName().getIdentifier())); // name of constant arguments.add(fFactory.makeConstant(node.resolveVariable().getVariableId())); // id arguments.addAll(node.arguments()); - CAstNode rhsNode = createClassInstanceCreation(node, arguments, node.resolveConstructorBinding(), - null, node.getAnonymousClassDeclaration(), context); + CAstNode rhsNode = createClassInstanceCreation(node, arguments, node.resolveConstructorBinding(), null, node + .getAnonymousClassDeclaration(), context); CAstNode assNode = makeNode(context, fFactory, node, CAstNode.ASSIGN, lhsNode, rhsNode); return assNode; // their naming, not mine } else { - -// String[] x = (new Direction[] { -// NORTH, EAST, SOUTH, WEST, $VALUES, $VALUES$ -// }); - + + // String[] x = (new Direction[] { + // NORTH, EAST, SOUTH, WEST, $VALUES, $VALUES$ + // }); + return null; } } @@ -3294,41 +3285,41 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private CAstEntity createEnumValueOfMethod(ITypeBinding enumType, WalkContext oldContext) { IMethodBinding met = null, superMet = null; // find our valueOf(String) - for ( IMethodBinding m: enumType.getDeclaredMethods() ) - if ( m.getName().equals("valueOf") && m.getParameterTypes().length == 1 && m.getParameterTypes()[0].isEqualTo(ast.resolveWellKnownType("java.lang.String")) ) + for (IMethodBinding m : enumType.getDeclaredMethods()) + if (m.getName().equals("valueOf") && m.getParameterTypes().length == 1 + && m.getParameterTypes()[0].isEqualTo(ast.resolveWellKnownType("java.lang.String"))) met = m; // find Enum.valueOf(Class, String) - for ( IMethodBinding m: enumType.getSuperclass().getTypeDeclaration().getDeclaredMethods() ) - if ( m.getName().equals("valueOf") && m.getParameterTypes().length == 2 ) + for (IMethodBinding m : enumType.getSuperclass().getTypeDeclaration().getDeclaredMethods()) + if (m.getName().equals("valueOf") && m.getParameterTypes().length == 2) superMet = m; - Assertions._assert(met!=null && superMet!=null, "Couldn't find enum values() function in JDT bindings!"); + Assertions._assert(met != null && superMet != null, "Couldn't find enum values() function in JDT bindings!"); - Map memberEntities = new LinkedHashMap(); + Map memberEntities = new LinkedHashMap(); final MethodContext context = new MethodContext(oldContext, memberEntities); - MethodDeclaration fakeMet = ast.newMethodDeclaration(); fakeMet.setName(ast.newSimpleName("valueOf")); - fakeMet.setSourceRange(-1,0); + fakeMet.setSourceRange(-1, 0); fakeMet.setBody(ast.newBlock()); SingleVariableDeclaration stringS = ast.newSingleVariableDeclaration(); stringS.setName(ast.newSimpleName("s")); fakeMet.parameters().add(stringS); - // TODO: probably uses reflection so isn't very useful for analyses. Is there something more useful we could put in here? // return (MyEnum)Enum.valueOf(MyEnum.class, s); // cast(call(type_literal, var))) - CAstNode typeLit = makeNode(context, fFactory, fakeMet, CAstNode.TYPE_LITERAL_EXPR, fFactory.makeConstant(fIdentityMapper.typeToTypeID(enumType))); + CAstNode typeLit = makeNode(context, fFactory, fakeMet, CAstNode.TYPE_LITERAL_EXPR, fFactory.makeConstant(fIdentityMapper + .typeToTypeID(enumType))); CAstNode stringSvar = makeNode(context, fFactory, fakeMet, CAstNode.VAR, fFactory.makeConstant("s")); ArrayList args = new ArrayList(); args.add(typeLit); args.add(stringSvar); CAstNode call = createMethodInvocation(fakeMet, superMet, makeNode(context, fFactory, fakeMet, CAstNode.VOID), args, context); CAstNode cast = createCast(fakeMet, call, enumType, superMet.getReturnType(), context); - CAstNode bodyNode = makeNode(context, fFactory, fakeMet, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, fakeMet, CAstNode.BLOCK_STMT, - makeNode(context, fFactory, fakeMet, CAstNode.RETURN, cast))); + CAstNode bodyNode = makeNode(context, fFactory, fakeMet, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, fakeMet, + CAstNode.BLOCK_STMT, makeNode(context, fFactory, fakeMet, CAstNode.RETURN, cast))); ArrayList paramTypes = new ArrayList(1); paramTypes.add(fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("java.lang.String"))); @@ -3338,101 +3329,103 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { private CAstEntity createEnumValuesMethod(ITypeBinding enumType, ArrayList constants, WalkContext oldContext) { IMethodBinding met = null; - for ( IMethodBinding m: enumType.getDeclaredMethods() ) - if ( m.getName().equals("values") && m.getParameterTypes().length == 0 ) + for (IMethodBinding m : enumType.getDeclaredMethods()) + if (m.getName().equals("values") && m.getParameterTypes().length == 0) met = m; - Assertions._assert(met!=null, "Couldn't find enum values() function in JDT bindings!"); + Assertions._assert(met != null, "Couldn't find enum values() function in JDT bindings!"); - Map memberEntities = new LinkedHashMap(); + Map memberEntities = new LinkedHashMap(); final MethodContext context = new MethodContext(oldContext, memberEntities); MethodDeclaration fakeMet = ast.newMethodDeclaration(); fakeMet.setName(ast.newSimpleName("values")); - fakeMet.setSourceRange(-1,0); + fakeMet.setSourceRange(-1, 0); fakeMet.setBody(ast.newBlock()); - // make enum constant values array: new MyEnum() { MYENUMCST1, MYENUMCST2, ... } + // make enum constant values array: new MyEnum() { MYENUMCST1, MYENUMCST2, ... } CAstNode[] eltNodes = new CAstNode[constants.size() + 1]; int idx = 0; TypeReference arrayTypeRef = fIdentityMapper.getTypeRef(enumType.createArrayType(1)); - eltNodes[idx++] = makeNode(context, fFactory, fakeMet, CAstNode.NEW, fFactory.makeConstant(arrayTypeRef), fFactory.makeConstant(constants.size())); - for (IVariableBinding cst: constants) - eltNodes[idx++] = createFieldAccess(makeNode(context,fFactory,fakeMet,CAstNode.VOID), cst.getName(), cst, fakeMet, context); + eltNodes[idx++] = makeNode(context, fFactory, fakeMet, CAstNode.NEW, fFactory.makeConstant(arrayTypeRef), fFactory + .makeConstant(constants.size())); + for (IVariableBinding cst : constants) + eltNodes[idx++] = createFieldAccess(makeNode(context, fFactory, fakeMet, CAstNode.VOID), cst.getName(), cst, fakeMet, context); - CAstNode bodyNode = makeNode(context, fFactory, fakeMet, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, fakeMet, CAstNode.BLOCK_STMT, - makeNode(context, fFactory, fakeMet, CAstNode.RETURN, makeNode(context, fFactory, fakeMet, CAstNode.ARRAY_LITERAL, eltNodes)))); + CAstNode bodyNode = makeNode(context, fFactory, fakeMet, CAstNode.LOCAL_SCOPE, makeNode(context, fFactory, fakeMet, + CAstNode.BLOCK_STMT, makeNode(context, fFactory, fakeMet, CAstNode.RETURN, makeNode(context, fFactory, fakeMet, + CAstNode.ARRAY_LITERAL, eltNodes)))); ArrayList paramTypes = new ArrayList(0); - return new ProcedureEntity(bodyNode, fakeMet, enumType, memberEntities, context, paramTypes, enumType.createArrayType(1), met.getModifiers()); + return new ProcedureEntity(bodyNode, fakeMet, enumType, memberEntities, context, paramTypes, enumType.createArrayType(1), met + .getModifiers()); } - private void doEnumHiddenEntities(ITypeBinding typeBinding, ArrayList staticInits, List memberEntities, WalkContext context) { + private void doEnumHiddenEntities(ITypeBinding typeBinding, ArrayList staticInits, List memberEntities, + WalkContext context) { // PART I: create a $VALUES field // collect constants -// ArrayList constants = new ArrayList(); -// for ( ASTNode n: staticInits ) -// if ( n instanceof EnumConstantDeclaration ) -// constants.add(((EnumConstantDeclaration)n).getName().getIdentifier()); + // ArrayList constants = new ArrayList(); + // for ( ASTNode n: staticInits ) + // if ( n instanceof EnumConstantDeclaration ) + // constants.add(((EnumConstantDeclaration)n).getName().getIdentifier()); // figure out a suitable untaken name -// String hiddenFieldName = "hidden values field"; // illegal name -// // public static final MyEnum[] $VALUES; -// memberEntities.add(new FieldEntity(hiddenFieldName, -// typeBinding.createArrayType(1), enumQuals, -// makePosition(-1,-1))); -// -// EnumConstantDeclaration fakeValuesDecl = ast.newEnumConstantDeclaration(); -// // pass along values that we will use in createEnumConstantDeclarationInit() in creating static initializer -// fakeValuesDecl.setProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclName", hiddenFieldName); -// fakeValuesDecl.setProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclConstants", constants); -// staticInits.add(fakeValuesDecl); + // String hiddenFieldName = "hidden values field"; // illegal name + // // public static final MyEnum[] $VALUES; + // memberEntities.add(new FieldEntity(hiddenFieldName, + // typeBinding.createArrayType(1), enumQuals, + // makePosition(-1,-1))); + // + // EnumConstantDeclaration fakeValuesDecl = ast.newEnumConstantDeclaration(); + // // pass along values that we will use in createEnumConstantDeclarationInit() in creating static initializer + // fakeValuesDecl.setProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclName", hiddenFieldName); + // fakeValuesDecl.setProperty("com.ibm.wala.cast.java.translator.jdt.fakeValuesDeclConstants", constants); + // staticInits.add(fakeValuesDecl); ArrayList constants = new ArrayList(); - for ( IVariableBinding var: typeBinding.getDeclaredFields() ) - if ( var.isEnumConstant() ) + for (IVariableBinding var : typeBinding.getDeclaredFields()) + if (var.isEnumConstant()) constants.add(var); - + // constants are unsorted by default - Collections.sort(constants,new Comparator() { + Collections.sort(constants, new Comparator() { public int compare(IVariableBinding arg0, IVariableBinding arg1) { return arg0.getVariableId() - arg1.getVariableId(); } }); - + // PART II: create values() memberEntities.add(createEnumValuesMethod(typeBinding, constants, context)); - + // PART III: create valueOf() memberEntities.add(createEnumValueOfMethod(typeBinding, context)); } - + private CAstEntity visit(EnumDeclaration n, WalkContext context) { - // JDT contains correct type info / class / subclass info for the enum - return createClassDeclaration(n, n.bodyDeclarations(), n.enumConstants(), n.resolveBinding(), n.getName().getIdentifier(), n.resolveBinding().getModifiers(), false, context); - } - + return createClassDeclaration(n, n.bodyDeclarations(), n.enumConstants(), n.resolveBinding(), n.getName().getIdentifier(), n + .resolveBinding().getModifiers(), false, context); + } /** * @param n for positioning. */ @SuppressWarnings("unchecked") - private CAstEntity createEnumConstructorWithParameters(IMethodBinding ctor, ASTNode n, WalkContext oldContext, ArrayList inits, MethodDeclaration nonDefaultCtor) { // PART I: find super ctor to call ITypeBinding newType = ctor.getDeclaringClass(); ITypeBinding javalangenumType = newType.getSuperclass(); IMethodBinding superCtor = null; - - if ( newType.isEnum() ) { - for ( IMethodBinding met: javalangenumType.getDeclaredMethods() ) - if ( met.isConstructor() ) { + + if (newType.isEnum()) { + for (IMethodBinding met : javalangenumType.getDeclaredMethods()) + if (met.isConstructor()) { superCtor = met; break; } } - + Assertions._assert(superCtor != null, "enum"); // PART II: make ctor with simply "super(a,b,c...)" @@ -3446,19 +3439,22 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { // PART IIa: make a fake JDT constructor method with the proper number of args // Make fake args that will be passed - String[] fakeArguments = new String[3+ctor.getParameterTypes().length]; - if ( nonDefaultCtor == null ) { + String[] fakeArguments = new String[3 + ctor.getParameterTypes().length]; + if (nonDefaultCtor == null) { for (int i = 3; i < fakeArguments.length; i++) - fakeArguments[i] = "__wala_jdtcast_argument" + i; // this is in the case of an anonymous class with parameters, eg NORTH in the following example: public enum A { NORTH("south") { ...} A(String s){} } + fakeArguments[i] = "__wala_jdtcast_argument" + i; // this is in the case of an anonymous class with parameters, eg NORTH in + // the following example: public enum A { NORTH("south") { ...} A(String + // s){} } } else { for (int i = 3; i < fakeArguments.length; i++) - fakeArguments[i] = ((SingleVariableDeclaration)nonDefaultCtor.parameters().get(i-3)).getName().getIdentifier(); + fakeArguments[i] = ((SingleVariableDeclaration) nonDefaultCtor.parameters().get(i - 3)).getName().getIdentifier(); } ArrayList paramTypes = new ArrayList(superCtor.getParameterTypes().length); fakeArguments[0] = "this"; fakeArguments[1] = "__wala_jdtcast_argument1"; // TODO FIXME: change to invalid name in the case that nonDefaultCtor != null - fakeArguments[2] = "__wala_jdtcast_argument2"; // otherwise there will be conflicts if we name our variable __wala_jdtcast_argument1!!! + fakeArguments[2] = "__wala_jdtcast_argument2"; // otherwise there will be conflicts if we name our variable + // __wala_jdtcast_argument1!!! for (int i = 1; i < fakeArguments.length; i++) { // the name SingleVariableDeclaration svd = ast.newSingleVariableDeclaration(); @@ -3466,28 +3462,28 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { fakeCtor.parameters().add(svd); // the type - if ( i == 1 ) + if (i == 1) paramTypes.add(fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("java.lang.String"))); - else if ( i == 2 ) + else if (i == 2) paramTypes.add(fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("int"))); else paramTypes.add(fTypeDict.getCAstTypeFor(ctor.getParameterTypes()[i - 3])); } - // PART IIb: create the statements in the constructor // one super() call plus the inits CAstNode[] bodyNodes; - if ( nonDefaultCtor == null ) + if (nonDefaultCtor == null) bodyNodes = new CAstNode[inits.size() + 1]; else bodyNodes = new CAstNode[inits.size() + 2]; - + // make super(...) call // this, call ref, args CAstNode[] children; - if ( ctor.isDefaultConstructor() ) - children = new CAstNode[4+ctor.getParameterTypes().length]; // anonymous class' implicit constructors call constructors with more than standard two enum args + if (ctor.isDefaultConstructor()) + children = new CAstNode[4 + ctor.getParameterTypes().length]; // anonymous class' implicit constructors call constructors with + // more than standard two enum args else children = new CAstNode[4]; // explicit constructor children[0] = makeNode(context, fFactory, n, CAstNode.SUPER); @@ -3497,26 +3493,23 @@ public class JDTJava2CAstTranslator implements TranslatorToCAst { children[2] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[1])); children[3] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[2])); - if ( ctor.isDefaultConstructor() ) - for ( int i = 0; i < ctor.getParameterTypes().length; i++ ) - children[i+4] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[i+3])); - - + if (ctor.isDefaultConstructor()) + for (int i = 0; i < ctor.getParameterTypes().length; i++) + children[i + 4] = makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(fakeArguments[i + 3])); + bodyNodes[0] = makeNode(context, fFactory, n, CAstNode.CALL, children); // QUESTION: no handleExceptions? for (int i = 0; i < inits.size(); i++) bodyNodes[i + 1] = visitFieldInitNode(inits.get(i), context); - if ( nonDefaultCtor != null ) - bodyNodes[bodyNodes.length-1] = visitNode(nonDefaultCtor.getBody(), context); - + if (nonDefaultCtor != null) + bodyNodes[bodyNodes.length - 1] = visitNode(nonDefaultCtor.getBody(), context); + // finally, make the procedure entity CAstNode ast = makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, bodyNodes); return new ProcedureEntity(ast, fakeCtor, newType, memberEntities, context, paramTypes, null); } - } - diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceLoaderImpl.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceLoaderImpl.java index cfad35d41..70b34c35d 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceLoaderImpl.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceLoaderImpl.java @@ -48,12 +48,12 @@ import com.ibm.wala.types.ClassLoaderReference; public class JDTSourceLoaderImpl extends JavaSourceLoaderImpl { - public JDTSourceLoaderImpl(ClassLoaderReference loaderRef, IClassLoader parent, SetOfClasses exclusions, - IClassHierarchy cha) throws IOException { - super(loaderRef, parent, exclusions, cha); - } + public JDTSourceLoaderImpl(ClassLoaderReference loaderRef, IClassLoader parent, SetOfClasses exclusions, IClassHierarchy cha) + throws IOException { + super(loaderRef, parent, exclusions, cha); + } - protected SourceModuleTranslator getTranslator() { - return new JDTSourceModuleTranslator(cha.getScope(), this); - } + protected SourceModuleTranslator getTranslator() { + return new JDTSourceModuleTranslator(cha.getScope(), this); + } } diff --git a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceModuleTranslator.java b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceModuleTranslator.java index c16ecceed..3552fc77c 100644 --- a/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceModuleTranslator.java +++ b/com.ibm.wala.cast.java.jdt/source/com/ibm/wala/cast/java/translator/jdt/JDTSourceModuleTranslator.java @@ -65,8 +65,9 @@ import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.util.debug.Assertions; /** - * A SourceModuleTranslator whose implementation of loadAllSources() uses the PolyglotFrontEnd pseudo-compiler to - * generate DOMO IR for the sources in the compile-time classpath. + * A SourceModuleTranslator whose implementation of loadAllSources() uses the PolyglotFrontEnd pseudo-compiler to generate DOMO IR + * for the sources in the compile-time classpath. + * * @author rfuhrer */ // remove me comment: Jdt little-case = not OK, upper case = OK @@ -105,31 +106,31 @@ public class JDTSourceModuleTranslator implements SourceModuleTranslator { cl = cl.getParent(); } } - -//Map options= javaProject.getOptions(true); -//// turn all errors and warnings into ignore. The customizable set of compiler -//// options only contains additional Eclipse options. The standard JDK compiler -//// options can't be changed anyway. -//for (Iterator iter= options.keySet().iterator(); iter.hasNext();) { -// String key= (String)iter.next(); -// String value= (String)options.get(key); -// if ("error".equals(value) || "warning".equals(value)) { //$NON-NLS-1$//$NON-NLS-2$ -// // System.out.println("Ignoring - " + key); -// options.put(key, "ignore"); //$NON-NLS-1$ -// } else if ("enabled".equals(value)) { -// // System.out.println(" - disabling " + key); -// options.put(key, "disabled"); -// } -//} -//options.put(JavaCore.COMPILER_TASK_TAGS, ""); -//parser.setCompilerOptions(options); + + // Map options= javaProject.getOptions(true); + // // turn all errors and warnings into ignore. The customizable set of compiler + // // options only contains additional Eclipse options. The standard JDK compiler + // // options can't be changed anyway. + // for (Iterator iter= options.keySet().iterator(); iter.hasNext();) { + // String key= (String)iter.next(); + // String value= (String)options.get(key); + // if ("error".equals(value) || "warning".equals(value)) { //$NON-NLS-1$//$NON-NLS-2$ + // // System.out.println("Ignoring - " + key); + // options.put(key, "ignore"); //$NON-NLS-1$ + // } else if ("enabled".equals(value)) { + // // System.out.println(" - disabling " + key); + // options.put(key, "disabled"); + // } + // } + // options.put(JavaCore.COMPILER_TASK_TAGS, ""); + // parser.setCompilerOptions(options); /* - * Project -> AST code from org.eclipse.jdt.core.tests.performance + * Project -> AST code from org.eclipse.jdt.core.tests.performance */ @SuppressWarnings("unchecked") -public void loadAllSources(Set modules) { + public void loadAllSources(Set modules) { // TODO: we might need one AST (-> "Object" class) for all files. // TODO: group by project and send 'em in JDTJava2CAstTranslator jdt2cast = new JDTJava2CAstTranslator(sourceLoader); @@ -137,14 +138,13 @@ public void loadAllSources(Set modules) { System.out.println(modules); - - // sort files into projects - HashMap> projectsFiles = new HashMap>(); - for ( Object m: modules ) { + // sort files into projects + HashMap> projectsFiles = new HashMap>(); + for (Object m : modules) { Assertions._assert(m instanceof EclipseSourceFileModule, "Expecing EclipseSourceFileModule"); EclipseSourceFileModule entry = (EclipseSourceFileModule) m; IProject proj = entry.getIFile().getProject(); - if ( ! projectsFiles.containsKey(proj) ) + if (!projectsFiles.containsKey(proj)) projectsFiles.put(proj, new ArrayList()); projectsFiles.get(proj).add(JavaCore.createCompilationUnitFrom(entry.getIFile())); } @@ -152,32 +152,31 @@ public void loadAllSources(Set modules) { final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); - for ( IProject proj: projectsFiles.keySet() ) { + for (IProject proj : projectsFiles.keySet()) { parser.setProject(JavaCore.create(proj)); ArrayList files = projectsFiles.get(proj); parser.createASTs(files.toArray(new ICompilationUnit[files.size()]), new String[0], new ASTRequestor() { public void acceptAST(ICompilationUnit source, CompilationUnit ast) { - + try { java2ir.translate(ast, source.getUnderlyingResource().getLocation().toOSString()); } catch (JavaModelException e) { e.printStackTrace(); } - + IProblem[] problems = ast.getProblems(); int length = problems.length; if (length > 0) { StringBuffer buffer = new StringBuffer(); - for (int i=0; i fSuperTypes = null; public String toString() { - return super.toString() + ":" +getName(); + return super.toString() + ":" + getName(); } - + public JdtJavaType(ITypeBinding type) { super(); fType = type; } public String getName() { - return fIdentityMapper.getTypeRef(fType).getName().toString(); + return fIdentityMapper.getTypeRef(fType).getName().toString(); } public Collection getSupertypes() { @@ -161,19 +161,20 @@ public class JDTTypeDictionary extends CAstTypeDictionaryImpl { private void buildSuperTypes() { // TODO this is a source entity, but it might actually be the root type // (Object), so assume # intfs + 1 - ITypeBinding superType = (fType.getSuperclass() == null) ? fAst.resolveWellKnownType("java.lang.Object") : fType.getSuperclass(); + ITypeBinding superType = (fType.getSuperclass() == null) ? fAst.resolveWellKnownType("java.lang.Object") : fType + .getSuperclass(); int N = fType.getInterfaces().length + 1; fSuperTypes = new ArrayList(N); // Following assumes that noone can call getSupertypes() before we have // created CAstType's for every type in the program being analyzed. fSuperTypes.add(getCAstTypeFor(superType)); - for (ITypeBinding t: fType.getInterfaces() ) + for (ITypeBinding t : fType.getInterfaces()) fSuperTypes.add(getCAstTypeFor(t)); } public Collection getQualifiers() { - return JDT2CAstUtils.mapModifiersToQualifiers(fType.getModifiers(),fType.isInterface()); + return JDT2CAstUtils.mapModifiersToQualifiers(fType.getModifiers(), fType.isInterface()); } public boolean isInterface() {