ソースを参照

Change director structure for java

tags/v1.0^2
Benjamin Attal 10年前
コミット
19a5457f07
7個のファイルの変更0行の追加386行の削除
  1. +0
    -40
      parsers/java/src/main/java/org/bitshift/parsing/Parse.java
  2. +0
    -3
      parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java
  3. +0
    -164
      parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java
  4. +0
    -16
      parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java
  5. +0
    -1
      parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java
  6. +0
    -153
      parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java
  7. +0
    -9
      parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java

+ 0
- 40
parsers/java/src/main/java/org/bitshift/parsing/Parse.java ファイルの表示

@@ -1,40 +0,0 @@
import java.io.*;
import java.net.*;

public class Parse {

public static void main(String[][] args) {
String fromClient;
String toClient;

try {
ServerSocket server = new ServerSocket(5002);

while(true) {
Socket connected = server.accept();
System.out.println("The client is connected.");

BufferedReader clientReader = new BufferedReader(
new InputStreamReader(connected.getInputStream()));

PrintWriter clientWriter = new PrintWriter(
connected.getOutputStream(), true);

while(true) {
StringBuilder builder = new StringBuilder();
while((fromClient = clientReader.readLine()) != null) {
builder.append(fromClient);
}

fromClient = builder.toString();

//Handle the data from the client here
}
}
} catch (IOException ex) {
}
}

}

+ 0
- 3
parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java ファイルの表示

@@ -1,3 +0,0 @@
package org.bitshift.parsing.parsers;

import org.bitshift.parsing.parsers.Parser;

+ 0
- 164
parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java ファイルの表示

@@ -1,164 +0,0 @@
package org.bitshift.parsing.parsers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.FieldAccess;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.QualifiedType;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

import org.bitshift.parsing.parsers.Parser;
import org.bitshift.parsing.symbols.Symbols;
import org.bitshift.parsing.symbols.JavaSymbols;

/*TODO: Work on parsing partial java code.
* Change visits to endVisit and implement a cache*/
public class JavaParser extends Parser {

protected JavaSymbols symbols;
protected CompilationUnit compUnit;
private Stack<Map<String, Object>> _cache;

public JavaParser(String source) {
super(source);
this.symbols = new JavaSymbols();
this._cache = new Stack<Map<String, Object>>();
}

@Override
public Symbols genSymbols() {
char[] source = this.source.toCharArray();

ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(source);

Map options = JavaCore.getOptions();
parser.setCompilerOptions(options);

//Work on parsing partial java code later
this.compUnit = (CompilationUnit) parser.createAST(null);

ASTVisitor visitor = new NodeVisitor();
this.compUnit.accept(visitor);

return this.symbols;
}

class NodeVisitor extends ASTVisitor {

public boolean visit(ClassInstanceCreation node) {
Type typeObj = node.getType();
Name nameObj = typeObj.isQualifiedType() ? ((QualifiedType) typeObj).getName() : ((SimpleType) typeObj).getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;

symbols.insertClassInstance(name, sl, sc, null, null);
return true;
}

public boolean visit(FieldAccess node) {
Name nameObj = node.getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;

symbols.insertFieldAccess(name, sl, sc, null, null);
return true;
}

public boolean visit(FieldDeclaration node) {
Type typeObj = node.getType();
Name nameObj = typeObj.isQualifiedType() ? ((QualifiedType) typeObj).getName() : ((SimpleType) typeObj).getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;

symbols.insertFieldDeclaration(name, sl, sc, null, null);
return true;
}

public boolean visit(MethodDeclaration node) {
Name nameObj = node.getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();
List<Statement> statements = node.getBody().statements();
Statement last = statements.get(statements.size() - 1);

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;
int el = compUnit.getLineNumber(last.getStartPosition()) - 1;
int ec = compUnit.getColumnNumber(last.getStartPosition()) - 1;

symbols.insertMethodDeclaration(name, sl, sc, el, ec);
return true;
}

public boolean visit(MethodInvocation node) {
Name nameObj = node.getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;

symbols.insertMethodInvocation(name, sl, sc, null, null);
return true;
}

public boolean visit(PackageDeclaration node) {
Name nameObj = node.getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

symbols.setPackage(name);
return true;
}

public boolean visit(TypeDeclaration node) {
Name nameObj = node.getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;

if (node.isInterface()) {
symbols.insertInterfaceDeclaration(name, sl, sc, null, null);
} else {
symbols.insertClassDeclaration(name, sl, sc, null, null);
}
return true;
}

public boolean visit(VariableDeclarationStatement node) {
Type typeObj = node.getType();
Name nameObj = typeObj.isQualifiedType() ? ((QualifiedType) typeObj).getName() : ((SimpleType) typeObj).getName();
String name = nameObj.isQualifiedName() ? ((QualifiedName)nameObj).getFullyQualifiedName() : ((SimpleName)nameObj).getIdentifier();

int sl = compUnit.getLineNumber(node.getStartPosition()) - 1;
int sc = compUnit.getColumnNumber(node.getStartPosition()) - 1;
symbols.insertVariableDeclaration(name, sl, sc, null, null);
return true;
}

}
}

