Git Product home page Git Product logo

tree-sitter-codeviews's Introduction

Tree Sitter Multi Codeview Generator

Tree Sitter Multi Codeview Generator aims to generate combined multi-code view graphs that can be used with various types of machine learning models (sequence models, graph neural networks, etc).

Comex

comex is a rebuild of Tree Sitter Multi Codeview Generator for easier invocation as a Python package. This rebuild also includes a cli interface. Currently, comex generates codeviews for Java and C#, for both method-level and file-level code snippets. comex can be used to generate over $15$ possible combinations of codeviews for both languages (complete list here). comex is designed to be easily extendable to various programming languages. This is primarliy because we use tree-sitter for parsing, a highly efficient incremental parser that supports over $40$ languages. If you wish to add support for more languages, please refer to the contributing guide.

If you wish to learn more about the approach taken, here are some conference talks and publications:

Cite Comex

If you use Comex in your research, please cite our work by using the following BibTeX entry:

@misc{das2023comex,
      title={COMEX: A Tool for Generating Customized Source Code Representations}, 
      author={Debeshee Das and Noble Saji Mathews and Alex Mathai and Srikanth Tamilselvam and Kranthi Sedamaki and Sridhar Chimalakonda and Atul Kumar},
      year={2023},
      eprint={2307.04693},
      archivePrefix={arXiv},
      primaryClass={cs.SE}
}

Installation from PyPi

comex is published on the Python Registry and can be easily installed via pip:

pip install comex

Note: You would need to install GraphViz(dot) so that the graph visualizations are generated

Installation from source

To setup comex for development using the source code in your python environment:

pip install -r requirements-dev.txt

This performs an editable install, meaning that comex would be available throughout your environment (particularly relevant if you use conda or something of the sort). This means now you can interact and import from comex just like any other package while remaining standalone but also reflecting any code side updates without any other manual steps


Usage as a CLI

This is the recommended way to get started with comex as it is the most user friendly

The attributes and options supported by the CLI are well documented and can be viewed by running:

comex --help

For example, to generate a combined CFG and DFG graph for a java file, you can run:

comex --lang "java" --code-file ./test.java --graphs "cfg,dfg"

Usage as a Python Package

The comex package can be used by importing required drivers as follows:

from comex.codeviews.combined_graph.combined_driver import CombinedDriver

CombinedDriver(
    src_language=lang,
    src_code=code,
    output_file="output.json",
    graph_format=output,
    codeviews=codeviews
)

In most cases the required combination can be obtained via the combined_driver module as shown above.

src_language: denotes one of the supported languaged hence currently "java" or "cs"

src_code: denotes the source code to be parsed

output_file: denotes the output file to which the generated graph is written

graph_format: denotes the format of the output graph. Currently supported formats are "dot" and "json". To generate both pass "all"

codeviews: refers to the configuration passed for each codeview

Limitations

While comex provides method-level and file-level support for both Java and C#, it's important to note the following limitations and known issues:

Java

  • No Inter-file Analysis Support: The tool currently does not support codeviews that involve interactions between multiple Java files. It is designed to generate codeviews for individual Java files only.

  • Syntax Errors in Code: Despite supporting non-compileable code, to ensure accurate codeviews, the input Java code must be free of syntax errors. Code with syntax errors may not be correctly parsed and displayed in the generated codeviews.

  • Limited Support for Function Call Arguments: The tool does not provide proper support for when a function call is passed as an argument to another function call in Java code. The resulting codeview might not accurately represent the intended behavior in such cases.

C#

In addition to the limitations mentioned for Java, the tool has the following limitations specific to C#:

  • No Support for Lambda Functions and Arrow Expressions: The tool does not support codeviews involving lambda functions and arrow expressions in C#. The generated codeviews may not accurately represent these language features.

  • No Support for Compiler Directives: Compiler directives, such as pragma directives, are not supported by the tool. Code involving such directives may not be properly displayed in the generated codeviews.

  • Incomplete Operator Declaration Support: The tool may have limited support for operator declarations in C#. Certain constraints and edge cases related to operator overloading might not be fully captured in the generated codeviews.

  • Limited Support for Inheritance and Abstraction: The tool's support for inheritance and abstraction in C# is not fully comprehensive. Codeviews involving complex inheritance hierarchies or advanced abstraction patterns may not be accurately represented.

