id
stringlengths
36
36
text
stringlengths
1
1.25M
07b23e6e-f9fb-4c27-81d0-c9cc44e71122
@Override public void handle(KeyEvent event) { final KeyCode keyCode = event.getCode(); switch(keyCode) { case UP: } }
a6e210ed-412f-4335-9bf1-52b23b24cef8
public BlackListedClass(Class<?> clazz, String rule){ this.clazz = clazz; this.rule = rule; }
04184367-22bb-4547-90e3-491c2825ca5f
public Class<?> getClazz() { return clazz; }
c51b9a8e-39b4-47a3-a71a-d263a5997b8e
public String getRule() { return rule; }
d9a0c571-cf59-401a-b0d7-8de9ef675158
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); tree = Trees.instance(processingEnv); }
bda7c85f-7981-4214-8cf3-d8bf41d077a6
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { BlackListCodeAnalyzerVisitor visitor = new BlackListCodeAnalyzerVisitor( processingEnv); // returns the Java classes, interfaces and packages in the compilation unit as a Set containing Element objects. Set<? extends Element> elements = roundEnv.getRootElements(); for (Element element : elements) { //Gets the TreePath node for a given Element. The TreePath consist of a tree of nodes(Class nodes, method nodes, variable nodes etc) TreePath treePath = tree.getPath(element); if (treePath != null) { visitor.scan(treePath, tree); } } return false; }
f5c6861d-4e1c-401a-829f-ac4fbb18e8d4
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); tree = Trees.instance(processingEnv); }
a99a7248-bc0d-40e5-a6e2-e44591401dd8
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { JdbcCodeAnalyzerVisitor visitor = new JdbcCodeAnalyzerVisitor( processingEnv); // returns the Java classes, interfaces and packages in the compilation unit as a Set containing Element objects. Set<? extends Element> elements = roundEnv.getRootElements(); for (Element element : elements) { //Gets the TreePath node for a given Element. The TreePath consist of a tree of nodes(Class nodes, method nodes, variable nodes etc). TreePath treePath = tree.getPath(element); visitor.scan(treePath, tree); } return false; }
a09afe0d-67f1-4cea-8987-7b690196dfe5
public JdbcCodeAnalyzerVisitor(ProcessingEnvironment processingEnv) { this.processingEnv = processingEnv; }
40535e8e-5a51-4c0d-9b49-f1ed8496b9de
@Override public Object visitMethod(MethodTree methodTree, Object arg1) { Trees trees = (Trees) arg1; CompilationUnitTree compilationUnitTree = getCurrentPath().getCompilationUnit(); // compileTree.getSourceFile().getName(); // filename including path List<? extends StatementTree> statements = methodTree.getBody() .getStatements(); processStatements(statements,trees,compilationUnitTree,methodTree); return super.visitMethod(methodTree, arg1); }
60011e98-dbfb-4748-bf99-e0ad4fe5bfdd
private void processStatements(List<? extends StatementTree> statements, Trees trees,CompilationUnitTree compileTree, MethodTree methodTree ) { for (StatementTree statement : statements) { if (statement.getKind().equals(Kind.EXPRESSION_STATEMENT)) { handleMessageForExpressionStatment(trees,statement,compileTree,methodTree); } else if (statement.getKind().equals(Kind.VARIABLE)) { handleMessageForVariable(trees,statement,compileTree,methodTree); } else if(statement.getKind().equals(Kind.TRY) ){ handleMessageForTryStatement(trees,statement,compileTree,methodTree); } else if ( statement.getKind().equals(Kind.IF)){ handleMessageForIFStatement(trees,statement,compileTree,methodTree); } else if(statement.getKind().equals(Kind.RETURN)){ handleMessageForReturnStatement(trees,statement,compileTree,methodTree); } else if(statement.getKind().equals(Kind.ENHANCED_FOR_LOOP)){ handleMessageForEnhancedForLoop(trees,statement,compileTree,methodTree); } } }
ebd7e8a5-ff04-4143-9ea9-e51ee5abdee8
private void handleMessageForEnhancedForLoop(Trees trees, StatementTree statement, CompilationUnitTree compileTree, MethodTree methodTree) { EnhancedForLoopTree enhanceForLoop = ( EnhancedForLoopTree)statement; enhanceForLoop.getExpression(); List<? extends StatementTree> statements = ((BlockTree)enhanceForLoop.getStatement()).getStatements(); processStatements(statements, trees, compileTree, methodTree); }
719f6258-646a-43c7-882c-642188d0a1c1
private void handleMessageForReturnStatement(Trees trees, StatementTree statement, CompilationUnitTree compileTree, MethodTree methodTree) { ReturnTree rt = ( ReturnTree)statement; if( rt.getExpression().getKind().equals(Kind.METHOD_INVOCATION) ) { MethodInvocationTree methodInvocationTree = (MethodInvocationTree)rt.getExpression(); List<? extends ExpressionTree> args = methodInvocationTree.getArguments(); for(ExpressionTree ex: args){ if(ex.getKind().equals(Kind.STRING_LITERAL)){ handleMessageForExpressionStatment(trees,statement, compileTree, methodTree); } } } }
bcfd3fde-ab8a-4377-bf1b-eeb0721c9315
private void handleMessageForIFStatement(Trees trees, StatementTree statement, CompilationUnitTree compileTree, MethodTree methodTree) { IfTree iftree = (IfTree)statement; BlockTree ifThenBlock= (BlockTree)iftree.getThenStatement(); ifThenBlock.getStatements(); processStatements(ifThenBlock.getStatements(), trees, compileTree, methodTree); BlockTree ifElseBlock = (BlockTree)iftree.getElseStatement(); processStatements(ifElseBlock.getStatements(), trees, compileTree, methodTree); }
09111029-e66c-4bd3-b9e1-939e3665b1d8
private void handleMessageForTryStatement(Trees trees, StatementTree statement, CompilationUnitTree compileTree, MethodTree methodTree) { TryTree tree = (TryTree)statement; List<? extends StatementTree> blockStatements = tree.getBlock().getStatements(); for(StatementTree stmt : blockStatements){ if (stmt.getKind().equals(Kind.EXPRESSION_STATEMENT)) { handleMessageForExpressionStatment(trees,stmt,compileTree,methodTree); } else if (stmt.getKind().equals(Kind.VARIABLE)) { handleMessageForVariable(trees,stmt,compileTree,methodTree); } } }
87e73b35-b055-45c9-9344-3bb8af386e03
private void handleMessageForVariable(Trees trees, StatementTree statement, CompilationUnitTree compileTree, MethodTree methodTree) { VariableTree queryVariable = (VariableTree) statement; SourcePositions sourcePosition = trees.getSourcePositions(); long startPosition = sourcePosition.getStartPosition( getCurrentPath().getCompilationUnit(), statement); if (statement.toString() != null && !statement.toString().isEmpty()) { if (statement.toString().toLowerCase().contains("select ")) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store retrieve entity operations on line " + compileTree.getLineMap() .getLineNumber( startPosition) + " for the jdbc query string variable " + queryVariable.getName() + " in the method " + methodTree.getName() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [ " + compileTree.getSourceFile() .getName() + " ] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.READ) + " in the Rule Table"); } else if (statement.toString().toLowerCase() .contains("update ")) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store update entity operations on line " + compileTree.getLineMap() .getLineNumber( startPosition) + " for the jdbc query string variable " + queryVariable.getName() + " in the method " + methodTree.getName() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [ " + compileTree.getSourceFile() .getName() + " ] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.UPDATE) + " in the Rule Table"); } else if (statement.toString().toLowerCase() .contains("insert ")) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store create entity operations on line " + compileTree.getLineMap() .getLineNumber( startPosition) + " for the jdbc query string variable " + queryVariable.getName() + " in the method " + methodTree.getName() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [ " + compileTree.getSourceFile() .getName() + " ] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.CREATE) + " in the Rule Table"); } else if (statement.toString().toLowerCase() .contains("delete ")) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store delete entity operations on line " + compileTree.getLineMap() .getLineNumber( startPosition) + " for the jdbc query string variable " + queryVariable.getName() + " in the method " + methodTree.getName() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [ " + compileTree.getSourceFile() .getName() + " ] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.DELETE) + " in the Rule Table"); } } }
3bdc3c1e-405c-405f-9cb4-00b41ed8c366
private void handleMessageForExpressionStatment(Trees trees,StatementTree stmt, CompilationUnitTree compilationUnitTree, MethodTree methodTree) { SourcePositions sourcePosition = trees.getSourcePositions(); long startPosition = sourcePosition.getStartPosition( getCurrentPath().getCompilationUnit(), stmt); if (stmt.toString() != null && !stmt.toString().isEmpty()) { if (stmt.toString().toLowerCase().contains("select ")) { processingEnv.getMessager().printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store retrieve entity operations on line " + compilationUnitTree.getLineMap() .getLineNumber(startPosition) + " in the method " + methodTree.getName().toString() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [" + compilationUnitTree.getSourceFile().getName() + "] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.READ) + " in the Rule Table"); } else if (stmt.toString().toLowerCase() .contains("update ")) { processingEnv.getMessager().printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store update entity operations on line " + compilationUnitTree.getLineMap() .getLineNumber(startPosition) + " in the method " + methodTree.getName().toString() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [" + compilationUnitTree.getSourceFile().getName() + "] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.UPDATE) + " in the Rule Table"); } else if (stmt.toString().toLowerCase() .contains("insert ")) { processingEnv.getMessager().printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store create entity operations on line " + compilationUnitTree.getLineMap() .getLineNumber(startPosition) + " in the method " + methodTree.getName().toString() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [" + compilationUnitTree.getSourceFile().getName() + "] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.CREATE) + " in the Rule Table"); } else if (stmt.toString().toLowerCase() .contains("delete ")) { processingEnv.getMessager().printMessage( javax.tools.Diagnostic.Kind.ERROR, "Use Data Store delete entity operations on line " + compilationUnitTree.getLineMap() .getLineNumber(startPosition) + " in the method " + methodTree.getName().toString() + " in the class " + TreeUtils.className(trees .getElement(getCurrentPath())) + " [" + compilationUnitTree.getSourceFile().getName() + "] "+" Refer Rules "+ SQLRuleRepository.getRule(Operation.DELETE) + " in the Rule Table"); } } }
1bf22565-5404-4fee-bf30-9927f36f3eb6
private TreeUtils() { }
5ce47686-9b6d-489f-a815-d5c3b6a9d7c8
public static String methodName(Element element) { Element e = element.getEnclosingElement(); while(true ){ if(e.getKind().equals(ElementKind.METHOD)){ return e.toString(); } else { e = e.getEnclosingElement(); } } }
244f1b19-dfcf-47e0-8622-8dffa0f6e9eb
public static String className(Element element) { Element e = element.getEnclosingElement(); while(true ){ if(e.getKind().equals(ElementKind.CLASS)){ return e.toString(); } else { e = e.getEnclosingElement(); } } }
504bf8bf-c7b0-4278-b023-11f739d95252
private AppEngineAnalyzerUtils(){}
c9507f2e-ca79-4741-9100-702787172c90
public static URLClassLoader getUrlClassLoader(String directoryPath) { // directoryPath File f = new File(directoryPath); URL url; URL[] urls = null; URLClassLoader urlClassLoader = null; try { url = f.toURI().toURL(); urls = new URL[] { url }; urlClassLoader = new URLClassLoader(urls); } catch (MalformedURLException e) { e.printStackTrace(); } return urlClassLoader; }
b6f5be4a-5150-48fe-9fe0-dbdcbd1746d2
public static boolean isClass(Element e) { return e.getKind().isClass() || e.getKind().isInterface(); }
eca784cd-8d1a-495a-8a8f-7278fb883d48
public BlackListCodeAnalyzerVisitor(ProcessingEnvironment processingEnv) { this.processingEnv = processingEnv; this.urlClassLoader = AppEngineAnalyzerUtils.getUrlClassLoader(ConfigurationPropertiesFileReader.getProperty("project.rootfolder.location")); }
095e9b17-ede6-4c93-9beb-d8fae5707356
@Override public Object visitClass(ClassTree node, Object arg1) { Trees trees = (Trees) arg1; Element element = trees.getElement(getCurrentPath()); if (AppEngineAnalyzerUtils.isClass(element)) { TypeElement clazz = (TypeElement) element; // check for JRE super class which is blacklisted checkIfSuperClassBlackListed(clazz, urlClassLoader); // check if it implements restricted interfaces checkIfInterfaceBlackListed(clazz, urlClassLoader); // check if it has restricted field variables } return super.visitClass(node, arg1); }
1751b003-06e2-44ce-be9f-d65d83596f57
@Override public Object visitVariable(VariableTree node, Object p) { try { JavacTrees javacTrees = (JavacTrees) p; Element element = javacTrees.getElement(getCurrentPath()); VarSymbol s = (VarSymbol) element; TreeUtils.className(javacTrees.getElement(getCurrentPath())); SourcePositions sourcePositions = javacTrees.getSourcePositions(); long startPosition = sourcePositions.getStartPosition( getCurrentPath().getCompilationUnit(), node); javacTrees.getTree(element); Class declaredType = urlClassLoader .loadClass(s.asType().toString()); for (Class blackListedClazz : GoogleAppEngineBlackList .getBlackList()) { if (blackListedClazz.isAssignableFrom(declaredType)) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "The Class " + TreeUtils.className(javacTrees .getElement(getCurrentPath())) + " has a declared type which is an app engine restricted JRE Interface/class " + declaredType + " at line number " + getCurrentPath() .getCompilationUnit() .getLineMap() .getLineNumber( startPosition) + "\n Rule: " + GoogleAppEngineBlackList .getRule(declaredType)); } } // } } catch (Exception e) { } return super.visitVariable(node, p); }
107843f0-25f9-4c4f-9cff-eb42e46435f6
private void checkIfInterfaceBlackListed(TypeElement clazz, URLClassLoader urlClassLoader) { List<? extends TypeMirror> interfaces = clazz.getInterfaces(); for (TypeMirror typeMirror : interfaces) { try { Class interfaceClazz = urlClassLoader.loadClass(typeMirror .toString()); for (Class blackListedClazz : GoogleAppEngineBlackList .getBlackList()) { if (blackListedClazz.isAssignableFrom(interfaceClazz)) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "The Class " + clazz + " implements an app engine restricted JRE Interface " + interfaceClazz + "\n Rule: " + GoogleAppEngineBlackList .getRule(interfaceClazz)); } } } catch (ClassNotFoundException e) { } } }
eb7723ed-0d96-4e10-ac67-59042f82d681
private void checkIfSuperClassBlackListed(TypeElement clazz, URLClassLoader urlClassLoader) { try { Class elementSuperClass = urlClassLoader.loadClass(clazz .getSuperclass().toString()); for (Class blackListedClass : GoogleAppEngineBlackList .getBlackList()) { if (blackListedClass.isAssignableFrom(elementSuperClass)) { processingEnv .getMessager() .printMessage( javax.tools.Diagnostic.Kind.ERROR, "The Class " + clazz + " extends an app engine restricted JRE Class " + blackListedClass + "\n Rule: " + GoogleAppEngineBlackList .getRule(elementSuperClass)); return; } } } catch (ClassNotFoundException e) {} }
b507f0ef-d0d3-4044-ac0b-ba25f39c5264
public SQLRule(Operation operation, int ruleNumber, String databaseSQL, String googleAppEngine) { super(); this.operation = operation; this.ruleNumber = ruleNumber; this.databaseSQL = databaseSQL; this.googleAppEngine = googleAppEngine; }
705dad1a-1e31-48e1-a570-1faab3d1e74d
public Operation getOperation() { return operation; }
064be11b-c54b-4ccc-9545-5723b87beb8d
public int getRuleNumber() { return ruleNumber; }
455e58ba-5754-42b0-93c6-a8602b7a2566
public String getDatabaseSQL() { return databaseSQL; }
cec5f35c-e3e4-46e4-a85a-8626fabfbf7b
public String getGoogleAppEngine() { return googleAppEngine; }
167b097d-b91a-489e-87fe-d610f78f8fc4
@Override public String toString() { StringBuffer sbf = new StringBuffer(); sbf.append("\n-------------------------------------------------------"); sbf.append("\nSQL CRUD Operation Type: "+ operation); sbf.append("\nRule No: "+ ruleNumber); sbf.append("\nSQL Query: "+ databaseSQL); sbf.append("\nDataStore API"+ googleAppEngine); sbf.append("\n-------------------------------------------------------"); return sbf.toString(); }
6dc8e97b-7dfe-4807-a1b7-5bf14c3d6cf7
private FileSearchMain() { }
ae345a1a-e94f-4ca5-afe8-86c55cd6bbae
public static List<File> getProjectFiles(String projectRootFolder) { if (projectRootFolder == null) { throw new NullPointerException( "Please Input a Valid Project Folder for searching App Engine Black listed Classes"); } List<File> fileList = new ArrayList<File>(); listfiles(projectRootFolder, fileList); return fileList; }
5245de03-0d0f-436a-9d74-11a92ff99d27
public static void listfiles(String directoryName, List<File> files) { File directory = new File(directoryName); // get all the files from a directory File[] fList = directory.listFiles(); for (File file : fList) { if (file.isFile() && file.getName().endsWith(".java")) { files.add(file); } else if (file.isDirectory()) { listfiles(file.getAbsolutePath(), files); } } }
d093390e-c9b4-4ae7-b2bd-6e2ed6f042e2
private ConfigurationPropertiesFileReader() {}
e9bf48f9-c541-4dad-9b03-4bc904c64543
public static String getProperty(String key){ return defaultProps.getProperty(key); }
1b388ce1-f602-4727-a0d5-3868f736ddef
public static void main(String[] args) throws IOException { // Gets the Java programming language compiler JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // Get a new instance of the standard file manager implementation StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); // Get the valid source files as a list List<File> files = new ArrayList<File>(); List<String> optionList = new ArrayList<String>(); optionList.addAll(Arrays.asList(System.getProperty("java.class.path"))); files.addAll(FileSearchMain.getProjectFiles(ConfigurationPropertiesFileReader.getProperty("project.rootfolder.location"))); if (files.size() > 0) { // Get the list of java file objects Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files); // Create the compilation task CompilationTask task = compiler.getTask(null, fileManager, null,null, null, compilationUnits); // Get the list of annotation processors LinkedList<AbstractProcessor> processors = new LinkedList<AbstractProcessor>(); processors.add(new BlackListCodeAnalyzerProcessor()); task.setProcessors(processors); // Perform the compilation task. task.call(); try { fileManager.close(); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); } } else { System.out.println("No valid source files to process. Extiting from the program"); System.exit(0); } }
1e2e7717-49d7-4ec3-a377-7faf11469079
private GoogleAppEngineBlackList(){}
9a684ffb-4808-4094-ad82-7d672145056e
public static List<Class> getBlackList(){ List<Class> clazzList = new ArrayList<Class>(); for(BlackListedClass blackListedClass: blackList){ clazzList.add(blackListedClass.getClazz()); } return clazzList; }
8130d963-9cae-489f-9315-5aea4f518727
public static String getRule(Class clazz){ for(BlackListedClass blackListedClass: blackList){ if( blackListedClass.getClazz().equals(clazz) || blackListedClass.getClazz().isAssignableFrom(clazz)){ return blackListedClass.getRule(); } } return "rule not found"; }
919daab3-e7b0-448a-a9c6-7bf95fad3981
public static boolean contains(Class clazz){ for(BlackListedClass blackListedClass: blackList){ if( blackListedClass.getClazz().equals(clazz) ){ return true; } } return false; }
3fc18a56-f02d-4a20-b1a4-811f770d55e3
public static void main(String[] args) { // Gets the Java programming language compiler JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // Get a new instance of the standard file manager implementation StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); List<File> files = new ArrayList<File>(); List<String> optionList = new ArrayList<String>(); optionList.addAll(Arrays.asList(System.getProperty("java.class.path"))); files.addAll(FileSearchMain.getProjectFiles(ConfigurationPropertiesFileReader.getProperty("project.jdbc.files.location"))); SQLRuleRepository.showRules(); if (files.size() > 0) { // Get the list of java file objects Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files); // Create the compilation task CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits); // Get the list of annotation processors LinkedList<AbstractProcessor> processors = new LinkedList<AbstractProcessor>(); processors.add(new JdbcDAOCodeAnalyzerProcessor()); task.setProcessors(processors); // Perform the compilation task. task.call(); try { fileManager.close(); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); } } else { System.out.println("No valid source files to process. " + "Extiting from the program"); System.exit(0); } }
038d7083-0541-434d-8e2a-cf903a2c2721
private SQLRuleRepository(){}
1fb604c3-69b8-43dd-add5-13f09c82edf2
public static String getRule(Operation operation) { StringBuffer sbf = new StringBuffer(""); sbf.append(" [ "); for (SQLRule sqlRule : rulesList) { if (sqlRule.getOperation().equals(operation)) { sbf.append(sqlRule.getRuleNumber() + ","); } } sbf.append(" ] "); return sbf.toString(); }
40c1bd19-fe57-44d4-b806-abdae252ece3
public static void showRules() { for(SQLRule sqlRule : rulesList){ System.out.println(sqlRule); } }
e504a081-ae7c-47b3-b76d-f31222bbec0e
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { //FileSearchMain.getProjectFiles("") URLClassLoader urlClassLoader = AppEngineAnalyzerUtils.getUrlClassLoader(ConfigurationPropertiesFileReader.getProperty("project.rootfolder.location")); //URLClassLoader urlClassLoader = AppEngineAnalyzerUtils.getUrlClassLoader("E:/NCIRL/dissertation/workspace/AppEngineBlackListAnalyzer/src/main/java/Counter.java"); for (Element element : roundEnv.getRootElements()) { if (AppEngineAnalyzerUtils.isClass( element)) { TypeElement clazz = (TypeElement) element; // check for JRE super class which is blacklisted checkIfSuperClassBlackListed(clazz, urlClassLoader); // check if it implements restricted interfaces checkIfInterfaceBlackListed(clazz, urlClassLoader); // check if it has restricted field variables checkIfVariablesBlackListed(clazz, urlClassLoader); } } return false; }
1d197a77-7d27-4d00-b2b3-5bf406f6ae26
private void checkIfVariablesBlackListed(TypeElement clazz, URLClassLoader urlClassLoader) { List<? extends Element> enclosingElements = clazz.getEnclosedElements(); try { for(Element element : enclosingElements){ if(element.asType().getKind() == TypeKind.DECLARED){ TypeMirror typeMirror = element.asType(); Class declaredType = urlClassLoader.loadClass(typeMirror.toString()); if (GoogleAppEngineBlackList.blackList.contains(declaredType)) { processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " has a declared type which is an app engine restricted JRE Interface/class " + declaredType); } else { for(Class blackListedClazz: GoogleAppEngineBlackList.getBlackList()){ if(blackListedClazz.isAssignableFrom(declaredType) ){ processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " has a declared type which is an app engine restricted JRE Interface/class " + declaredType); } } } } if( element.asType().getKind() == TypeKind.EXECUTABLE){ ExecutableElement executableElement = (ExecutableElement) element; TypeMirror typeMirrorReturnType = executableElement.getReturnType(); if( typeMirrorReturnType.getKind() == TypeKind.DECLARED ){ Class declaredType = urlClassLoader.loadClass(typeMirrorReturnType.toString()); if (GoogleAppEngineBlackList.blackList.contains(declaredType)) { processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " has a method "+ executableElement +" which returns a google app engine restricted interface/class" + declaredType); } } List<? extends VariableElement> methodParameters = executableElement.getParameters(); for( VariableElement methodParameter :methodParameters ){ if( methodParameter.asType().getKind() == TypeKind.DECLARED ){ Class declaredType = urlClassLoader.loadClass(methodParameter.asType().toString()); if (GoogleAppEngineBlackList.blackList.contains(declaredType)) { processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " has a method "+ executableElement +" which contains a google app engine restricted interface/class as method parameter" + declaredType); } } } } } } catch (ClassNotFoundException e) { } }
17625d0f-a094-4582-baa7-f15fa00c6bed
private void checkIfInterfaceBlackListed(TypeElement clazz , URLClassLoader urlClassLoader) { List<? extends TypeMirror> interfaces = clazz.getInterfaces(); for (TypeMirror typeMirror : interfaces) { try { Class interfaceClazz = urlClassLoader.loadClass(typeMirror.toString()); if (GoogleAppEngineBlackList.blackList.contains(interfaceClazz)) { processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " implements an app engine restricted JRE Interface " + interfaceClazz); } } catch (ClassNotFoundException e) { } } }
0d870552-9953-4b53-b05a-8fb0bb836e0c
private void checkIfSuperClassBlackListed(TypeElement clazz, URLClassLoader urlClassLoader) { try { Class elementSuperClass = urlClassLoader.loadClass(clazz.getSuperclass().toString()); for (Class blackListedClass : GoogleAppEngineBlackList.getBlackList()) { if (blackListedClass.isAssignableFrom(elementSuperClass)) { processingEnv .getMessager() .printMessage( Kind.ERROR, "The Class " + clazz + " extends an app engine restricted JRE Class " + blackListedClass); return; } } } catch (ClassNotFoundException e) { } }
77fc3fba-2866-46ca-906c-508e9e398749
public TimeTrackerController() { gson = new GsonBuilder().setPrettyPrinting().create(); load(); }
44bde3d8-03c2-499d-984d-3bb5c3a1a830
public String getCurrentTask() { return tracker.getCurrentTask(); }
0ec41039-c26b-4a3d-9b7b-bb6f1377897e
public void setCurrentTask(String name) { tracker.setCurrentTask(name); if (tracker.getTaskNames().contains(name) == false) { tracker.addTask(name); } save(); stopWatch.start(); }
13b3b19d-5523-4fb8-88d3-40f68908f3e5
public long getTime() { System.out.println("current task: " + tracker.getCurrentTask() + (StopWatch.NOT_RUNNING == stopWatch.getState() ? " (stopped)" : "")); if (tracker.getCurrentTask() == null) { return 0l; } return tracker.getTaskTime(tracker.getCurrentTask()) + (stopWatch.getState() == StopWatch.RUNNING ? (System.currentTimeMillis() - stopWatch.startTime) : 0l); }
661f75e9-837f-479e-a787-db95d574676a
public int toggle() throws NoTaskDefinedException { if (tracker.getCurrentTask() == null) { throw new NoTaskDefinedException(); } switch (stopWatch.getState()) { case StopWatch.RUNNING: long timing = stopWatch.stop(); tracker.getTasks().put(tracker.getCurrentTask(), getTime() + timing); save(); break; case StopWatch.NOT_RUNNING: stopWatch.start(); break; } return stopWatch.state; }
37500eeb-3649-4c73-98ba-013bc5751e47
public Map<String, Long> getTasks() { return tracker.getTasks(); }
75b72484-cfa2-4faf-8edd-645514598de0
public Collection<String> getTaskNames() { return tracker.getTaskNames(); }
173d1e5e-05c0-4faa-8c9b-dc33dc77f15e
public void save() { PrintWriter writer = null; try { writer = new PrintWriter("tasks.json"); writer.write(gson.toJson(tracker)); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { writer.flush(); writer.close(); } }
3adde3bb-16e1-4c81-9e55-61666e1c201e
public void load() { FileReader reader = null; try { reader = new FileReader("tasks.json"); tracker = gson.fromJson(reader, TimeTracker.class); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if(reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
1a4e5897-132a-4850-af94-28aa06b66138
public void addTask(String name) { if (tracker.getTaskNames().contains(name) == false) { tracker.addTask(name); } setCurrentTask(name); }
fe55d3eb-44da-4868-8f71-83dea0a370e3
@Override public void run() { while (true) { try { Thread.sleep(20000); System.out.println("TimeTrackerApp.DisplayUpdater.run()"); display.asyncExec(new Runnable() { @Override public void run() { TimeTrackerApp.this.update(); } }); } catch (InterruptedException e) { e.printStackTrace(); } } }
4822838c-36df-44c0-98e4-0ddc28cde2ee
@Override public void run() { TimeTrackerApp.this.update(); }
4569836a-5eac-4168-8e4f-359e046f90de
@Override public void mouseUp(MouseEvent e) { doClick(e); }
c90f956b-f3b2-4718-abfe-59e4a05df2cd
protected void doClick(MouseEvent e) { switch (e.button) { case 1: System.out.println("left click"); try { controller.toggle(); } catch (NoTaskDefinedException e1) { showProjectSelector(); } break; case 3: System.out.println("right click"); showProjectSelector(); break; } update(); }
b04968aa-a370-42a8-b150-ebb6468541d8
public static void main(String[] args) { try { TimeTrackerApp window = new TimeTrackerApp(); window.open(); } catch (Exception e) { e.printStackTrace(); } }
824bb314-feb9-40ef-964f-3229d032ea28
public void open() { display = Display.getDefault(); createContents(); new Thread(new DisplayUpdater()).start(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
7fc19d3f-2728-4ae6-ba3c-ccc4bdef34d4
protected void createContents() { shell = new Shell(); shell.setSize(315, 97); shell.setText("Time Tracker"); shell.setLayout(new GridLayout(2, false)); lblClock = new Label(shell, SWT.NONE); lblClock.setFont(SWTResourceManager.getFont("Lucida Grande", 44, SWT.BOLD)); lblClock.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); lblClock.setEnabled(false); lblClock.setAlignment(SWT.CENTER); lblClock.setText("000 : 00"); new Label(shell, SWT.NONE); lblCurrentTask = new Label(shell, SWT.RIGHT); lblCurrentTask.setFont(SWTResourceManager.getFont("Lucida Grande", 10, SWT.NORMAL)); lblCurrentTask.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); menu = new Menu (shell, SWT.POP_UP); shell.pack(); update(); }
94f88ad2-6298-4c2f-99d6-b6a8fe32fb8f
protected void showProjectSelector() { Collection<String> tasks = controller.getTaskNames(); if (tasks.size() == 0) { showNewTaskDialog(); } MenuItem addNew = new MenuItem(menu, SWT.NONE); addNew.setText("New Task..."); addNew.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { showNewTaskDialog(); } }); for (final String name : tasks) { MenuItem item = new MenuItem (menu, SWT.PUSH); item.setText(name); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { controller.setCurrentTask(name); update(); } }); } shell.setMenu(menu); }
6de2b366-b622-4ed1-ae42-045d222eb4cb
public void widgetSelected(SelectionEvent e) { showNewTaskDialog(); }
95aa9945-716a-43e2-bb86-a2c97d51ecdb
public void widgetSelected(SelectionEvent e) { controller.setCurrentTask(name); update(); }
c5074560-affc-4f83-938f-b8698cbb9145
private void showNewTaskDialog() { InputDialog newTaskDialog = new InputDialog(shell, "New Task", "Enter Task Name", null, null); if (newTaskDialog.open() == InputDialog.OK) { controller.setCurrentTask(newTaskDialog.getValue()); } update(); }
3ce0a15c-7b84-4cdd-a1b0-4b089a1567a7
public void update() { long time = controller.getTime(); String displayTime = String.format("%03d : %02d", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time))); System.out.println("updating: " + time + " -> " + displayTime); lblClock.setText(displayTime); if(controller.stopWatch.state == StopWatch.NOT_RUNNING) { lblClock.setForeground(display.getSystemColor(SWT.COLOR_GRAY)); System.out.println("stopped"); } else { lblClock.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); System.out.println("started"); } lblCurrentTask.setText(controller.getCurrentTask() == null ? "" : controller.getCurrentTask()); shell.layout(); }
8b74e59f-63ef-40cd-bd2e-ffccdd1bc1f2
public String getRecordState() { return recordState; }
22690bc3-b4f6-4bc9-a196-a53e013d7817
public void setRecordState(String recordState) { this.recordState = recordState; }
3c19ff35-805d-4c96-9850-ae5582c0dcd2
public void addTask(String name) { tasks.put(name, 0l); }
f8705ca7-9a25-4c32-bc90-8b76e6c84ae1
public void deleteTask(String name) { tasks.remove(name); }
3ec54954-fa31-41ad-ba9a-8aa6e8a32ddb
public long getTaskTime(String name) { return tasks.get(name); }
483864be-3c02-43b5-9fa0-b032c5664660
public Collection<String> getTaskNames() { return tasks.keySet(); }
a9470d96-4a26-4f2b-b1c4-7f22f2d1f2d7
public Map<String, Long> getTasks() { return tasks; }
0fe3594e-0103-4fef-8c05-4250103e752a
public void setTasks(Map<String, Long> tasks) { this.tasks = tasks; }
8a99f048-290a-43fc-8fbe-2af9d2708251
public String getCurrentTask() { return currentTask; }
1c4dbfd4-9966-406a-a62a-f6715740af95
public void setCurrentTask(String currentTask) { this.currentTask = currentTask; }
9d1b1f02-9ee9-4cf2-ab04-cd712bf7344b
public void updateClock(long time);
b4a2bdb9-b5c1-4364-bf7e-2654dfff10d5
public void start() { startTime = System.currentTimeMillis(); state = RUNNING; }
2a80e779-f28f-4925-8510-f5c238ad4fe7
public long stop() { lastTiming = getTime(); state = NOT_RUNNING; return lastTiming; }
8078a340-ca06-478f-8283-0a4da037420d
public long getTime() { return System.currentTimeMillis() - startTime; }
b13cbfa6-2cb2-4b85-9c94-c2fd4301e6bc
public int getState() { return state; }
48c859b2-cecd-449f-ac08-4b19e80be022
public static Color getColor(int systemColorID) { Display display = Display.getCurrent(); return display.getSystemColor(systemColorID); }
74b3ef31-2fcb-49b8-956e-4e6ab6d17408
public static Color getColor(int r, int g, int b) { return getColor(new RGB(r, g, b)); }
3a07c387-7d00-4b7f-8bb6-7e527b815721
public static Color getColor(RGB rgb) { Color color = m_colorMap.get(rgb); if (color == null) { Display display = Display.getCurrent(); color = new Color(display, rgb); m_colorMap.put(rgb, color); } return color; }
3331f469-af36-437c-b171-e2e3e96888e4
public static void disposeColors() { for (Color color : m_colorMap.values()) { color.dispose(); } m_colorMap.clear(); }
5b9f78ad-c0e1-410e-a64d-c1166e2cc06d
protected static Image getImage(InputStream stream) throws IOException { try { Display display = Display.getCurrent(); ImageData data = new ImageData(stream); if (data.transparentPixel > 0) { return new Image(display, data, data.getTransparencyMask()); } return new Image(display, data); } finally { stream.close(); } }
aaf645c0-b5d9-4828-994f-4a4f74cb842c
public static Image getImage(String path) { Image image = m_imageMap.get(path); if (image == null) { try { image = getImage(new FileInputStream(path)); m_imageMap.put(path, image); } catch (Exception e) { image = getMissingImage(); m_imageMap.put(path, image); } } return image; }
b057760f-bc33-41d9-8aab-43a773e891d6
public static Image getImage(Class<?> clazz, String path) { String key = clazz.getName() + '|' + path; Image image = m_imageMap.get(key); if (image == null) { try { image = getImage(clazz.getResourceAsStream(path)); m_imageMap.put(key, image); } catch (Exception e) { image = getMissingImage(); m_imageMap.put(key, image); } } return image; }
9f19c146-28e7-4cd2-8a39-01106f796b13
private static Image getMissingImage() { Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); // GC gc = new GC(image); gc.setBackground(getColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); gc.dispose(); // return image; }
8eab8f6e-6400-4ed8-b996-d4a64d63bf49
public static Image decorateImage(Image baseImage, Image decorator) { return decorateImage(baseImage, decorator, BOTTOM_RIGHT); }
3ae47675-89d9-4e0d-8a07-18558b18db6a
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { if (corner <= 0 || corner >= LAST_CORNER_KEY) { throw new IllegalArgumentException("Wrong decorate corner"); } Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner]; if (cornerDecoratedImageMap == null) { cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>(); m_decoratedImageMap[corner] = cornerDecoratedImageMap; } Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage); if (decoratedMap == null) { decoratedMap = new HashMap<Image, Image>(); cornerDecoratedImageMap.put(baseImage, decoratedMap); } // Image result = decoratedMap.get(decorator); if (result == null) { Rectangle bib = baseImage.getBounds(); Rectangle dib = decorator.getBounds(); // result = new Image(Display.getCurrent(), bib.width, bib.height); // GC gc = new GC(result); gc.drawImage(baseImage, 0, 0); if (corner == TOP_LEFT) { gc.drawImage(decorator, 0, 0); } else if (corner == TOP_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, 0); } else if (corner == BOTTOM_LEFT) { gc.drawImage(decorator, 0, bib.height - dib.height); } else if (corner == BOTTOM_RIGHT) { gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); } gc.dispose(); // decoratedMap.put(decorator, result); } return result; }
f86878a1-00fd-48a5-9ee2-2b77adbb3133
public static void disposeImages() { // dispose loaded images { for (Image image : m_imageMap.values()) { image.dispose(); } m_imageMap.clear(); } // dispose decorated images for (int i = 0; i < m_decoratedImageMap.length; i++) { Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i]; if (cornerDecoratedImageMap != null) { for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) { for (Image image : decoratedMap.values()) { image.dispose(); } decoratedMap.clear(); } cornerDecoratedImageMap.clear(); } } }