merge all into single repo
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
description = 'GumTree tree generator for C/C++, C# and Java code. Requires srcml.'
|
||||
|
||||
ext.isNative = true
|
||||
@@ -0,0 +1,46 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.gumtreediff</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<parent>
|
||||
<groupId>com.github.gumtreediff</groupId>
|
||||
<artifactId>gumtree</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>gen.srcml</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Gumtree Tree Generator</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>edu.lu.uni</groupId>
|
||||
<artifactId>simple-utils</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.gumtreediff</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>edu.lu.uni.serval</groupId>
|
||||
<artifactId>CommitParser</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency> -->
|
||||
<!-- Logger -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+437
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.gen.TreeGenerator;
|
||||
import com.github.gumtreediff.io.LineReader;
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.events.Characters;
|
||||
import javax.xml.stream.events.EndElement;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public abstract class AbstractSrcmlTreeGenerator extends TreeGenerator {
|
||||
|
||||
|
||||
|
||||
|
||||
// private static final String SRCML_CMD = System.getProperty("gumtree.srcml.path", "srcml");
|
||||
private String SRCML_CMD = "/Users/anil.koyuncu/Downloads22/srcML/src2srcml";
|
||||
// private static String namespace = "http://www.sdml.info/srcML/position";
|
||||
private static String namespace = "http://www.srcML.org/srcML/position";
|
||||
private static final QName LINE = new QName(namespace, "line", "pos");
|
||||
|
||||
private static final QName COLUMN = new QName(namespace, "column", "pos");
|
||||
private static final QName COMMENT_BLOCK = new QName("", "type", "");
|
||||
|
||||
private LineReader lr;
|
||||
|
||||
private HashSet<String> removeType = new HashSet<>(Arrays.asList("empty_stmt","comment"));
|
||||
private HashSet<String> labeled = new HashSet<String>(
|
||||
// Arrays.asList("comment"));
|
||||
Arrays.asList("specifier", "name", "argument","expr","type","value","index","operator","literal","incr","modifier","break","continue","default","literal:string","literal:number","literal:char","literal:boolean","literal:complex","literal:null"));
|
||||
|
||||
|
||||
private StringBuilder currentLabel;
|
||||
|
||||
private TreeContext context;
|
||||
|
||||
// Type position = type("position");
|
||||
|
||||
@Override
|
||||
public TreeContext generate(Reader r) throws IOException {
|
||||
lr = new LineReader(r);
|
||||
String xml = readStandardOutput(lr);
|
||||
return getTreeContext(xml);
|
||||
}
|
||||
|
||||
public static <T, E> List<T> getKeysByValue(Map<T, E> map, E value) {
|
||||
return map.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> Objects.equals(entry.getValue(), value))
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public TreeContext getTreeContext(String xml) {
|
||||
XMLInputFactory fact = XMLInputFactory.newInstance();
|
||||
context = new TreeContext();
|
||||
currentLabel = new StringBuilder();
|
||||
boolean isBlock = false;
|
||||
try {
|
||||
ArrayDeque<ITree> trees = new ArrayDeque<>();
|
||||
XMLEventReader r = fact.createXMLEventReader(new StringReader(xml));
|
||||
while (r.hasNext()) {
|
||||
XMLEvent ev = r.nextEvent();
|
||||
|
||||
if (ev.isStartElement()) {
|
||||
StartElement s = ev.asStartElement();
|
||||
String typeLabel = s.getName().getLocalPart();
|
||||
String prefix = s.getName().getPrefix();
|
||||
if(removeType.contains(typeLabel) || isBlock){
|
||||
if(s.getName().getLocalPart().equals("comment") && s.getAttributeByName(COMMENT_BLOCK).getValue().equals("block")){
|
||||
isBlock = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeLabel.equals("position"))
|
||||
// Type type = type(s.getName().getLocalPart());
|
||||
// if (type.equals(position))
|
||||
setLength(trees.peekFirst(), s);
|
||||
else {
|
||||
if (prefix.equals("cpp") && (typeLabel.equals("if") || typeLabel.equals("else"))){
|
||||
typeLabel = prefix + ":"+typeLabel;
|
||||
}
|
||||
|
||||
if(typeLabel.equals("literal")){
|
||||
if(s.getAttributeByName(COMMENT_BLOCK) != null){
|
||||
String value = s.getAttributeByName(COMMENT_BLOCK).getValue();
|
||||
typeLabel = typeLabel + ":"+value;
|
||||
}
|
||||
}
|
||||
List<Integer> keysByValue = getKeysByValue(NodeMap_new.map, typeLabel);
|
||||
if(keysByValue == null || keysByValue.size() ==0){
|
||||
System.out.println(typeLabel);
|
||||
}
|
||||
int type = keysByValue.get(0);
|
||||
|
||||
ITree t = context.createTree(type, "", typeLabel);
|
||||
|
||||
|
||||
if (trees.isEmpty()) {
|
||||
context.setRoot(t);
|
||||
t.setPos(0);
|
||||
} else {
|
||||
t.setParentAndUpdateChildren(trees.peekFirst());
|
||||
setPos(t, s);
|
||||
}
|
||||
trees.addFirst(t);
|
||||
}
|
||||
} else if (ev.isEndElement()) {
|
||||
EndElement end = ev.asEndElement();
|
||||
if(removeType.contains(end.getName().getLocalPart() ) ){
|
||||
if(end.getName().getLocalPart().equals("comment") && isBlock){
|
||||
isBlock = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!end.getName().getLocalPart().equals("position") && !isBlock){
|
||||
if (isLabeled(trees)){
|
||||
trees.peekFirst().setLabel(currentLabel.toString());
|
||||
}
|
||||
trees.removeFirst();
|
||||
currentLabel = new StringBuilder();
|
||||
}
|
||||
} else if (ev.isCharacters() && !isBlock) {
|
||||
Characters chars = ev.asCharacters();
|
||||
if(chars.getData().trim().startsWith("\"This module provides access to some")){
|
||||
chars.getData();
|
||||
}
|
||||
if (!chars.isWhiteSpace() && isLabeled(trees))
|
||||
currentLabel.append(chars.getData().replace("\n",""));
|
||||
}
|
||||
}
|
||||
fixPos(context);
|
||||
return context; //TODO check way validate is removed
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isLabeled(ArrayDeque<ITree> trees) {
|
||||
return labeled.contains(context.getTypeLabel(trees.peekFirst().getType()));
|
||||
}
|
||||
|
||||
private void fixPos(TreeContext ctx) {
|
||||
for (ITree t : ctx.getRoot().postOrder()) {
|
||||
if (!t.isLeaf()) {
|
||||
//put the keywords as labels
|
||||
if(t.getType() == 34 || t.getType() ==37 || t.getType() ==38 || t.getType()==39 || t.getType() == 41 || t.getType()==45 || t.getType() ==55 || t.getType()==14){
|
||||
t.setLabel(NodeMap_new.map.get(t.getType())+" " +t.getLabel());
|
||||
}
|
||||
if (t.getPos() == ITree.NO_VALUE || t.getLength() == ITree.NO_VALUE || t.getType()==10) {
|
||||
|
||||
ITree firstChild = t.getChild(0);
|
||||
t.setPos(firstChild.getPos());
|
||||
|
||||
if (t.getChildren().size() == 1) {
|
||||
t.setLabel(t.getLabel() + firstChild.getLabel());
|
||||
}
|
||||
else {
|
||||
|
||||
ITree lastChild = t.getChild(t.getChildren().size() - 1);
|
||||
if(t.getPos() == -1){
|
||||
|
||||
if(t.getChild(0).getChildren().size() == 0) {
|
||||
t.getChild(0).setPos(t.getChild(1).getPos());
|
||||
t.setPos(lastChild.getPos());
|
||||
}
|
||||
|
||||
}else{
|
||||
t.getPos();
|
||||
}
|
||||
|
||||
if(t.getType() != 1){
|
||||
t.setLabel(t.getLabel() + t.getChildrenLabels());
|
||||
}
|
||||
}
|
||||
}else if (t.getLabel().equals("")){
|
||||
if(t.getType() == 60 || t.getType() == 56 || t.getType() == 47 || t.getType() == 8 || t.getType() == 43 || NodeMap_new.StatementMap.containsKey(t.getType())){
|
||||
String childrenLabels = t.getChildrenLabels();
|
||||
if(t.getType() == 53){
|
||||
t.setLabel("return "+childrenLabels);
|
||||
}else{
|
||||
if (!childrenLabels.equals("")){
|
||||
t.setLabel(childrenLabels);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
|
||||
if (t.getPos() == ITree.NO_VALUE ) {
|
||||
|
||||
if(t.getType() == 7){
|
||||
ITree parent = t.getParent();
|
||||
if(parent.getType() == 22){
|
||||
ITree child = parent.getParent().getChild(0);
|
||||
if (child.getType() == 22){
|
||||
ITree child1 = child.getChild(0);
|
||||
if(child1.getType() == 7){
|
||||
t.setLabel(child1.getLabel());
|
||||
t.setPos(child1.getPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int childPosition = t.getParent().getChildPosition(t);
|
||||
if(childPosition != 0){
|
||||
ITree child = t.getParent().getChild(childPosition - 1);
|
||||
t.setPos(child.getPos()+child.getLength()+1);
|
||||
|
||||
}else{
|
||||
if(t.getParent().getChildren().size() > 1){
|
||||
ITree child = t.getParent().getChild(childPosition + 1);
|
||||
t.setPos(child.getPos()-1);
|
||||
}else{
|
||||
|
||||
/*
|
||||
(34 "if" "" ((183 -1)) (
|
||||
(8 "condition" "i != j" ((186 6)) (
|
||||
(20 "expr" "i != j" ((187 6)) (
|
||||
(6 "name" "i" ((187 1)) ()
|
||||
(4 "operator" "!=" ((188 2)) ()
|
||||
(6 "name" "j" ((190 1)) ()))
|
||||
(36 "then" "" () (
|
||||
(9 "block" "" () ()))
|
||||
* */
|
||||
if (t.getPos() == ITree.NO_VALUE ){
|
||||
|
||||
ITree firstParent = t.getParent();
|
||||
if(firstParent.getType() == 36){//then
|
||||
ITree secondParent = firstParent.getParent();
|
||||
if(secondParent.getType() == 34){//
|
||||
if(secondParent.getChildren().size()>1){
|
||||
int childPosition1 = secondParent.getChildPosition(firstParent);
|
||||
if (childPosition1 !=0){
|
||||
ITree child = secondParent.getChild(childPosition1 - 1);
|
||||
firstParent.setPos(child.getPos()+child.getLength());
|
||||
// firstParent.setLength(0);
|
||||
firstParent.getChild(0).setPos(child.getPos()+child.getLength());
|
||||
// firstParent.getChild(0).setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(firstParent.getType() == 55){//sizeof
|
||||
ITree secondParent = firstParent.getParent();
|
||||
if(secondParent.getType() == 20){//
|
||||
if(secondParent.getChildren().size()>1){
|
||||
int childPosition1 = secondParent.getChildPosition(firstParent);
|
||||
if (childPosition1 ==0){
|
||||
ITree child = secondParent.getChild(childPosition1 + 1);
|
||||
firstParent.setPos(child.getPos()-child.getLength());
|
||||
// firstParent.setLength(0);
|
||||
firstParent.getChild(0).setPos(child.getPos()-child.getLength());
|
||||
// firstParent.getChild(0).setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ITree child = t.getParent().getChild(childPosition);
|
||||
if(child.getType() ==61){ //condition
|
||||
t.setPos(child.getPos()-1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
t.setLength(t.getLabel().length());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void setPos(ITree t, StartElement e) {
|
||||
if (e.getAttributeByName(LINE) != null) {
|
||||
int line = Integer.parseInt(e.getAttributeByName(LINE).getValue());
|
||||
int column = Integer.parseInt(e.getAttributeByName(COLUMN).getValue());
|
||||
t.setPos(lr.positionFor(line, column));
|
||||
}
|
||||
}
|
||||
|
||||
private void setLength(ITree t, StartElement e) {
|
||||
if (t.getPos() == -1)
|
||||
return;
|
||||
if (e.getAttributeByName(LINE) != null) {
|
||||
int line = Integer.parseInt(e.getAttributeByName(LINE).getValue());
|
||||
int column = Integer.parseInt(e.getAttributeByName(COLUMN).getValue());
|
||||
t.setLength(lr.positionFor(line, column) - t.getPos() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public String getXml(Reader r) throws IOException {
|
||||
//FIXME this is not efficient but I am not sure how to speed up things here.
|
||||
File f = File.createTempFile("gumtree", "");
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedReader br = new BufferedReader(r);
|
||||
String line = br.readLine();
|
||||
while (line != null) {
|
||||
w.append(line);
|
||||
w.append(System.lineSeparator());
|
||||
line = br.readLine();
|
||||
}
|
||||
w.close();
|
||||
br.close();
|
||||
ProcessBuilder b = new ProcessBuilder(getArguments(f.getAbsolutePath()));
|
||||
b.directory(f.getParentFile());
|
||||
try {
|
||||
Process p = b.start();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
// TODO Why do we need to read and bufferize everything, when we could/should only use generateFromStream
|
||||
line = null;
|
||||
while ((line = br.readLine()) != null)
|
||||
buf.append(line + "\n");
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) throw new RuntimeException();
|
||||
r.close();
|
||||
String xml = buf.toString();
|
||||
return xml;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getLanguage();
|
||||
|
||||
|
||||
|
||||
public void setSRCML_CMD(String SRCML_CMD) {
|
||||
this.SRCML_CMD = SRCML_CMD;
|
||||
}
|
||||
|
||||
public String getSRCML_CMD() {
|
||||
return SRCML_CMD;
|
||||
}
|
||||
|
||||
public String[] getCommandLine(String file) {
|
||||
return new String[]{SRCML_CMD, "-l", getLanguage(), "--position", file, "--tabs=1"};
|
||||
}
|
||||
|
||||
public String[] getArguments(String file) {
|
||||
return new String[]{getSRCML_CMD(), "-l", getLanguage(), "--position", file, "--tabs=1"};
|
||||
}
|
||||
public String readStandardOutput(Reader r) throws IOException {
|
||||
// TODO avoid recreating file if supplied reader is already a file
|
||||
File f = dumpReaderInTempFile(r);
|
||||
ProcessBuilder b = new ProcessBuilder(getCommandLine(f.getAbsolutePath()));
|
||||
b.directory(f.getParentFile());
|
||||
Process p = b.start();
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = br.readLine()) != null){
|
||||
|
||||
//// String e = "<else pos:line=\"[0-9]+\" pos:column=\"[0-9]+\">else\\W*<block type=\"pseudo\"><empty_stmt pos:line=\"[0-9]+\" pos:column=\"[0-9]+\">;<pos:position pos:line=\"[0-9]+\" pos:column=\"[0-9]+\"/></empty_stmt></block></else>";
|
||||
// String e = "<else pos:line=\\\\\\\"[0-9]+\\\\\\\" pos:column=\\\\\\\"[0-9]+\\\\\\\">else\\\\W*<block type=\\\\\\\"pseudo\\\\\\\"><empty_stmt pos:line=\\\\\\\"[0-9]+\\\\\\\" pos:column=\\\\\\\"[0-9]+\\\\\\\">;<pos:position pos:line=\\\\\\\"[0-9]+\\\\\\\" pos:column=\\\\\\\"[0-9]+\\\\\\\"/></empty_stmt></block></else>";
|
||||
// //<else pos:line="37" pos:column="4">else <block type="pseudo"><empty_stmt pos:line="37" pos:column="9">;<pos:position pos:line="37" pos:column="10"/></empty_stmt></block></else></if>
|
||||
// line = line.replaceAll(e,"");
|
||||
// String s = "<expr_stmt><pos:position pos:line=\"[0-9]+\" pos:column=\"[0-9]+\"/></expr_stmt>";
|
||||
// line = line.replaceAll(s,"");
|
||||
buf.append(line + System.lineSeparator());
|
||||
}
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0)
|
||||
throw new RuntimeException(buf.toString());
|
||||
r.close();
|
||||
p.destroy();
|
||||
String s = buf.toString();
|
||||
String p1 = "<expr_stmt><pos:position pos:line=\"[0-9]+\" pos:column=\"[0-9]+\"/></expr_stmt>";
|
||||
String p2 = "<else pos:line=\"[0-9]+\" pos:column=\"[0-9]+\">else\\W*<block type=\"pseudo\"><empty_stmt pos:line=\"[0-9]+\" pos:column=\"[0-9]+\">;<pos:position pos:line=\"[0-9]+\" pos:column=\"[0-9]+\"/></empty_stmt></block></else>";
|
||||
s = s.replaceAll(p2,"");
|
||||
s = s.replaceAll(p1,"");
|
||||
return s;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private File dumpReaderInTempFile(Reader r) throws IOException {
|
||||
File f = File.createTempFile("gumtree", "");
|
||||
try (
|
||||
Writer w = Files.newBufferedWriter(f.toPath(), Charset.forName("UTF-8"))
|
||||
) {
|
||||
char[] buf = new char[8192];
|
||||
while (true) {
|
||||
int length = r.read(buf);
|
||||
if (length < 0)
|
||||
break;
|
||||
w.write(buf, 0, length);
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.actions.ActionGenerator;
|
||||
import com.github.gumtreediff.actions.model.Action;
|
||||
import com.github.gumtreediff.matchers.Matcher;
|
||||
import com.github.gumtreediff.matchers.Matchers;
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.github.gumtreediff.tree.TreeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GumTreeCComparer {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(GumTreeCComparer.class);
|
||||
|
||||
public List<Action> compareCFilesWithGumTree(File prevFile, File revFile, String srcmlPath) {
|
||||
// Generate GumTree.
|
||||
ITree oldTree = null;
|
||||
ITree newTree = null;
|
||||
try {
|
||||
// oldTree = new GumTreeGenerator().generateITreeForCFileForCode(prevFile);
|
||||
// newTree = new GumTreeGenerator().generateITreeForCFileForCode(revFile);
|
||||
oldTree = new SrcmlCTreeGenerator(srcmlPath).generateFromFile(prevFile).getRoot();
|
||||
newTree = new SrcmlCTreeGenerator(srcmlPath).generateFromFile(revFile).getRoot();
|
||||
} catch (Exception e) {
|
||||
if (oldTree == null) {
|
||||
log.info("Null GumTree of Previous File: " + prevFile.getPath());
|
||||
throw new NullPointerException(prevFile.getPath());
|
||||
} else if (newTree == null) {
|
||||
log.info("Null GumTree of Revised File: " + revFile.getPath());
|
||||
throw new NullPointerException(revFile.getPath());
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
// if(checkTree(oldTree) || checkTree(newTree)){
|
||||
// log.debug("Not parsebable " + prevFile.getPath());
|
||||
// return null;
|
||||
// }
|
||||
|
||||
if (oldTree != null && newTree != null) {
|
||||
Matcher m = Matchers.getInstance().getMatcher(oldTree, newTree);
|
||||
m.match();
|
||||
ActionGenerator ag = new ActionGenerator(oldTree, newTree, m.getMappings());
|
||||
ag.generate();
|
||||
List<Action> actions = ag.getActions(); // change actions from bug to patch
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean checkTree(ITree tree) {
|
||||
List<String> errorList = new ArrayList<>(Arrays.asList("[(57@@[(22@@)])]","[(55@@[(6@@)])]","[(9@@[(53@@)][(19@@)])]","[(19@@)]","[(146@@)]","[(6@@)]","[(56@@[(57@@[(22@@)])])]"));
|
||||
List<ITree> iTrees = TreeUtils.breadthFirst(tree);
|
||||
// List<ITree> collect = iTrees.stream().filter(m -> m.getPos() == -1).collect(Collectors.toList());
|
||||
// for (ITree c : collect){
|
||||
// if (!errorList.contains(c.toStaticHashString())){
|
||||
// log.error(c.toStaticHashString());
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
boolean hasMissing = iTrees.stream().anyMatch(m -> m.getPos() == -1);
|
||||
// boolean hasMissing = collect.size() > 0;
|
||||
return hasMissing;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NodeMap_new {
|
||||
|
||||
|
||||
|
||||
public static Map<Integer, String> map;
|
||||
public static Map<Integer, String> StatementMap;
|
||||
public static Map<Integer, String> DeclarationMap;
|
||||
|
||||
|
||||
static {
|
||||
map = new HashMap<Integer, String>();
|
||||
map.put(1 , "unit");
|
||||
map.put(2 , "comment");
|
||||
map.put(3 , "literal");
|
||||
map.put(4 , "operator");
|
||||
map.put(5 , "modifier");
|
||||
map.put(6 , "name");
|
||||
map.put(7 , "type");
|
||||
map.put(8 , "condition");
|
||||
map.put(9 , "block");
|
||||
map.put(10 , "index");
|
||||
map.put(11 , "decltype");
|
||||
map.put(12 , "typename");
|
||||
map.put(13 , "atomic");
|
||||
map.put(14 , "assert");
|
||||
map.put(15 , "generic_selection");
|
||||
map.put(16 , "selector");
|
||||
map.put(17 , "association_list");
|
||||
map.put(18 , "association");
|
||||
map.put(19 , "expr_stmt");
|
||||
map.put(20 , "expr");
|
||||
map.put(21 , "decl_stmt");
|
||||
map.put(22 , "decl");
|
||||
map.put(23 , "init");
|
||||
map.put(24 , "range");
|
||||
map.put(25 , "break");
|
||||
map.put(26 , "continue");
|
||||
map.put(27 , "goto");
|
||||
map.put(28 , "label");
|
||||
map.put(29 , "typedef");
|
||||
map.put(30 , "asm");
|
||||
map.put(31 , "macro");
|
||||
map.put(32 , "enum");
|
||||
map.put(33 , "enum_decl");
|
||||
map.put(34 , "if");
|
||||
map.put(35 , "ternary");
|
||||
map.put(36 , "then");
|
||||
map.put(37 , "else");
|
||||
map.put(38 , "elseif");
|
||||
map.put(39 , "while");
|
||||
map.put(40 , "typeof");
|
||||
map.put(41 , "do");
|
||||
map.put(42 , "switch");
|
||||
map.put(43 , "case");
|
||||
map.put(44 , "default");
|
||||
map.put(45 , "for");
|
||||
map.put(46 , "foreach");
|
||||
map.put(47 , "control");
|
||||
map.put(48 , "incr");
|
||||
map.put(49 , "function");
|
||||
map.put(50 , "function_decl");
|
||||
map.put(51 , "lambda");
|
||||
map.put(52 , "specifier");
|
||||
map.put(53 , "return");
|
||||
map.put(54 , "call");
|
||||
map.put(55 , "sizeof");
|
||||
map.put(56 , "parameter_list");
|
||||
map.put(57 , "parameter");
|
||||
map.put(58 , "krparameter_list");
|
||||
map.put(59 , "krparameter");
|
||||
map.put(60 , "argument_list");
|
||||
map.put(61 , "argument");
|
||||
map.put(62 , "capture");
|
||||
map.put(63 , "struct");
|
||||
map.put(64 , "struct_decl");
|
||||
map.put(65 , "union");
|
||||
map.put(66 , "union_decl");
|
||||
map.put(67 , "class");
|
||||
map.put(68 , "class_decl");
|
||||
map.put(69 , "public");
|
||||
map.put(70 , "private");
|
||||
map.put(71 , "protected");
|
||||
map.put(72 , "signals");
|
||||
map.put(73 , "forever");
|
||||
map.put(74 , "emit");
|
||||
map.put(75 , "member_init_list");
|
||||
map.put(76 , "constructor");
|
||||
map.put(77 , "constructor_decl");
|
||||
map.put(78 , "destructor");
|
||||
map.put(79 , "destructor_decl");
|
||||
map.put(80 , "super");
|
||||
map.put(81 , "friend");
|
||||
map.put(82 , "extern");
|
||||
map.put(83 , "namespace");
|
||||
map.put(84 , "using");
|
||||
map.put(85 , "try");
|
||||
map.put(86 , "catch");
|
||||
map.put(87 , "finally");
|
||||
map.put(88 , "throw");
|
||||
map.put(89 , "throws");
|
||||
map.put(90 , "noexcept");
|
||||
map.put(91 , "template");
|
||||
map.put(92 , "directive");
|
||||
map.put(93 , "file");
|
||||
map.put(94 , "number");
|
||||
map.put(95 , "include");
|
||||
map.put(96 , "define");
|
||||
map.put(97 , "undef");
|
||||
map.put(98 , "line");
|
||||
map.put(99 , "ifdef");
|
||||
map.put(100 , "ifndef");
|
||||
map.put(101 , "elif");
|
||||
map.put(102 , "endif");
|
||||
map.put(103 , "pragma");
|
||||
map.put(104 , "error");
|
||||
map.put(105 , "warning");
|
||||
map.put(106 , "value");
|
||||
map.put(107 , "empty");
|
||||
map.put(108 , "region");
|
||||
map.put(109 , "endregion");
|
||||
map.put(110 , "import");
|
||||
map.put(111 , "marker");
|
||||
map.put(112 , "parse");
|
||||
map.put(113 , "mode");
|
||||
map.put(114 , "lock");
|
||||
map.put(115 , "fixed");
|
||||
map.put(116 , "checked");
|
||||
map.put(117 , "unchecked");
|
||||
map.put(118 , "unsafe");
|
||||
map.put(119 , "using_stmt");
|
||||
map.put(120 , "delegate");
|
||||
map.put(121 , "event");
|
||||
map.put(122 , "constraint");
|
||||
map.put(123 , "extends");
|
||||
map.put(124 , "implements");
|
||||
map.put(125 , "package");
|
||||
map.put(126 , "synchronized");
|
||||
map.put(127 , "interface");
|
||||
map.put(128 , "interface_decl");
|
||||
map.put(129 , "annotation_defn");
|
||||
map.put(130 , "static");
|
||||
map.put(131 , "attribute");
|
||||
map.put(132 , "target");
|
||||
map.put(133 , "linq");
|
||||
map.put(134 , "from");
|
||||
map.put(135 , "select");
|
||||
map.put(136 , "where");
|
||||
map.put(137 , "let");
|
||||
map.put(138 , "orderby");
|
||||
map.put(139 , "group");
|
||||
map.put(140 , "join");
|
||||
map.put(141 , "in");
|
||||
map.put(142 , "on");
|
||||
map.put(143 , "equals");
|
||||
map.put(144 , "by");
|
||||
map.put(145 , "into");
|
||||
map.put(146 , "escape");
|
||||
map.put(147 , "annotation");
|
||||
map.put(148 , "alignas");
|
||||
map.put(149 , "alignof");
|
||||
map.put(150 , "typeid");
|
||||
map.put(151 , "ref_qualifier");
|
||||
map.put(152 , "receiver");
|
||||
map.put(153 , "message");
|
||||
map.put(154 , "protocol_list");
|
||||
map.put(155 , "category");
|
||||
map.put(156 , "protocol");
|
||||
map.put(157 , "required");
|
||||
map.put(158 , "optional");
|
||||
map.put(159 , "property");
|
||||
map.put(160 , "attribute_list");
|
||||
map.put(161 , "synthesize");
|
||||
map.put(162 , "dynamic");
|
||||
map.put(163 , "encode");
|
||||
map.put(164 , "autoreleasepool");
|
||||
map.put(165 , "compatibility_alias");
|
||||
map.put(166 , "protocol_decl");
|
||||
map.put(167 , "cast");
|
||||
map.put(168 , "position");
|
||||
map.put(169 , "clause");
|
||||
map.put(170 , "empty_stmt");
|
||||
map.put(171 , "cpp:if");
|
||||
map.put(172 , "cpp:else");
|
||||
map.put(173 , "literal:string");
|
||||
map.put(174 , "literal:number");
|
||||
map.put(175 , "literal:char");
|
||||
map.put(176 , "literal:boolean");
|
||||
map.put(177 , "literal:complex");
|
||||
map.put(178 , "literal:null");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
DeclarationMap = new HashMap<Integer, String>();
|
||||
DeclarationMap.put(21 , "decl_stmt");
|
||||
DeclarationMap.put(22 , "decl");
|
||||
DeclarationMap.put(50 , "function_decl");
|
||||
DeclarationMap.put(49 , "function");
|
||||
DeclarationMap.put(5 , "modifier");
|
||||
DeclarationMap.put(29 , "typedef");
|
||||
DeclarationMap.put(23 , "init");
|
||||
DeclarationMap.put(24 , "range");
|
||||
DeclarationMap.put(64 , "struct_decl");
|
||||
DeclarationMap.put(63 , "struct");
|
||||
DeclarationMap.put(65 , "union");
|
||||
DeclarationMap.put(66 , "union_decl");
|
||||
DeclarationMap.put(32 , "enum");
|
||||
DeclarationMap.put(33 , "enum_decl");
|
||||
}
|
||||
static {
|
||||
StatementMap = new HashMap<Integer, String>();
|
||||
StatementMap.put(34 , "if");
|
||||
// StatementMap.put(8 , "condition");
|
||||
StatementMap.put(36 , "then");
|
||||
StatementMap.put(37 , "else");
|
||||
StatementMap.put(38 , "elseif");
|
||||
StatementMap.put(39 , "while");
|
||||
StatementMap.put(45 , "for");
|
||||
StatementMap.put(41 , "do");
|
||||
// StatementMap.put(25 , "break");
|
||||
// StatementMap.put(26 , "continue");
|
||||
StatementMap.put(53 , "return");
|
||||
StatementMap.put(42 , "switch");
|
||||
// StatementMap.put(43 , "case");
|
||||
// StatementMap.put(44 , "default");
|
||||
StatementMap.put(9 , "block");
|
||||
StatementMap.put(27 , "goto");
|
||||
StatementMap.put(28 , "label");
|
||||
|
||||
StatementMap.put(21 , "decl_stmt");
|
||||
// StatementMap.put(22 , "decl");
|
||||
StatementMap.put(50 , "function_decl");
|
||||
StatementMap.put(49 , "function");
|
||||
// StatementMap.put(5 , "modifier");
|
||||
StatementMap.put(29 , "typedef");
|
||||
// StatementMap.put(23 , "init");
|
||||
// StatementMap.put(24 , "range");
|
||||
StatementMap.put(64 , "struct_decl");
|
||||
StatementMap.put(63 , "struct");
|
||||
StatementMap.put(65 , "union");
|
||||
StatementMap.put(66 , "union_decl");
|
||||
StatementMap.put(32 , "enum");
|
||||
StatementMap.put(33 , "enum_decl");
|
||||
StatementMap.put(19 , "expr_stmt");
|
||||
StatementMap.put(82 , "extern");
|
||||
// StatementMap.put(31 , "macro");
|
||||
}
|
||||
// static {
|
||||
// StatementMap = new HashMap<Integer, String>();
|
||||
//
|
||||
// StatementMap.put(9 , "block");
|
||||
// StatementMap.put(14 , "assert");
|
||||
// StatementMap.put(15 , "generic_selection");
|
||||
// StatementMap.put(16 , "selector");
|
||||
// StatementMap.put(17 , "association_list");
|
||||
// StatementMap.put(18 , "association");
|
||||
// StatementMap.put(19 , "expr_stmt");
|
||||
//// StatementMap.put(20 , "expr");
|
||||
// StatementMap.put(21 , "decl_stmt");
|
||||
// StatementMap.put(22 , "decl");
|
||||
// StatementMap.put(23 , "init");
|
||||
// StatementMap.put(24 , "range");
|
||||
// StatementMap.put(25 , "break");
|
||||
// StatementMap.put(26 , "continue");
|
||||
// StatementMap.put(27 , "goto");
|
||||
// StatementMap.put(28 , "label");
|
||||
// StatementMap.put(29 , "typedef");
|
||||
// StatementMap.put(30 , "asm");
|
||||
// StatementMap.put(31 , "macro");
|
||||
// StatementMap.put(32 , "enum");
|
||||
// StatementMap.put(33 , "enum_decl");
|
||||
// StatementMap.put(34 , "if");
|
||||
// StatementMap.put(35 , "ternary");
|
||||
// StatementMap.put(36 , "then");
|
||||
// StatementMap.put(37 , "else");
|
||||
// StatementMap.put(38 , "elseif");
|
||||
// StatementMap.put(39 , "while");
|
||||
// StatementMap.put(40 , "typeof");
|
||||
// StatementMap.put(41 , "do");
|
||||
// StatementMap.put(42 , "switch");
|
||||
// StatementMap.put(43 , "case");
|
||||
// StatementMap.put(44 , "default");
|
||||
// StatementMap.put(45 , "for");
|
||||
// StatementMap.put(46 , "foreach");
|
||||
// StatementMap.put(47 , "control");
|
||||
//
|
||||
// StatementMap.put(49 , "function");
|
||||
// StatementMap.put(50 , "function_decl");
|
||||
// StatementMap.put(53 , "return");
|
||||
//
|
||||
// StatementMap.put(63 , "struct");
|
||||
// StatementMap.put(64 , "struct_decl");
|
||||
// StatementMap.put(65 , "union");
|
||||
// StatementMap.put(66 , "union_decl");
|
||||
// StatementMap.put(67 , "class");
|
||||
// StatementMap.put(68 , "class_decl");
|
||||
//
|
||||
// StatementMap.put(73 , "forever");
|
||||
// StatementMap.put(74 , "emit");
|
||||
// StatementMap.put(88 , "throw");
|
||||
//
|
||||
// StatementMap.put(95 , "include");
|
||||
// StatementMap.put(96 , "define");
|
||||
//
|
||||
// StatementMap.put(114 , "lock");
|
||||
// StatementMap.put(115 , "fixed");
|
||||
// StatementMap.put(116 , "checked");
|
||||
// StatementMap.put(117 , "unchecked");
|
||||
// StatementMap.put(118 , "unsafe");
|
||||
// StatementMap.put(119 , "using_stmt");
|
||||
//
|
||||
//// StatementMap.put(14 ,"assert");
|
||||
//// StatementMap.put(16 ,"expr_stmt");
|
||||
//// StatementMap.put(18 ,"decl_stmt");
|
||||
//// StatementMap.put(19 ,"decl");
|
||||
//// StatementMap.put(21 ,"break");
|
||||
//// StatementMap.put(22 ,"continue");
|
||||
//// StatementMap.put(23 ,"goto");
|
||||
//// StatementMap.put(24 ,"label");
|
||||
//// StatementMap.put(25 ,"typedef");
|
||||
////// StatementMap.put(26 ,"asm");
|
||||
//// StatementMap.put(27 ,"enum");
|
||||
//// StatementMap.put(30 ,"while");
|
||||
//// StatementMap.put(31 ,"lock");
|
||||
//// StatementMap.put(32 ,"fixed");
|
||||
//// StatementMap.put(33 ,"checked");
|
||||
//// StatementMap.put(34 ,"unchecked");
|
||||
//// StatementMap.put(35 ,"unsafe");
|
||||
//// StatementMap.put(36 ,"do");
|
||||
//// StatementMap.put(37 ,"switch");
|
||||
//// StatementMap.put(38 ,"case");
|
||||
//// StatementMap.put(39 ,"default");
|
||||
//// StatementMap.put(40 ,"for");
|
||||
//// StatementMap.put(41 ,"foreach");
|
||||
//// StatementMap.put(45 ,"function");
|
||||
//// StatementMap.put(46 ,"function_decl");
|
||||
//// StatementMap.put(49 ,"return");
|
||||
//// StatementMap.put(59 ,"struct");
|
||||
//// StatementMap.put(60 ,"struct_decl");
|
||||
//// StatementMap.put(61 ,"union");
|
||||
//// StatementMap.put(62 ,"union_decl");
|
||||
//// StatementMap.put(63 ,"class");
|
||||
//// StatementMap.put(64 ,"class_decl");
|
||||
//// StatementMap.put(70 ,"try");
|
||||
//// StatementMap.put(71 ,"catch");
|
||||
//// StatementMap.put(72 ,"finally");
|
||||
//// StatementMap.put(73 ,"throw");
|
||||
//// StatementMap.put(74 ,"throws");
|
||||
//// StatementMap.put(80 ,"include");
|
||||
//// StatementMap.put(81 ,"define");
|
||||
//// StatementMap.put(82 ,"undef");
|
||||
//// StatementMap.put(84 ,"if");
|
||||
//// StatementMap.put(85 ,"ifdef");
|
||||
//// StatementMap.put(86 ,"ifndef");
|
||||
//// StatementMap.put(87 ,"else");
|
||||
//// StatementMap.put(88 ,"elif");
|
||||
//// StatementMap.put(89 ,"endif");
|
||||
//// StatementMap.put(90 ,"then");
|
||||
//// StatementMap.put(91 ,"pragma");
|
||||
//// StatementMap.put(92 ,"error");
|
||||
//// StatementMap.put(93 ,"macro");
|
||||
//// StatementMap.put(96 ,"constructor_decl");
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
public static <T, E> List<T> getKeysByValue(Map<T, E> map, E value) {
|
||||
return map.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> Objects.equals(entry.getValue(), value))
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.gen.Register;
|
||||
import com.github.gumtreediff.gen.TreeGenerator;
|
||||
import com.github.gumtreediff.io.LineReader;
|
||||
import com.github.gumtreediff.io.TreeIoUtils;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
import com.github.gumtreediff.tree.TreeContext.MetadataSerializers;
|
||||
import com.github.gumtreediff.tree.TreeContext.MetadataUnserializers;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Register(id = "c-srcml", accept = "\\.[ch]$")
|
||||
public class SrcmlCTreeGenerator extends AbstractSrcmlTreeGenerator {
|
||||
|
||||
public SrcmlCTreeGenerator(String SRCML_CMD) {
|
||||
super.setSRCML_CMD(SRCML_CMD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "C";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected TreeContext generate(Reader r, int astParserType) throws IOException {
|
||||
LineReader lr;
|
||||
lr = new LineReader(r);
|
||||
String xml = getXml(lr);
|
||||
return getTreeContext(xml);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.gen.Register;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
@Register(id = "cpp-srcml", accept = "\\.(CC?|cpp|cc|hh?|hpp)$")
|
||||
public class SrcmlCppTreeGenerator extends AbstractSrcmlTreeGenerator {
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "C++";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TreeContext generate(Reader r, int astParserType) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.gen.Register;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
@Register(id = "cs-srcml", accept = "\\.cs$")
|
||||
public class SrcmlCsTreeGenerator extends AbstractSrcmlTreeGenerator {
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "C#";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TreeContext generate(Reader r, int astParserType) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.gen.Register;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
@Register(id = "java-srcml", accept = "\\.java$")
|
||||
public class SrcmlJavaTreeGenerator extends AbstractSrcmlTreeGenerator {
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "Java";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TreeContext generate(Reader r, int astParserType) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestSrcmlCGenerator {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
String input = "/Users/anilkoyuncu/Downloads/parmap-1.0-rc8/bytearray_stubs.c";
|
||||
ITree t = new SrcmlCTreeGenerator("/Users/anilkoyuncu/Downloads/srcML2/src2srcml").generateFromFile(input).getRoot();
|
||||
Assert.assertEquals(148, t.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestSrcmlCppGenerator {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
String input = "\n"
|
||||
+ "namespace R {\n"
|
||||
+ "template <typename T>\n"
|
||||
+ "static inline void print_array(T *__recv){\n"
|
||||
+ " int len = LEN(__recv);\n"
|
||||
+ " fprintf(stdout, \"%d:%d [\", TYPE(__recv), len);\n"
|
||||
+ " for(int i = 0; i < len; i++)\n"
|
||||
+ " print_item(__recv, i);\n"
|
||||
+ " fprintf(stdout, \" ]\\n\");\n"
|
||||
+ "}\n"
|
||||
+ "\n"
|
||||
+ "template <typename T>\n"
|
||||
+ "static inline void print_item(T *__recv, int idx){\n"
|
||||
+ " fprintf(stdout, \" %x\", GET(__recv, idx));\n"
|
||||
+ "}\n"
|
||||
+ "}";
|
||||
ITree t = new SrcmlCppTreeGenerator().generateFromString(input).getRoot();
|
||||
Assert.assertEquals(148, t.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestSrcmlCsGenerator {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
String input = "using System;\n"
|
||||
+ "public class HelloWorld\n"
|
||||
+ "{\n"
|
||||
+ "public static void Main()\n"
|
||||
+ "{\n"
|
||||
+ "Console.WriteLine(\"Hello world !\");\n"
|
||||
+ "Console.ReadLine();\n"
|
||||
+ "}\n"
|
||||
+ "}";
|
||||
ITree t = new SrcmlCsTreeGenerator().generateFromString(input).getRoot();
|
||||
Assert.assertEquals(34, t.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of GumTree.
|
||||
*
|
||||
* GumTree is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GumTree is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with GumTree. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2016 Jean-Rémy Falleri <jr.falleri@gmail.com>
|
||||
*/
|
||||
|
||||
package com.github.gumtreediff.gen.srcml;
|
||||
|
||||
import com.github.gumtreediff.io.TreeIoUtils;
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import com.github.gumtreediff.tree.TreeContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestSrcmlJavaGenerator {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
String input = "public class HelloWorld {\n"
|
||||
+ "public static void main(String[] args) {\n"
|
||||
+ "System.out.println(\"Hello, World\");\n"
|
||||
+ "}\n"
|
||||
+ "}";
|
||||
TreeContext ctx = new SrcmlJavaTreeGenerator().generateFromString(input);
|
||||
ITree t = ctx.getRoot();
|
||||
Assert.assertEquals(33, t.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user