Skip to content

Commit c69eb03

Browse files
author
Mihail Slavchev
committed
merge master branch
2 parents 2550988 + 23e1593 commit c69eb03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1967
-2340
lines changed

binding-generator/Generator/src/com/tns/bindings/Dump.java

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -389,65 +389,110 @@ private Method[] groupMethodsByName(Method[] methods)
389389

390390
return result.values().toArray(new Method[result.size()]);
391391
}
392+
393+
private String getMethodSignature(Method m)
394+
{
395+
String sig = m.toGenericString();
396+
397+
int nameIdx = sig.indexOf("(");
398+
int endSigIdx = sig.indexOf(")") + 1;
399+
400+
return m.getName() + sig.substring(nameIdx, endSigIdx);
401+
}
392402

393403
private Method[] getSupportedMethods(Class<?> clazz, HashSet<String> methodOverrides)
394404
{
395405
ArrayList<Method> result = new ArrayList<Method>();
396-
HashMap<String, Method> finalMethods = new HashMap<String, Method>();
397-
ArrayList<Class<?>> implementedInterfaces = new ArrayList<Class<?>>();
398-
while (clazz != null)
406+
407+
if (clazz.isInterface())
399408
{
400-
Method[] methods = clazz.getDeclaredMethods();
401-
402-
ArrayList<Method> methodz = new ArrayList<Method>();
403-
404-
for (int i = 0; i < methods.length; i++)
409+
Set<String> objectMethods = new HashSet<String>();
410+
for (Method objMethod: java.lang.Object.class.getDeclaredMethods())
405411
{
406-
Method candidateMethod = methods[i];
407-
if (methodOverrides != null && !methodOverrides.contains(candidateMethod.getName()))
412+
if (!Modifier.isStatic(objMethod.getModifiers()))
408413
{
409-
continue;
414+
String sig = getMethodSignature(objMethod);
415+
objectMethods.add(sig);
410416
}
411-
412-
methodz.add(methods[i]);
413417
}
414-
415-
416-
Class<?>[] interfaces = clazz.getInterfaces();
417-
for (int i = 0; i < interfaces.length; i++)
418+
Set<Method> notImplementedObjectMethods = new HashSet<Method>();
419+
Method[] ifaceMethods = clazz.getDeclaredMethods();
420+
for (Method ifaceMethod: ifaceMethods)
418421
{
419-
implementedInterfaces.add(interfaces[i]);
422+
if (!Modifier.isStatic(ifaceMethod.getModifiers()))
423+
{
424+
String sig = getMethodSignature(ifaceMethod);
425+
if (objectMethods.contains(sig) && !methodOverrides.contains(ifaceMethod.getName()))
426+
{
427+
notImplementedObjectMethods.add(ifaceMethod);
428+
}
429+
}
420430
}
421-
422-
for (int i = 0; i < methodz.size(); i++)
431+
for (Method ifaceMethod: ifaceMethods)
423432
{
424-
Method method = methodz.get(i);
425-
426-
if (isMethodSupported(method, finalMethods))
433+
if (!notImplementedObjectMethods.contains(ifaceMethod))
427434
{
428-
result.add(method);
435+
result.add(ifaceMethod);
429436
}
430437
}
431-
432-
clazz = clazz.getSuperclass();
433438
}
434-
435-
for (int i = 0; i < implementedInterfaces.size(); i++)
439+
else
436440
{
437-
Class<?> implementedInterface = implementedInterfaces.get(i);
438-
Method[] interfaceMethods = implementedInterface.getMethods();
439-
for (int j = 0; j < interfaceMethods.length; j++)
441+
HashMap<String, Method> finalMethods = new HashMap<String, Method>();
442+
ArrayList<Class<?>> implementedInterfaces = new ArrayList<Class<?>>();
443+
while (clazz != null)
440444
{
441-
Method method = interfaceMethods[j];
445+
Method[] methods = clazz.getDeclaredMethods();
446+
447+
ArrayList<Method> methodz = new ArrayList<Method>();
448+
449+
for (int i = 0; i < methods.length; i++)
450+
{
451+
Method candidateMethod = methods[i];
452+
if (methodOverrides != null && !methodOverrides.contains(candidateMethod.getName()))
453+
{
454+
continue;
455+
}
456+
457+
methodz.add(methods[i]);
458+
}
459+
460+
Class<?>[] interfaces = clazz.getInterfaces();
461+
for (int i = 0; i < interfaces.length; i++)
462+
{
463+
implementedInterfaces.add(interfaces[i]);
464+
}
442465

443-
if (methodOverrides != null && !methodOverrides.contains(method.getName()))
466+
for (int i = 0; i < methodz.size(); i++)
444467
{
445-
continue;
468+
Method method = methodz.get(i);
469+
470+
if (isMethodSupported(method, finalMethods))
471+
{
472+
result.add(method);
473+
}
446474
}
447475

448-
if (!isMethodMarkedAsFinalInClassHierarchy(method, finalMethods))
476+
clazz = clazz.getSuperclass();
477+
}
478+
479+
for (int i = 0; i < implementedInterfaces.size(); i++)
480+
{
481+
Class<?> implementedInterface = implementedInterfaces.get(i);
482+
Method[] interfaceMethods = implementedInterface.getMethods();
483+
for (int j = 0; j < interfaceMethods.length; j++)
449484
{
450-
result.add(method);
485+
Method method = interfaceMethods[j];
486+
487+
if (methodOverrides != null && !methodOverrides.contains(method.getName()))
488+
{
489+
continue;
490+
}
491+
492+
if (!isMethodMarkedAsFinalInClassHierarchy(method, finalMethods))
493+
{
494+
result.add(method);
495+
}
451496
}
452497
}
453498
}
@@ -1158,4 +1203,4 @@ private int getDexModifiers(int modifiers)
11581203

11591204
return org.ow2.asmdex.Opcodes.ACC_PROTECTED;
11601205
}
1161-
}
1206+
}

