Summary: Testing procedure for java source parser - we can run directly the parser without compiling and analysing the source file - we add a test file Reviewed By: ngorogiannis Differential Revision: D23705199 fbshipit-source-id: 2103c1681master
parent
8f13e6ecb3
commit
2c6fd7a617
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package java.source.parser;
|
||||
|
||||
@interface ExampleCustomAnnotation {
|
||||
String name();
|
||||
|
||||
String address();
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package java.source.parser;
|
||||
|
||||
public class Main {
|
||||
|
||||
// Tests for annotations
|
||||
static interface Interface {
|
||||
public Object foo();
|
||||
}
|
||||
|
||||
@ExampleCustomAnnotation(name = "Chaitanya", address = "Agra, India")
|
||||
class AnnotatedClass {
|
||||
@Deprecated
|
||||
void method1() {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void method2() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static class Impl implements Interface {
|
||||
@Override
|
||||
public Object foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// tests for anonymous inner classes
|
||||
static class MyThread {
|
||||
MyThread(Object o) {}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Thread t1 =
|
||||
new Thread() {
|
||||
public void run() {
|
||||
System.out.println("Child Thread");
|
||||
}
|
||||
};
|
||||
t1.start();
|
||||
|
||||
Thread t2 =
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
System.out.println("Child Thread");
|
||||
}
|
||||
});
|
||||
t2.start();
|
||||
|
||||
// nested anonymous classes
|
||||
MyThread mt =
|
||||
new MyThread(
|
||||
new Object() {
|
||||
private int counter;
|
||||
|
||||
int get_counter() {
|
||||
return this.counter;
|
||||
}
|
||||
}) {
|
||||
private String label;
|
||||
|
||||
String get_label() {
|
||||
return this.label;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// tests for enum
|
||||
|
||||
public enum Block {
|
||||
NONE(""),
|
||||
|
||||
WALL("Wall") {
|
||||
@Override
|
||||
public boolean good() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
PIT("Pit") {
|
||||
@Override
|
||||
public boolean good() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
FOG("Fog") {
|
||||
@Override
|
||||
public boolean good() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private class C {};
|
||||
|
||||
private String name;
|
||||
|
||||
private Block(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean good() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
TESTS_DIR = ../..
|
||||
|
||||
INFER_OPTIONS = --java-debug-source-file-info
|
||||
SOURCES = Main.java
|
||||
|
||||
test: parser.output.test
|
||||
$(call check_no_diff,parser.output,parser.output.test)
|
||||
|
||||
replace: parser.output.test
|
||||
cp $< parser.output
|
||||
|
||||
clean:
|
||||
rm -fr infer-out parser.output.test *.class
|
||||
|
||||
# we check if the java source file is valid for javac
|
||||
compile:
|
||||
javac *.java
|
||||
|
||||
.PHONY: parser.output.test
|
||||
parser.output.test: $(SOURCES) $(INFER_BIN)
|
||||
$(INFER_BIN) $(INFER_OPTIONS) $(SOURCES) > parser.output.test
|
||||
|
||||
include $(TESTS_DIR)/base.make
|
@ -0,0 +1,11 @@
|
||||
class java.source.parser.Main at line 9, column 13
|
||||
class java.source.parser.Main$Interface at line 12, column 19
|
||||
class java.source.parser.Main$AnnotatedClass at line 17, column 8
|
||||
class java.source.parser.Main$Impl at line 29, column 15
|
||||
class java.source.parser.Main$MyThread at line 37, column 15
|
||||
class java.source.parser.Main$MyThread$1 at line 43, column 23
|
||||
class java.source.parser.Main$MyThread$2 at line 52, column 29
|
||||
class java.source.parser.Main$MyThread$3 at line 62, column 27
|
||||
class java.source.parser.Main$MyThread$4 at line 68, column 17
|
||||
class java.source.parser.Main$Block at line 80, column 14
|
||||
class java.source.parser.Main$Block$C at line 104, column 18
|
Loading…
Reference in new issue