Please note that while we continuously work to improve the tool and address these limitations, the current implementation may not be perfect. We appreciate your understanding and encourage you to provide feedback and report any issues you encounter, as this helps us enhance the tool's capabilities.


Output Examples:

Combined simple AST+CFG+DFG for a simple Java program that finds the maximum among 2 numbers:

Sample AST CFG DFG

Below we present more examples of input code snippets and generated codeviews for both Java and C#.


CLI Command:

comex --lang "java" --code-file sample/example.java --graphs "cfg,dfg"

Java Code Snippet:

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    //    static String INPUT = "5\n3 2 2 4 1\n1 2 2 2 1";
    static String INPUT = "";

    public static void main(String[] args) {
        InputStream is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());

        Scanner scanner = new Scanner(is);

        final int n = scanner.nextInt();
        List<Position> positionList = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            positionList.add(
                    new Position(
                            scanner.nextInt(),
                            scanner.nextInt(),
                            scanner.nextInt()
                    )
            );
        }

        System.out.println(solve(positionList) ? "Yes" : "No");
    }

    static class Position {
        int t;
        int x;
        int y;

        public Position(int t, int x, int y) {
            this.t = t;
            this.x = x;
            this.y = y;
        }
    }

    static boolean solve(List<Position> positionList) {
        Position currentPosition = new Position(0, 0, 0);
        for (int i = 0; i < positionList.size(); i++) {
            Position nextPosition = positionList.get(i);
            if (!possibleMove(currentPosition.t, nextPosition.t, currentPosition.x, nextPosition.x, currentPosition.y, nextPosition.y)) {
                return false;
            }
            currentPosition = nextPosition;
        }
        return true;
    }

    static boolean possibleMove(int t1, int t2, int x1, int x2, int y1, int y2) {
        int tDiff = t2 - t1;
        int absX = Math.abs(x1 - x2);
        int absY = Math.abs(y1 - y2);

        if (absX + absY <= tDiff) {
            if (tDiff % 2 == (absX + absY) % 2) {
                return true;
            }
        }
        return false;
    }

}

Generated Codeview:

Java File-level


CLI Command:

comex --lang "cs" --code-file sample/example.cs --graphs "cfg,dfg"

C# Code Snippet:

public class DFG_A2 {
    public void main(string[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // {}
        String str = br.attribute1; // {3}
        str = br.attribute2.method1(); // {3}
        br.attribute1 = br.attribute2; // {3,5}
        br.method2(br.attribute1, br.attribute2); // {3,5,6}
        BufferedReader br2 = br; // {5,6,7}
        br.method3(); // {5,6,7}
        int j = br2.attribute1.method2(3,4); // {8}
    }
}

Generated Codeview:

C# Method-level


More examples and results can be found in the tests/data directory

Code Organization

The code is structured in the following way:

  1. For each code-view, first the source code is parsed using the tree-sitter parser and then the various code-views are generated. In the tree_parser directory, the Parser and ParserDriver is implemented with various funcitonalities commonly required by all code-views. Language-specific features are further developed in the language-specific parsers also placed in this directory.
  2. The codeviews directory contains the core logic for the various codeviews. Each codeview has a driver class and a codeview class, which is further inherited and extended by language in case of code-views that require language-specific implementation.
  3. The cli.py file is the CLI implementation. The drivers can also be directly imported and used like a python package. It is responsible for parsing the source code and generating the codeviews.

Testing

The repo is setup to automatically perform CI tests on making pulls to main and development branches. To test locally:

Run specific test

