From 19a5457f071fce4c55c3f14586430e7cd43e0e7b Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Sun, 20 Apr 2014 01:42:57 -0400 Subject: [PATCH] Change director structure for java --- .../src/main/java/org/bitshift/parsing/Parse.java | 40 ----- .../java/org/bitshift/parsing/parsers/CParser.java | 3 - .../org/bitshift/parsing/parsers/JavaParser.java | 164 --------------------- .../java/org/bitshift/parsing/parsers/Parser.java | 16 -- .../org/bitshift/parsing/symbols/CSymbols.java | 1 - .../org/bitshift/parsing/symbols/JavaSymbols.java | 153 ------------------- .../java/org/bitshift/parsing/symbols/Symbols.java | 9 -- 7 files changed, 386 deletions(-) delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/Parse.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java delete mode 100644 parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java diff --git a/parsers/java/src/main/java/org/bitshift/parsing/Parse.java b/parsers/java/src/main/java/org/bitshift/parsing/Parse.java deleted file mode 100644 index 593645b..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/Parse.java +++ /dev/null @@ -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) { - - } - } - -} diff --git a/parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java b/parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java deleted file mode 100644 index 9cd4308..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/parsers/CParser.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.bitshift.parsing.parsers; - -import org.bitshift.parsing.parsers.Parser; diff --git a/parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java b/parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java deleted file mode 100644 index bb7b7e4..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/parsers/JavaParser.java +++ /dev/null @@ -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> _cache; - - public JavaParser(String source) { - super(source); - this.symbols = new JavaSymbols(); - this._cache = new Stack>(); - } - - @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 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; - } - - } -} diff --git a/parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java b/parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java deleted file mode 100644 index 9b96a8d..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/parsers/Parser.java +++ /dev/null @@ -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(); - -} - diff --git a/parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java b/parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java deleted file mode 100644 index f71667e..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/symbols/CSymbols.java +++ /dev/null @@ -1 +0,0 @@ -package org.bitshift.parsing.symbols; diff --git a/parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java b/parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java deleted file mode 100644 index aa39cfd..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/symbols/JavaSymbols.java +++ /dev/null @@ -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 _classes; - private Map _interfaces; - private Map _methods; - private Map _fields; - private Map _vars; - - public JavaSymbols() { - _packageName = null; - _classes = new HashMap(); - _interfaces = new HashMap(); - _methods = new HashMap(); - _fields = new HashMap(); - _vars = new HashMap(); - } - - public boolean setPackage(String name) { - _packageName = name; - return true; - } - - public boolean insertClassDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) { - List pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : 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 pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : copy; - - copy.add(pos); - _classes.put(name, copy); - return true; - } - - public boolean insertInterfaceDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) { - List pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : 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 pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : copy; - - copy.add(pos); - _classes.put(name, copy); - return true; - } - - public boolean insertMethodDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) { - List pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : 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 pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : copy; - - copy.add(pos); - _classes.put(name, copy); - return true; - } - - public boolean insertFieldDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) { - List pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : 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 pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : copy; - - copy.add(pos); - _classes.put(name, copy); - return true; - } - - public boolean insertVariableDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) { - List pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : 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 pos = new ArrayList(4); - pos.set(0, startLine); pos.set(1, startCol); pos.set(2, endLine); pos.set(3, endCol); - - List> copy = (List>)_classes.get(name); - copy = (copy == null) ? new ArrayList>() : copy; - - copy.add(pos); - _classes.put(name, copy); - return true; - } - - public String toString() { - return ""; - } -} - diff --git a/parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java b/parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java deleted file mode 100644 index 70762b1..0000000 --- a/parsers/java/src/main/java/org/bitshift/parsing/symbols/Symbols.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.bitshift.parsing.symbols; - -public class Symbols { - - public Symbols() { - - } - -}