+ 0
- 16
parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java ファイルの表示

@@ -1,16 +0,0 @@
package org.bitshift.parsing.parsers;

import org.bitshift.parsing.symbols.Symbols;

public abstract class Parser {

protected String source;

public Parser(String source) {
this.source = source;
}

abstract Symbols genSymbols();
}


+ 0
- 1
parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java ファイルの表示

@@ -1 +0,0 @@
package org.bitshift.parsing.symbols;

+ 0
- 153
parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java ファイルの表示

@@ -1,153 +0,0 @@
package org.bitshift.parsing.symbols;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import org.bitshift.parsing.symbols.Symbols;

/*TODO: Overwrite toString
* Change instance vars to HashMaps of HashMaps*/
public class JavaSymbols extends Symbols {

private String _packageName;
private Map<String, Object> _classes;
private Map<String, Object> _interfaces;
private Map<String, Object> _methods;
private Map<String, Object> _fields;
private Map<String, Object> _vars;

public JavaSymbols() {
_packageName = null;
_classes = new HashMap<String, Object>();
_interfaces = new HashMap<String, Object>();
_methods = new HashMap<String, Object>();
_fields = new HashMap<String, Object>();
_vars = new HashMap<String, Object>();
}

public boolean setPackage(String name) {
_packageName = name;
return true;
}

public boolean insertClassDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(0, pos);
_classes.put(name, copy);
return true;
}
public boolean insertClassInstance(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(pos);
_classes.put(name, copy);
return true;
}

public boolean insertInterfaceDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(0, pos);
_classes.put(name, copy);
return true;
}
public boolean insertInterfaceInstance(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(pos);
_classes.put(name, copy);
return true;
}

public boolean insertMethodDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(0, pos);
_classes.put(name, copy);
return true;
}
public boolean insertMethodInvocation(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(pos);
_classes.put(name, copy);
return true;
}

public boolean insertFieldDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(0, pos);
_classes.put(name, copy);
return true;
}
public boolean insertFieldAccess(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(pos);
_classes.put(name, copy);
return true;
}

public boolean insertVariableDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(0, pos);
_classes.put(name, copy);
return true;
}
public boolean insertVariableAccess(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
List<Integer> pos = new ArrayList<Integer>(4);
pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol);
List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;

copy.add(pos);
_classes.put(name, copy);
return true;
}

public String toString() {
return "";
}
}


+ 0
- 9
parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java ファイルの表示

@@ -1,9 +0,0 @@
package org.bitshift.parsing.symbols;

public class Symbols {

public Symbols() {
}

}

読み込み中…
キャンセル
保存