build/project-template-gradle/build-tools/android-static-binding-generator/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

build/project-template-gradle/build-tools/android-static-binding-generator/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/project-template-gradle/build-tools/android-static-binding-generator/ast-parser/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

build/project-template-gradle/build-tools/android-static-binding-generator/ast-parser/example_command.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var fs = require("fs"),
2+
path = require("path");
3+
module.exports = function Helpers(config) {
4+
5+
function cleanOutFile(filePath) {
6+
fs.truncateSync(filePath, 0);
7+
if(config && config.logger) {
8+
config.logger.info("+cleared out file: " + filePath);
9+
}
10+
}
11+
12+
function createFile(filePath) {
13+
if(ensureDirectories(filePath)) {
14+
fs.writeFileSync(filePath, "");
15+
if(config && config.logger) {
16+
config.logger.info("+created ast output file: ");
17+
}
18+
}
19+
cleanOutFile(filePath)
20+
}
21+
22+
function ensureDirectories(filePath) {
23+
var parentDir = path.dirname(filePath);
24+
if(fs.existsSync(parentDir)) {
25+
return true;
26+
}
27+
28+
ensureDirectories(parentDir);
29+
fs.mkdirSync(parentDir);
30+
return true;
31+
}
32+
33+
return {
34+
cleanOutFile: cleanOutFile,
35+
createFile: createFile,
36+
ensureDirectories: ensureDirectories
37+
}
38+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var stringifyOnce = function(obj, replacer, indent){
2+
var printedObjects = [];
3+
var printedObjectKeys = [];
4+
var passingIndent = 4;
5+
if(indent) {
6+
passingIndent = indent;
7+
}
8+
9+
function printOnceReplacer(key, value){
10+
if ( printedObjects.length > 2000){ // browsers will not print more than 20K, I don't see the point to allow 2K.. algorithm will not be fast anyway if we have too many objects
11+
return 'object too long';
12+
}
13+
var printedObjIndex = false;
14+
printedObjects.forEach(function(obj, index){
15+
if(obj===value){
16+
printedObjIndex = index;
17+
}
18+
});
19+
20+
if ( key == ''){ //root element
21+
printedObjects.push(obj);
22+
printedObjectKeys.push("root");
23+
return value;
24+
}
25+
26+
else if(printedObjIndex+"" != "false" && typeof(value)=="object"){
27+
if ( printedObjectKeys[printedObjIndex] == "root"){
28+
return "(pointer to root)";
29+
}else{
30+
return "(see " + ((!!value && !!value.constructor) ? value.constructor.name.toLowerCase() : typeof(value)) + " with key " + printedObjectKeys[printedObjIndex] + ")";
31+
}
32+
}else{
33+
34+
var qualifiedKey = key || "(empty key)";
35+
printedObjects.push(value);
36+
printedObjectKeys.push(qualifiedKey);
37+
if(replacer){
38+
return replacer(key, value);
39+
}else{
40+
return value;
41+
}
42+
}
43+
}
44+
return JSON.stringify(obj, printOnceReplacer, passingIndent);
45+
};
46+
47+
module.exports = stringifyOnce;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var fs = require('fs'),
2+
path = require('path'),
3+
os = require('os'),
4+
fileHelpers = require("./file_helpers")();
5+
6+
module.exports = function(setting){
7+
8+
var logDirectory = path.dirname(setting.logPath);
9+
if (!fs.existsSync(logDirectory)){
10+
console.error("couldn't find logDirectory so it will be created in place:" + setting.logPath);
11+
fileHelpers.ensureDirectories(setting.logPath);
12+
}
13+
if (os.type().indexOf('Windows') === -1) {
14+
var appLogStat = fs.statSync(logDirectory);
15+
if (canWrite(process.uid === appLogStat.uid, process.gid === appLogStat.gid, appLogStat.mode)){
16+
console.error("ERROR WRITING TO LOG FILE DIRECTORY : " + logDirectory);
17+
process.exit(-1);
18+
}
19+
}
20+
21+
var appLog = createLog(setting.APP_NAME, logDirectory, setting);
22+
23+
if(setting.disable) {
24+
for(var prop in appLog) {
25+
appLog[prop] = function() {};
26+
}
27+
}
28+
return appLog;
29+
};
30+
31+
function canWrite(owner, inGroup, mode){
32+
return owner && (mode & 00200) || // User is owner and owner can write.
33+
inGroup && (mode & 00020) || // User is in group and group can write.
34+
(mode & 00002); // Anyone can write.
35+
}
36+
37+
function createLog(appName, logDirectory, setting){
38+
39+
var appLog = {};
40+
41+
function getRequestId() {
42+
return (process.domain && process.domain.id) || "";
43+
}
44+
45+
function getLogDate(){
46+
var today = new Date();
47+
48+
var fullYear = today.getFullYear();
49+
var month = today.getMonth();
50+
var day = today.getDate();
51+
var hours = today.getHours();
52+
var minutes = today.getMinutes();
53+
var seconds = today.getSeconds();
54+
55+
var logDate = fullYear + "-" + month + "-" + day + "/" + hours + ":" + minutes + ":" + seconds;
56+
return logDate;
57+
}
58+
59+
function setMessageWithFormat(message) {
60+
var res = getLogDate() + "\t" + message;
61+
return res;
62+
}
63+
64+
function appendToLogFile(line) {
65+
var logFile = logDirectory + path.sep + appName + ".log";
66+
var augmentedLine = getLogDate() + "\t" + line + os.EOL
67+
fs.appendFile(logFile, augmentedLine, function (err) {
68+
if(err) {
69+
throw "couldn't write to " + logFile;
70+
}
71+
});
72+
}
73+
74+
appLog.log = function (input) {
75+
console.log(setMessageWithFormat(input));
76+
appendToLogFile(input);
77+
}
78+
79+
appLog.info = appLog.log;
80+
81+
appLog.warn = function (input) {
82+
console.warn(setMessageWithFormat(input));
83+
appendToLogFile(input);
84+
}
85+
86+
appLog.error = function (input) {
87+
console.error(setMessageWithFormat(input));
88+
appendToLogFile(input);
89+
}
90+
91+
return appLog;
92+
}
93+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)