Skip to content

Commit

Permalink
Add method block location..
Browse files Browse the repository at this point in the history
  • Loading branch information
Lynn-Dai committed Mar 5, 2024
1 parent c1abf5a commit 132f2f5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/main/java/TempOutput/DependsString.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ public DependsString getDependsString(String projectName, String projectPath, St
int src = -1;
try{
src = singleCollect.getFileIndex(getCurrentFileId(fromEntity));
}
catch (IndexOutOfBoundsException e){
} catch (IndexOutOfBoundsException e){
continue;
}
for (Tuple<Integer,Relation> toEntityObj : relationMap.get(fromEntity)) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/client/IdentifyEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.eclipse.jdt.core.dom.FileASTRequestor;
import util.*;
import visitor.EntityVisitor;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -68,7 +70,7 @@ public ArrayList<String> getAdditional_path() {
return additional_path;
}

public void run(){
public void run() throws IOException {

FileUtil current;
if(this.getAidl_path() != null){
Expand Down Expand Up @@ -137,7 +139,7 @@ public void acceptAST(String source, CompilationUnit ast) {
}
catch (NullPointerException e){
for(String filePath: whole_file_list){
parser.setSource(filePath.toCharArray());
parser.setSource(FileUtils.readFileToString(new File(filePath), "UTF-8").toCharArray());
pairs.add(new CompilationUnitPair(filePath, (CompilationUnit)parser.createAST(null)));
}
}
Expand All @@ -153,9 +155,6 @@ public void acceptAST(String source, CompilationUnit ast) {
System.out.println(PathUtil.getPathInProject(PathUtil.unifyPath(pair.source),this.project_name));
// System.out.println(PathUtil.unifyPath(pair.source));

// if("src/main/java/helloJDT/LauncherAccessibilityDelegate.java".equals(PathUtil.getPathInProject(PathUtil.unifyPath(pair.source),this.project_name))){
// pair.ast.accept(new EntityVisitor(PathUtil.getPathInProject(PathUtil.unifyPath(pair.source),this.project_name), pair.ast));
// }
Tuple<String, Integer> fileBin = null;
for (Tuple<String, Integer> currentBinPath: checkBin.keySet()){
if (checkBin.get(currentBinPath).contains(PathUtil.unifyPath(pair.source))){
Expand All @@ -175,6 +174,10 @@ public void acceptAST(String source, CompilationUnit ast) {
e.printStackTrace();
System.out.println("Null Pointer: "+ pair.source);
}
catch (Exception e){
e.printStackTrace();
System.out.println("Exception: "+ e.getMessage() + ":" + pair.source);
}
}

System.out.println("Entities identified successfully...");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/client/TemplateWork.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import util.Configure;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

Expand Down Expand Up @@ -54,7 +55,7 @@ public final void workflow(String[] args) {

}

public Map<Integer, ArrayList<Tuple<Integer, Relation>>> execute(EnreCommand app) {
public Map<Integer, ArrayList<Tuple<Integer, Relation>>> execute(EnreCommand app) throws IOException {
config("java", app.getSrc(), app.getProjectName());
IdentifyEntities entityTreeBuilder;
if (app.getAidl() != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/entity/adapter/EntityDTOAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ protected void write(JsonWriter out, MethodEntityDTO value) throws IOException {
writeRawType(out, value.getRawType());
writeHidden(out, value.getHidden());
writeICCMethodAttributeDTO(out, value.getIccMethodAttribute());
writeLocationDTO(out, value.getLocation(), "blockLoc");
}

protected void write(JsonWriter out, TypeParameterEntityDTO value) throws IOException {
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/visitor/ProcessEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public int processType(TypeDeclaration node, int parentId, CompilationUnit cu, T
// classEntity.setSuperClassName(superType.toString());
}
} catch (NullPointerException e){
// e.printStackTrace();
e.printStackTrace();
}

//interface, default id is -1
Expand All @@ -246,7 +246,7 @@ public int processType(TypeDeclaration node, int parentId, CompilationUnit cu, T
}
}
} catch (NullPointerException e){
// e.printStackTrace();
e.printStackTrace();
}

for(Object o : node.modifiers()) {
Expand Down Expand Up @@ -309,7 +309,6 @@ public int processEnum(EnumDeclaration node, int parentId, CompilationUnit cu, T
} else {
qualifiedName = singleCollect.getEntityById(parentId).getQualifiedName()+"."+enumName;
}

}

EnumEntity enumEntity = new EnumEntity(enumId, enumName, qualifiedName, parentId);
Expand All @@ -318,15 +317,15 @@ public int processEnum(EnumDeclaration node, int parentId, CompilationUnit cu, T
enumEntity.setBinNum(currentBin);

//interfaces
try {
try{
List superInterfaces = node.superInterfaceTypes();
for (Object temp : superInterfaces){
if (temp instanceof Type){
enumEntity.addInterface(((Type) temp).resolveBinding().getQualifiedName(), -1);
}
}
} catch (NullPointerException e){
// e.printStackTrace();
e.printStackTrace();
}

for(Object o : node.modifiers()) {
Expand Down Expand Up @@ -497,7 +496,9 @@ public int processMethod(MethodDeclaration node,int parentTypeId, CompilationUni
methodEntity.setParentId(parentTypeId);
methodEntity.setLocation(supplement_location(cu, node.getStartPosition(), node.getLength()));
//methodEntity.setCodeSnippet(node.toString());
methodEntity.setBlockLoc(supplement_location(cu, node.getBody().getStartPosition(), node.getBody().getLength()));
if (node.getBody() != null){
methodEntity.setBlockLoc(supplement_location(cu, node.getBody().getStartPosition(), node.getBody().getLength()));
}

if(node.isConstructor()){
methodEntity.setConstructor(true);
Expand Down Expand Up @@ -949,7 +950,7 @@ public boolean overridesMethod(MethodDeclaration methodDeclaration) {
}
return overridesMethod(methodDeclaration, typeBindings);
} catch (NullPointerException nullPointerException) {
// System.out.println("error in overridesMethod(MethodDeclaration methodDeclaration) while resolving typeBindings," + "[funcImpl name] : " + indices.getObject() + ", [location] : " + indices.getLocation().getLine() + "," + indices.getLocation().getRow());
System.out.println("error in overridesMethod(MethodDeclaration methodDeclaration) while resolving typeBindings," + "[funcImpl name] : " + methodDeclaration.getName());
}
return false;
}
Expand Down Expand Up @@ -986,7 +987,7 @@ private boolean overridesMethod(MethodDeclaration methodDeclaration, Set<ITypeBi
} else
return false;
} catch (NullPointerException nullPointerException) {
// System.out.println("error in (MethodDeclaration methodDeclaration, Set<ITypeBinding> typeBindings) while judging" + "[funcImpl name] : " + indices.getObject() + ", [location] : " + indices.getLocation().getLine() + "," + indices.getLocation().getRow());
System.out.println("error in (MethodDeclaration methodDeclaration, Set<ITypeBinding> typeBindings) while judging" + "[funcImpl name] : " + methodDeclaration.getName());
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/visitor/deper/ReflectBf.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ else if (reflect.getKind().equals(Configure.REFLECT_METHOD)){
if(reflectId != -1){
saveRelation(entity.getId(), reflectId, Configure.RELATION_REFLECT, Configure.RELATION_REFLECTED_BY, reflect.getLocation(), reflect.getModifyAccessible(), true);
}
} catch (ClassCastException e){
//Reflect not type
} catch (Exception e){
e.printStackTrace();
}

}
Expand All @@ -74,8 +74,8 @@ else if (reflect.getKind().equals(Configure.REFLECT_FIELD)){
if(reflectId != -1){
saveRelation(entity.getId(), reflectId, Configure.RELATION_REFLECT, Configure.RELATION_REFLECTED_BY, reflect.getLocation(), reflect.getModifyAccessible(), true);
}
} catch (ClassCastException e){
//Reflect not type
} catch (Exception e){
e.printStackTrace();
}

}
Expand Down

0 comments on commit 132f2f5

Please sign in to comment.