  • Say you wish to run test_cfg function
  • Drop the '[...]' part to run all tests in a file
    • formatted as [extension-filename]
  • no-cov prevents coverage report from being printed
pytest -k 'test_cfg[cs-test7]' --no-cov

Run all tests and get coverage report

pytest

Analyze the deviation report given by deepdiff by using the verbose output. This will help quickly figure out difference from the gold file

pytest -k 'test_cfg[cs-test7]' --no-cov -vv

Publishing

Make sure to bump the version in setup.cfg.

Then run the following commands:

rm -rf build dist
python setup.py sdist bdist_wheel

Then upload it to PyPI using twine (pip install twine if not installed):

twine upload dist/*

About the IBM OSCP Project

This tool was developed for research purposes as a part of the OSCP Project. Efficient representation of source code is essential for various software engineering tasks using AI pipelines such as code translation, code search and code clone detection. Code Representation aims at extracting the both syntactic and semantic features of source code and representing them by a vector which can be readily used for the downstream tasks. Multiple works exist that attempt to encode the code as sequential data to easily leverage state of art NN models like transformers. But it leads to a loss of information. Graphs are a natural representation for the code but very few works(MVG-AAAI’22) have tried to represent the different code features obtained from different code views like Program Dependency Graph, Data Flow Graph etc. as a multi-view graph. In this work, we want to explore more code views and its relevance to different code tasks as well as leverage transformers model for the multi-code view graphs. We believe such a work will help to

  1. Establish influence of specific code views for common tasks
  2. Demonstrate how graphs can combined with transformers
  3. Create re-usable models

Team

This tool is based on the ongoing joint research effort between IBM and Risha Lab at IIT Tirupati to explore the effects of different code representations on code based tasks involving:

tree-sitter-codeviews's People

Contributors

alex-mathai-98 avatar debesheedas avatar ibm-open-source-bot avatar noblemathews avatar tusharsadhwani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tree-sitter-codeviews's Issues

Package does not work on Python 3.12

In Python 3.12 distutils is no longer a built-in module:

$ comex --lang "java" --code-file ./Foo.java --graphs dfg
Traceback (most recent call last):
  File "/private/tmp/venv/bin/comex", line 5, in <module>
    from comex.cli import app
  File "/private/tmp/venv/lib/python3.12/site-packages/comex/__init__.py", line 3, in <module>
    from tree_sitter import Language
  File "/private/tmp/venv/lib/python3.12/site-packages/tree_sitter/__init__.py", line 4, in <module>
    from distutils.ccompiler import new_compiler
ModuleNotFoundError: No module named 'distutils'

The fix would be to install setuptools for Python 3.12 and above.

Missing CFG_python

I would like to ask if CFG_java and DFG_java files can also be used to produce CFG and DFG for python source code?

Lightweight Program Analysis Support

I am new to this library, and I must say it looks great! I intend to perform lightweight program analysis for incomplete code. For example, I am considering to perform backward and forward slicing. I would like to know if this library is a good fit for this particular form of analysis. If so, I would greatly appreciate any examples on how to achieve this with the existing functionality.

However, if the library currently does not support such analysis, I would like to request the addition of this feature. I think having this functionality integrated into the library would be extremely beneficial.

Thank you for considering this request. I am excited to hear your feedback and any insights you can provide.

local variable 'class_name' referenced before assignment

I have a problem using this tool. What is the problem? and How can I solve this?
Thank you for your help!

  • Terminal that it include error.
(crypto) people@abc-95:$ comex --lang "java" --code-file /data/Crypto/data_tmp/rule2/com.appybuilder.moviesnowupdates.AadharCardLink_com.go
ogle.appinventor.components.runtime.util.AppInvHTTPD.java --graphs cfg
2023-11-28 22:29:39.645 | ERROR    | comex.cli:main:118 - local variable 'class_name' referenced before assignment
  • Code that I try to make graph is this.
package com.google.appinventor.components.runtime.util;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.ReplForm;
import com.google.appinventor.components.runtime.util.NanoHTTPD;
import gnu.expr.Language;
import gnu.expr.ModuleExp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Enumeration;
import java.util.Formatter;
import java.util.Properties;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import kawa.standard.Scheme;
import org.shaded.apache.http.client.methods.HttpOptions;
import org.shaded.apache.http.client.methods.HttpPut;


public class AppInvHTTPD extends NanoHTTPD {
    private static final String LOG_TAG = "AppInvHTTPD";
    private static final String MIME_JSON = "application/json";
    private static final int YAV_SKEW_BACKWARD = 4;
    private static final int YAV_SKEW_FORWARD = 1;
    private static byte[] hmacKey;
    private static int seq;
    private final Handler androidUIHandler;
    private ReplForm form;
    private File rootDir;
    private Language scheme;
    private boolean secure;

    public AppInvHTTPD(int port, File wwwroot, boolean secure, ReplForm form) throws IOException {
        super(port, wwwroot);
        this.androidUIHandler = new Handler();
        this.rootDir = wwwroot;
        this.scheme = Scheme.getInstance("scheme");
        this.form = form;
        this.secure = secure;
        ModuleExp.mustNeverCompile();
    }

    @Override  com.google.appinventor.components.runtime.util.NanoHTTPD
    public NanoHTTPD.Response serve(String uri, String method, Properties header, Properties parms, Properties files, Socket mySocket) {
        NanoHTTPD.Response res;
        String installer;
        NanoHTTPD.Response res2;
        Log.d(LOG_TAG, method + " '" + uri + "' ");
        if (this.secure) {
            InetAddress myAddress = mySocket.getInetAddress();
            String hostAddress = myAddress.getHostAddress();
            if (!hostAddress.equals("127.0.0.1")) {
                Log.d(LOG_TAG, "Debug: hostAddress = " + hostAddress + " while in secure mode, closing connection.");
                NanoHTTPD.Response res3 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: Invalid Source Location " + hostAddress + "\"}");
                res3.addHeader("Access-Control-Allow-Origin", "*");
                res3.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                res3.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                res3.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                return res3;
            }
        }
        if (method.equals(HttpOptions.METHOD_NAME)) {
            Enumeration e = header.propertyNames();
            while (e.hasMoreElements()) {
                String value = (String) e.nextElement();
                Log.d(LOG_TAG, "  HDR: '" + value + "' = '" + header.getProperty(value) + "'");
            }
            NanoHTTPD.Response res4 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "OK");
            res4.addHeader("Access-Control-Allow-Origin", "*");
            res4.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res4.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res4.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            return res4;
        } else if (uri.equals("/_newblocks")) {
            String inSeq = parms.getProperty("seq", "0");
            int iseq = Integer.parseInt(inSeq);
            String blockid = parms.getProperty("blockid");
            String code = parms.getProperty("code");
            String inMac = parms.getProperty("mac", "no key provided");
            if (hmacKey != null) {
                try {
                    Mac hmacSha1 = Mac.getInstance("HmacSHA1");
                    SecretKeySpec key = new SecretKeySpec(hmacKey, "RAW");
                    hmacSha1.init(key);
                    byte[] tmpMac = hmacSha1.doFinal((code + inSeq + blockid).getBytes());
                    StringBuffer sb = new StringBuffer(tmpMac.length * 2);
                    Formatter formatter = new Formatter(sb);
                    for (byte b : tmpMac) {
                        formatter.format("%02x", Byte.valueOf(b));
                    }
                    String compMac = sb.toString();
                    Log.d(LOG_TAG, "Incoming Mac = " + inMac);
                    Log.d(LOG_TAG, "Computed Mac = " + compMac);
                    Log.d(LOG_TAG, "Incoming seq = " + inSeq);
                    Log.d(LOG_TAG, "Computed seq = " + seq);
                    Log.d(LOG_TAG, "blockid = " + blockid);
                    if (!inMac.equals(compMac)) {
                        Log.e(LOG_TAG, "Hmac does not match");
                        this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "Invalid HMAC");
                        NanoHTTPD.Response res5 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: Invalid MAC\"}");
                        return res5;
                    } else if (seq != iseq && seq != iseq + 1) {
                        Log.e(LOG_TAG, "Seq does not match");
                        this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "Invalid Seq");
                        NanoHTTPD.Response res6 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: Invalid Seq\"}");
                        return res6;
                    } else {
                        if (seq == iseq + 1) {
                            Log.e(LOG_TAG, "Seq Fixup Invoked");
                        }
                        seq = iseq + 1;
                        String code2 = "(begin (require <com.google.youngandroid.runtime>) (process-repl-input " + blockid + " (begin " + code + " )))";
                        Log.d(LOG_TAG, "To Eval: " + code2);
                        this.form.loadComponents();
                        try {
                            if (code.equals("#f")) {
                                Log.e(LOG_TAG, "Skipping evaluation of #f");
                            } else {
                                this.scheme.eval(code2);
                            }
                            res2 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, RetValManager.fetch(false));
                        } catch (Throwable ex) {
                            RetValManager.appendReturnValue(blockid, "BAD", ex.toString());
                            res2 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, RetValManager.fetch(false));
                        }
                        res2.addHeader("Access-Control-Allow-Origin", "*");
                        res2.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                        res2.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                        res2.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                        return res2;
                    }
                } catch (Exception e2) {
                    Log.e(LOG_TAG, "Error working with hmac", e2);
                    this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "Exception working on HMAC");
                    NanoHTTPD.Response res7 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "NOT");
                    return res7;
                }
            }
            Log.e(LOG_TAG, "No HMAC Key");
            this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "No HMAC Key");
            NanoHTTPD.Response res8 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: No HMAC Key\"}");
            return res8;
        } else if (uri.equals("/_values")) {
            NanoHTTPD.Response res9 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, RetValManager.fetch(true));
            res9.addHeader("Access-Control-Allow-Origin", "*");
            res9.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res9.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res9.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            return res9;
        } else if (uri.equals("/_getversion")) {
            try {
                String packageName = this.form.getPackageName();
                PackageInfo pInfo = this.form.getPackageManager().getPackageInfo(packageName, 0);
                if (SdkLevel.getLevel() >= 5) {
                    installer = EclairUtil.getInstallerPackageName(YaVersion.ACCEPTABLE_COMPANION_PACKAGE, this.form);
                } else {
                    installer = "Not Known";
                }
                String versionName = pInfo.versionName;
                if (installer == null) {
                    installer = "Not Known";
                }
                res = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"version\" : \"" + versionName + "\", \"fingerprint\" : \"" + Build.FINGERPRINT + "\", \"installer\" : \"" + installer + "\", \"package\" : \"" + packageName + "\", \"fqcn\" : true }");
            } catch (PackageManager.NameNotFoundException n) {
                n.printStackTrace();
                res = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"verison\" : \"Unknown\"");
            }
            res.addHeader("Access-Control-Allow-Origin", "*");
            res.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            if (this.secure) {
                seq = 1;
                this.androidUIHandler.post(new Runnable() {  from class: com.google.appinventor.components.runtime.util.AppInvHTTPD.1
                    @Override  java.lang.Runnable
                    public void run() {
                        AppInvHTTPD.this.form.clear();
                    }
                });
                return res;
            }
            return res;
        } else if (uri.equals("/_update") || uri.equals("/_install")) {
            String url = parms.getProperty("url", "");
            String inMac2 = parms.getProperty("mac", "");
            if (!url.equals("") && hmacKey != null && !inMac2.equals("")) {
                try {
                    SecretKeySpec key2 = new SecretKeySpec(hmacKey, "RAW");
                    Mac hmacSha12 = Mac.getInstance("HmacSHA1");
                    hmacSha12.init(key2);
                    byte[] tmpMac2 = hmacSha12.doFinal(url.getBytes());
                    StringBuffer sb2 = new StringBuffer(tmpMac2.length * 2);
                    Formatter formatter2 = new Formatter(sb2);
                    for (byte b2 : tmpMac2) {
                        formatter2.format("%02x", Byte.valueOf(b2));
                    }
                    String compMac2 = sb2.toString();
                    Log.d(LOG_TAG, "Incoming Mac (update) = " + inMac2);
                    Log.d(LOG_TAG, "Computed Mac (update) = " + compMac2);
                    if (!inMac2.equals(compMac2)) {
                        Log.e(LOG_TAG, "Hmac does not match");
                        this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "Invalid HMAC (update)");
                        NanoHTTPD.Response res10 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: Invalid MAC\"}");
                        res10.addHeader("Access-Control-Allow-Origin", "*");
                        res10.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                        res10.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                        res10.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                        return res10;
                    }
                    doPackageUpdate(url);
                    NanoHTTPD.Response res11 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"OK\", \"message\" : \"Update Should Happen\"}");
                    res11.addHeader("Access-Control-Allow-Origin", "*");
                    res11.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                    res11.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                    res11.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                    return res11;
                } catch (Exception e3) {
                    Log.e(LOG_TAG, "Error verifying update", e3);
                    this.form.dispatchErrorOccurredEvent(this.form, LOG_TAG, ErrorMessages.ERROR_REPL_SECURITY_ERROR, "Exception working on HMAC for update");
                    NanoHTTPD.Response res12 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Security Error: Exception processing MAC\"}");
                    res12.addHeader("Access-Control-Allow-Origin", "*");
                    res12.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                    res12.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                    res12.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                    return res12;
                }
            }
            NanoHTTPD.Response res13 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, MIME_JSON, "{\"status\" : \"BAD\", \"message\" : \"Missing Parameters\"}");
            res13.addHeader("Access-Control-Allow-Origin", "*");
            res13.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res13.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res13.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            return res13;
        } else if (uri.equals("/_package")) {
            String packageapk = parms.getProperty("package", null);
            if (packageapk == null) {
                NanoHTTPD.Response res14 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "NOT OK");
                return res14;
            }
            Log.d(LOG_TAG, this.rootDir + "/" + packageapk);
            doPackageUpdate("file:/" + this.rootDir + "/" + packageapk);
            NanoHTTPD.Response res15 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "OK");
            res15.addHeader("Access-Control-Allow-Origin", "*");
            res15.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res15.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res15.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            return res15;
        } else if (method.equals(HttpPut.METHOD_NAME)) {
            Boolean error = false;
            String tmpFileName = files.getProperty("content", null);
            if (tmpFileName != null) {
                File fileFrom = new File(tmpFileName);
                String filename = parms.getProperty("filename", null);
                if (filename != null && (filename.startsWith("..") || filename.endsWith("..") || filename.indexOf("../") >= 0)) {
                    Log.d(LOG_TAG, " Ignoring invalid filename: " + filename);
                    filename = null;
                }
                if (filename != null) {
                    File fileTo = new File(this.rootDir + "/" + filename);
                    File parentFileTo = fileTo.getParentFile();
                    if (!parentFileTo.exists()) {
                        parentFileTo.mkdirs();
                    }
                    if (!fileFrom.renameTo(fileTo)) {
                        copyFile(fileFrom, fileTo);
                        fileFrom.delete();
                    }
                } else {
                    fileFrom.delete();
                    Log.e(LOG_TAG, "Received content without a file name!");
                    error = true;
                }
            } else {
                Log.e(LOG_TAG, "Received PUT without content.");
                error = true;
            }
            if (error.booleanValue()) {
                NanoHTTPD.Response res16 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "NOTOK");
                res16.addHeader("Access-Control-Allow-Origin", "*");
                res16.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                res16.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                res16.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                return res16;
            }
            NanoHTTPD.Response res17 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "OK");
            res17.addHeader("Access-Control-Allow-Origin", "*");
            res17.addHeader("Access-Control-Allow-Headers", "origin, content-type");
            res17.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
            res17.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
            return res17;
        } else {
            Enumeration e4 = header.propertyNames();
            while (e4.hasMoreElements()) {
                String value2 = (String) e4.nextElement();
                Log.d(LOG_TAG, "  HDR: '" + value2 + "' = '" + header.getProperty(value2) + "'");
            }
            Enumeration e5 = parms.propertyNames();
            while (e5.hasMoreElements()) {
                String value3 = (String) e5.nextElement();
                Log.d(LOG_TAG, "  PRM: '" + value3 + "' = '" + parms.getProperty(value3) + "'");
            }
            Enumeration e6 = files.propertyNames();
            if (e6.hasMoreElements()) {
                String fieldname = (String) e6.nextElement();
                String tempLocation = files.getProperty(fieldname);
                String filename2 = parms.getProperty(fieldname);
                if (filename2.startsWith("..") || filename2.endsWith("..") || filename2.indexOf("../") >= 0) {
                    Log.d(LOG_TAG, " Ignoring invalid filename: " + filename2);
                    filename2 = null;
                }
                File fileFrom2 = new File(tempLocation);
                if (filename2 == null) {
                    fileFrom2.delete();
                } else {
                    File fileTo2 = new File(this.rootDir + "/" + filename2);
                    if (!fileFrom2.renameTo(fileTo2)) {
                        copyFile(fileFrom2, fileTo2);
                        fileFrom2.delete();
                    }
                }
                Log.d(LOG_TAG, " UPLOADED: '" + filename2 + "' was at '" + tempLocation + "'");
                NanoHTTPD.Response res18 = new NanoHTTPD.Response(NanoHTTPD.HTTP_OK, "text/plain", "OK");
                res18.addHeader("Access-Control-Allow-Origin", "*");
                res18.addHeader("Access-Control-Allow-Headers", "origin, content-type");
                res18.addHeader("Access-Control-Allow-Methods", "POST,OPTIONS,GET,HEAD,PUT");
                res18.addHeader("Allow", "POST,OPTIONS,GET,HEAD,PUT");
                return res18;
            }
            NanoHTTPD.Response res19 = serveFile(uri, header, this.rootDir, true);
            return res19;
        }
    }

    private void copyFile(File infile, File outfile) {
        try {
            FileInputStream in = new FileInputStream(infile);
            FileOutputStream out = new FileOutputStream(outfile);
            byte[] buffer = new byte[32768];
            while (true) {
                int len = in.read(buffer);
                if (len > 0) {
                    out.write(buffer, 0, len);
                } else {
                    in.close();
                    out.close();
                    return;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void setHmacKey(String inputKey) {
        hmacKey = inputKey.getBytes();
        seq = 1;
    }

    private void doPackageUpdate(String inurl) {
        PackageInstaller.doPackageInstall(this.form, inurl);
    }

    public void resetSeq() {
        seq = 1;
    }
}

Support for Python

Do you plan to add support for Python? If yes, what's the timeline looks like?

Query on Tree Sitter Multi Codeview Generator's Ability to Resolve Object Types

I am exploring the Tree Sitter Multi Codeview Generator's functionalities, particularly its ability to resolve object types within a class. I have a scenario in my project where a class is designed to instantiate another class within its constructor and subsequently use this instance. Here's a simplified code snippet to illustrate the setup:

import AnotherClass;

class SomeClass {
   private AnotherClass anotherClass;

   // Constructor initializing some variables from another class
   public SomeClass() {
       this.anotherClass = new AnotherClass();
   }

   // Method that uses a variable from the constructor to perform operations
   public void someMethod() {
       // Operations using anotherClass instance
       this.anotherClass.someMethodFromAnotherClass();
   }
}

In this context, I am trying to understand whether Tree Sitter Multi Codeview Generator can effectively detect that this.anotherClass is an instance of AnotherClass.

Could you provide insights or confirm whether Tree Sitter Multi Codeview Generator supports this level of type resolution?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.