[infer][java] add an option to only translate the signature of the methods and skip the body

Summary: This adds an option to only translate the body of a method when the file matches the give pattern. This is especially intended to be use for generated files.

Reviewed By: jvillard

Differential Revision: D5729120

fbshipit-source-id: 1e28469
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent 1a221e798c
commit 32d462b778

@ -6,5 +6,12 @@
"language": "Java",
"source_contains": "_SHOULD_BE_SKIPPED_"
}
],
"skip-implementation": [
{
"language": "Java",
"source_contains": "_SHOULD_SKIP_IMPLEMENTATION_"
}
]
}

@ -296,6 +296,9 @@ let never_return_null_matcher =
let skip_translation_matcher =
FileOrProcMatcher.load_matcher (patterns_of_json_with_key Config.patterns_skip_translation)
let skip_implementation_matcher =
FileOrProcMatcher.load_matcher (patterns_of_json_with_key Config.patterns_skip_implementation)
let load_filters analyzer =
{ whitelist= Config.analysis_path_regex_whitelist analyzer
; blacklist= Config.analysis_path_regex_blacklist analyzer

@ -30,6 +30,8 @@ val never_return_null_matcher : SourceFile.t -> Typ.Procname.t -> bool
val skip_translation_matcher : SourceFile.t -> Typ.Procname.t -> bool
val skip_implementation_matcher : SourceFile.t -> Typ.Procname.t -> bool
val modeled_expensive_matcher : (string -> bool) -> Typ.Procname.t -> bool
val test : unit -> unit

@ -1338,6 +1338,13 @@ and patterns_never_returning_null =
, CLOpt.mk_json ~deprecated:["never_returning_null"] ~long
"Matcher or list of matchers for functions that never return $(i,null)." )
and patterns_skip_implementation =
let long = "skip-implementation" in
( long
, CLOpt.mk_json ~long
"Matcher or list of matchers for names of files where we only want to translate the method declaration, skipping the body of the methods (Java only)."
)
and patterns_skip_translation =
let long = "skip-translation" in
( long
@ -2131,16 +2138,20 @@ and only_show = !only_show
and passthroughs = !passthroughs
and patterns_modeled_expensive =
match patterns_modeled_expensive
with k, r -> (k, !r)
and patterns_never_returning_null =
match patterns_never_returning_null
with k, r -> (k, !r)
and patterns_skip_translation =
match patterns_skip_translation
and patterns_skip_implementation =
match patterns_skip_implementation
with k, r -> (k, !r)
and patterns_modeled_expensive =
match patterns_modeled_expensive
and patterns_skip_translation =
match patterns_skip_translation
with k, r -> (k, !r)
and per_procedure_parallelism = !per_procedure_parallelism

@ -185,6 +185,8 @@ val patterns_modeled_expensive : string * Yojson.Basic.json
val patterns_never_returning_null : string * Yojson.Basic.json
val patterns_skip_implementation : string * Yojson.Basic.json
val patterns_skip_translation : string * Yojson.Basic.json
val per_procedure_parallelism : bool

@ -157,6 +157,9 @@ let create_icfg source_file linereader program icfg cn node =
-> ignore (JTrans.create_am_procdesc source_file program icfg am proc_name)
| Javalib.ConcreteMethod cm when JTrans.is_java_native cm
-> ignore (JTrans.create_native_procdesc source_file program icfg cm proc_name)
| Javalib.ConcreteMethod cm
when Inferconfig.skip_implementation_matcher source_file proc_name
-> ignore (JTrans.create_native_procdesc source_file program icfg cm proc_name)
| Javalib.ConcreteMethod cm
-> add_cmethod source_file program linereader icfg cm proc_name ) ;
Cg.add_defined_node icfg.JContext.cg proc_name

@ -1,4 +1,5 @@
infer/tests/build_systems/genrule/module1/Class1.java, void Class1.localNPE1(), 2, NULL_DEREFERENCE, [start of procedure localNPE1()]
infer/tests/build_systems/genrule/module2/Class2.java, void Class2.followMethodDeclarationOnlyBad(SkipImplementationClass1), 2, NULL_DEREFERENCE, [start of procedure followMethodDeclarationOnlyBad(...),Skipping annotatedNullable(): function or method not found]
infer/tests/build_systems/genrule/module2/Class2.java, void Class2.interTargetAbstractNPE(Class1), 2, NULL_DEREFERENCE, [start of procedure interTargetAbstractNPE(...),Skipping abstractMayReturnNull(): function or method not found]
infer/tests/build_systems/genrule/module2/Class2.java, void Class2.interTargetNPE(), 2, NULL_DEREFERENCE, [start of procedure interTargetNPE(),start of procedure returnsNull(),return from a call to String Class1.returnsNull()]
infer/tests/build_systems/genrule/module2/Class2.java, void Class2.interTargetNativeNPE(Class1), 2, NULL_DEREFERENCE, [start of procedure interTargetNativeNPE(...),Skipping nativeMayReturnNull(): function or method not found]

@ -1,6 +1,6 @@
java_library(
name='module1',
srcs=['Class1.java'],
srcs=glob(["*.java"]),
deps=[
'//infer/tests/build_systems/genrule/annotations:annotations',
],

@ -0,0 +1,26 @@
/*
* Copyright (c) 2017 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// _SHOULD_SKIP_IMPLEMENTATION_
package genrule.module1;
import genrule.annotations.Nullable;
public class SkipImplementationClass1 {
public @Nullable Object annotatedNullable() {
return new Object();
}
public Object notAnnotatedNullable() {
return null;
}
}

@ -1,6 +1,6 @@
java_library(
name='module2',
srcs=['Class2.java'],
srcs=glob(["*.java"]),
deps=[
'//infer/tests/build_systems/genrule/module1:module1'
]

@ -10,6 +10,7 @@
package genrule.module2;
import genrule.module1.Class1;
import genrule.module1.SkipImplementationClass1;
public class Class2 {
@ -33,4 +34,14 @@ public class Class2 {
obj.toString();
}
void followMethodDeclarationOnlyBad(SkipImplementationClass1 obj1) {
Object obj2 = obj1.annotatedNullable();
obj2.toString();
}
void followMethodDeclarationOnlyOk(SkipImplementationClass1 obj1) {
Object obj2 = obj1.notAnnotatedNullable();
obj2.toString();
}
}

Loading…
Cancel
Save