extract Inferer as IBindingResolver interface
This commit is contained in:
parent
3768f51d89
commit
18a7c2b851
|
@ -68,7 +68,7 @@ height="2.8465277777777778in"}
|
||||||
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
||||||
|
|
||||||
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
||||||
fileEntity, EntityRepo repo, Inferer inferer)。其说明如下:
|
fileEntity, EntityRepo repo, Inferer IBindingResolver)。其说明如下:
|
||||||
|
|
||||||
How to find the corresponding entity out of current scope
|
How to find the corresponding entity out of current scope
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ How to find the corresponding entity out of current scope
|
||||||
>
|
>
|
||||||
> **repo** - the whole entity repo, which could be used when necessary
|
> **repo** - the whole entity repo, which could be used when necessary
|
||||||
>
|
>
|
||||||
> **inferer** - the inferer object, which could be used when necessary
|
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ Relation更简单,仅仅包含依赖关系的类型以及指向的Entity。Rel
|
||||||
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
||||||
addRelation的职责很容易理解。
|
addRelation的职责很容易理解。
|
||||||
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
||||||
resolve和type inferer。
|
resolve和type IBindingResolver。
|
||||||
|
|
||||||
### 表达式Expression
|
### 表达式Expression
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ height="2.8465277777777778in"}
|
||||||
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
||||||
|
|
||||||
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
||||||
fileEntity, EntityRepo repo, Inferer inferer)。其说明如下:
|
fileEntity, EntityRepo repo, Inferer IBindingResolver)。其说明如下:
|
||||||
|
|
||||||
How to find the corresponding entity out of current scope
|
How to find the corresponding entity out of current scope
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ How to find the corresponding entity out of current scope
|
||||||
>
|
>
|
||||||
> **repo** - the whole entity repo, which could be used when necessary
|
> **repo** - the whole entity repo, which could be used when necessary
|
||||||
>
|
>
|
||||||
> **inferer** - the inferer object, which could be used when necessary
|
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ Relation更简单,仅仅包含依赖关系的类型以及指向的Entity。Rel
|
||||||
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
||||||
addRelation的职责很容易理解。
|
addRelation的职责很容易理解。
|
||||||
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
||||||
resolve和type inferer。
|
resolve和type IBindingResolver。
|
||||||
|
|
||||||
### 表达式Expression {#表达式expression}
|
### 表达式Expression {#表达式expression}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ For example, the implementation of FileParser is as follows:
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
Python3Parser parser = new Python3Parser(tokens);
|
Python3Parser parser = new Python3Parser(tokens);
|
||||||
Python3CodeListener bridge = new Python3CodeListener(fileFullPath,
|
Python3CodeListener bridge = new Python3CodeListener(fileFullPath,
|
||||||
entityRepo,inferer);
|
entityRepo,IBindingResolver);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
walker.walk(bridge, parser.file_input());
|
walker.walk(bridge, parser.file_input());
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,8 @@ Create a Lexer, create a Parse, create a Listener, and start traversing each of
|
||||||
First, create a context for the file:
|
First, create a context for the file:
|
||||||
|
|
||||||
public Python3CodeListener(String fileFullPath, EntityRepo entityRepo,
|
public Python3CodeListener(String fileFullPath, EntityRepo entityRepo,
|
||||||
Inferer inferer) {
|
Inferer IBindingResolver) {
|
||||||
this.context = new PythonHandlerContext(entityRepo,inferer);
|
this.context = new PythonHandlerContext(entityRepo,IBindingResolver);
|
||||||
this.expressionUsage = new ExpressionUsage();
|
this.expressionUsage = new ExpressionUsage();
|
||||||
context.startFile(fileFullPath);
|
context.startFile(fileFullPath);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ We already succefully make the depends knows that a function entity is created.
|
||||||
ImportStrategy is a strategy class named *Lang*ImportLookupStrategy that inherits the ImportLookupStrategy interface. Its role is to establish the relationship between different compilation units. Specifically, how to find a specific name in another compilation unit.
|
ImportStrategy is a strategy class named *Lang*ImportLookupStrategy that inherits the ImportLookupStrategy interface. Its role is to establish the relationship between different compilation units. Specifically, how to find a specific name in another compilation unit.
|
||||||
|
|
||||||
The core method of ImportStrategy is lookupImportedType(String name, FileEntity
|
The core method of ImportStrategy is lookupImportedType(String name, FileEntity
|
||||||
fileEntity, EntityRepo repo, Inferer inferer). Its description is as follows:
|
fileEntity, EntityRepo repo, Inferer IBindingResolver). Its description is as follows:
|
||||||
|
|
||||||
How to find the corresponding entity out of current scope
|
How to find the corresponding entity out of current scope
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ How to find the corresponding entity out of current scope
|
||||||
>
|
>
|
||||||
> **repo** - the whole entity repo, which could be used when necessary
|
> **repo** - the whole entity repo, which could be used when necessary
|
||||||
>
|
>
|
||||||
> **inferer** - the inferer object, which could be used when necessary
|
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ Relation is simpler, just contains the type of the dependency and the Entity poi
|
||||||
Entity provides several important methods. Includes addRelation and inferEntities.
|
Entity provides several important methods. Includes addRelation and inferEntities.
|
||||||
The responsibilities of addRelation are easy to understand.
|
The responsibilities of addRelation are easy to understand.
|
||||||
inferEntities is an important method that is responsible for completing all types of bindings starting from this entity.
|
inferEntities is an important method that is responsible for completing all types of bindings starting from this entity.
|
||||||
Resolve and type inferer.
|
Resolve and type IBindingResolver.
|
||||||
|
|
||||||
### Expression Expression
|
### Expression Expression
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ import depends.generator.FunctionDependencyGenerator;
|
||||||
import depends.generator.StructureDependencyGenerator;
|
import depends.generator.StructureDependencyGenerator;
|
||||||
import depends.matrix.core.DependencyMatrix;
|
import depends.matrix.core.DependencyMatrix;
|
||||||
import depends.matrix.transform.MatrixLevelReducer;
|
import depends.matrix.transform.MatrixLevelReducer;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.BindingResolver;
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
import depends.relations.RelationCounter;
|
import depends.relations.RelationCounter;
|
||||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
|
@ -104,14 +105,14 @@ public class Main {
|
||||||
System.err.println("Not support this language: " + lang);
|
System.err.println("Not support this language: " + lang);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Inferer inferer = new Inferer(langProcessor.getEntityRepo(), langProcessor.getImportLookupStrategy(), langProcessor.getBuiltInType()
|
IBindingResolver bindingResolver = new BindingResolver(langProcessor.getEntityRepo(), langProcessor.getImportLookupStrategy(), langProcessor.getBuiltInType()
|
||||||
, app.isOutputExternalDependencies(), app.isDuckTypingDeduce());
|
, app.isOutputExternalDependencies(), app.isDuckTypingDeduce());
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
//step1: build data
|
//step1: build data
|
||||||
EntityRepo entityRepo = langProcessor.buildDependencies(inputDir, includeDir, inferer);
|
EntityRepo entityRepo = langProcessor.buildDependencies(inputDir, includeDir, bindingResolver);
|
||||||
|
|
||||||
new RelationCounter(entityRepo,supportImplLink,langProcessor,inferer).computeRelations();
|
new RelationCounter(entityRepo,supportImplLink,langProcessor, bindingResolver).computeRelations();
|
||||||
System.out.println("Dependency done....");
|
System.out.println("Dependency done....");
|
||||||
|
|
||||||
//step2: generate dependencies matrix
|
//step2: generate dependencies matrix
|
||||||
|
|
|
@ -24,13 +24,9 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import depends.relations.IBindingResolver;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import java.util.*;
|
||||||
|
|
||||||
public class AliasEntity extends Entity {
|
public class AliasEntity extends Entity {
|
||||||
private Entity referToEntity = new EmptyTypeEntity();
|
private Entity referToEntity = new EmptyTypeEntity();
|
||||||
|
@ -45,9 +41,9 @@ public class AliasEntity extends Entity {
|
||||||
this.originName = originTypeName;
|
this.originName = originTypeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
if (!(referToEntity instanceof EmptyTypeEntity)) return;
|
if (!(referToEntity instanceof EmptyTypeEntity)) return;
|
||||||
Entity entity = inferer.resolveName(this, originName, true);
|
Entity entity = bindingResolver.resolveName(this, originName, true);
|
||||||
while(entity instanceof AliasEntity) {
|
while(entity instanceof AliasEntity) {
|
||||||
AliasEntity aliasEntity = (AliasEntity)entity;
|
AliasEntity aliasEntity = (AliasEntity)entity;
|
||||||
if (this.referPath.contains(aliasEntity)) {
|
if (this.referPath.contains(aliasEntity)) {
|
||||||
|
@ -55,7 +51,7 @@ public class AliasEntity extends Entity {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.referPath.add(aliasEntity);
|
this.referPath.add(aliasEntity);
|
||||||
entity = inferer.resolveName(aliasEntity, aliasEntity.originName,true);
|
entity = bindingResolver.resolveName(aliasEntity, aliasEntity.originName,true);
|
||||||
if (entity==null) break;
|
if (entity==null) break;
|
||||||
if (entity.equals(this)) {
|
if (entity.equals(this)) {
|
||||||
entity = null;
|
entity = null;
|
||||||
|
|
|
@ -24,15 +24,11 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import depends.relations.IBindingResolver;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
import depends.relations.Relation;
|
import depends.relations.Relation;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class CandidateTypes extends TypeEntity {
|
public class CandidateTypes extends TypeEntity {
|
||||||
private List<TypeEntity> candidateTypes;
|
private List<TypeEntity> candidateTypes;
|
||||||
|
|
||||||
|
@ -119,9 +115,9 @@ public class CandidateTypes extends TypeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
System.err.println("error: inferLocalLevelEntities should not been invoked");
|
System.err.println("error: inferLocalLevelEntities should not been invoked");
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -166,10 +162,9 @@ public class CandidateTypes extends TypeEntity {
|
||||||
super.addExpression(key, expression);
|
super.addExpression(key, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void resolveExpressions(IBindingResolver bindingResolver) {
|
||||||
public void resolveExpressions(Inferer inferer) {
|
|
||||||
System.err.println("error: resolveExpressions should not been invoked");
|
System.err.println("error: resolveExpressions should not been invoked");
|
||||||
super.resolveExpressions(inferer);
|
super.resolveExpressions(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,9 +206,9 @@ public class CandidateTypes extends TypeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<Entity> identiferToEntities(Inferer inferer, Collection<GenericName> identifiers) {
|
protected Collection<Entity> identiferToEntities(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||||
System.err.println("error: identiferToTypes should not been invoked");
|
System.err.println("error: identiferToTypes should not been invoked");
|
||||||
return super.identiferToEntities(inferer, identifiers);
|
return super.identiferToEntities(bindingResolver, identifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -289,9 +284,9 @@ public class CandidateTypes extends TypeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferEntities(Inferer inferer) {
|
public void inferEntities(IBindingResolver bindingResolver) {
|
||||||
System.err.println("error: inferEntities should not been invoked");
|
System.err.println("error: inferEntities should not been invoked");
|
||||||
super.inferEntities(inferer);
|
super.inferEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,7 +25,7 @@ SOFTWARE.
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import depends.relations.Relation;
|
import depends.relations.Relation;
|
||||||
import multilang.depends.util.file.TemporaryFile;
|
import multilang.depends.util.file.TemporaryFile;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -119,24 +119,24 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
||||||
* For all data in the class, infer their types. Should be override in
|
* For all data in the class, infer their types. Should be override in
|
||||||
* sub-classes
|
* sub-classes
|
||||||
*/
|
*/
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
for (VarEntity var : this.vars()) {
|
for (VarEntity var : this.vars()) {
|
||||||
if (var.getParent()!=this) {
|
if (var.getParent()!=this) {
|
||||||
var.inferLocalLevelEntities(inferer);
|
var.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (FunctionEntity func : this.getFunctions()) {
|
for (FunctionEntity func : this.getFunctions()) {
|
||||||
if (func.getParent()!=this) {
|
if (func.getParent()!=this) {
|
||||||
func.inferLocalLevelEntities(inferer);
|
func.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inferer.isEagerExpressionResolve()) {
|
if (bindingResolver.isEagerExpressionResolve()) {
|
||||||
reloadExpression(inferer.getRepo());
|
reloadExpression(bindingResolver.getRepo());
|
||||||
resolveExpressions(inferer);
|
resolveExpressions(bindingResolver);
|
||||||
cacheExpressions();
|
cacheExpressions();
|
||||||
}
|
}
|
||||||
resolvedMixins = identiferToContainerEntity(inferer, getMixins());
|
resolvedMixins = identiferToContainerEntity(bindingResolver, getMixins());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<GenericName> getMixins() {
|
private Collection<GenericName> getMixins() {
|
||||||
|
@ -145,11 +145,11 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
||||||
return mixins;
|
return mixins;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<ContainerEntity> identiferToContainerEntity(Inferer inferer, Collection<GenericName> identifiers) {
|
private Collection<ContainerEntity> identiferToContainerEntity(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||||
if (identifiers.size()==0) return null;
|
if (identifiers.size()==0) return null;
|
||||||
ArrayList<ContainerEntity> r = new ArrayList<>();
|
ArrayList<ContainerEntity> r = new ArrayList<>();
|
||||||
for (GenericName identifier : identifiers) {
|
for (GenericName identifier : identifiers) {
|
||||||
Entity entity = inferer.resolveName(this, identifier, true);
|
Entity entity = bindingResolver.resolveName(this, identifier, true);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -162,10 +162,9 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
||||||
/**
|
/**
|
||||||
* Resolve all expression's type
|
* Resolve all expression's type
|
||||||
*
|
*
|
||||||
* @param inferer
|
* @param bindingResolver
|
||||||
*/
|
*/
|
||||||
public void resolveExpressions(Inferer inferer) {
|
public void resolveExpressions(IBindingResolver bindingResolver) {
|
||||||
|
|
||||||
if (this instanceof FunctionEntity) {
|
if (this instanceof FunctionEntity) {
|
||||||
((FunctionEntity)this).linkReturnToLastExpression();
|
((FunctionEntity)this).linkReturnToLastExpression();
|
||||||
}
|
}
|
||||||
|
@ -187,20 +186,13 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
||||||
// 2. if expression's rawType existed, directly infer type by rawType
|
// 2. if expression's rawType existed, directly infer type by rawType
|
||||||
// if expression's rawType does not existed, infer type based on identifiers
|
// if expression's rawType does not existed, infer type based on identifiers
|
||||||
if (expression.getRawType() != null) {
|
if (expression.getRawType() != null) {
|
||||||
expression.setType(inferer.inferTypeFromName(this, expression.getRawType()), null, inferer);
|
expression.setType(bindingResolver.inferTypeFromName(this, expression.getRawType()), null, bindingResolver);
|
||||||
if (expression.getType() != null) {
|
if (expression.getType() != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (expression.getIdentifier() != null) {
|
if (expression.getIdentifier() != null) {
|
||||||
|
Entity entity = bindingResolver.resolveName(this, expression.getIdentifier(), true);
|
||||||
// if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py") &&
|
|
||||||
// expression.getIdentifier().contains("config")) {
|
|
||||||
// System.out.print("dd");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
Entity entity = inferer.resolveName(this, expression.getIdentifier(), true);
|
|
||||||
String composedName = expression.getIdentifier().toString();
|
String composedName = expression.getIdentifier().toString();
|
||||||
Expression theExpr = expression;
|
Expression theExpr = expression;
|
||||||
if (entity==null) {
|
if (entity==null) {
|
||||||
|
@ -208,27 +200,27 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
||||||
theExpr = theExpr.getParent();
|
theExpr = theExpr.getParent();
|
||||||
if (theExpr.getIdentifier()==null) break;
|
if (theExpr.getIdentifier()==null) break;
|
||||||
composedName = composedName + "." + theExpr.getIdentifier().toString();
|
composedName = composedName + "." + theExpr.getIdentifier().toString();
|
||||||
entity = inferer.resolveName(this, GenericName.build(composedName), true);
|
entity = bindingResolver.resolveName(this, GenericName.build(composedName), true);
|
||||||
if (entity!=null)
|
if (entity!=null)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
expression.setType(entity.getType(), entity, inferer);
|
expression.setType(entity.getType(), entity, bindingResolver);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (expression.isCall()) {
|
if (expression.isCall()) {
|
||||||
List<Entity> funcs = this.lookupFunctionInVisibleScope(expression.getIdentifier());
|
List<Entity> funcs = this.lookupFunctionInVisibleScope(expression.getIdentifier());
|
||||||
if (funcs != null) {
|
if (funcs != null) {
|
||||||
for (Entity func:funcs) {
|
for (Entity func:funcs) {
|
||||||
expression.setType(func.getType(), func, inferer);
|
expression.setType(func.getType(), func, bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Entity varEntity = this.lookupVarInVisibleScope(expression.getIdentifier());
|
Entity varEntity = this.lookupVarInVisibleScope(expression.getIdentifier());
|
||||||
if (varEntity != null) {
|
if (varEntity != null) {
|
||||||
expression.setType(varEntity.getType(), varEntity, inferer);
|
expression.setType(varEntity.getType(), varEntity, bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -67,33 +67,33 @@ public abstract class DecoratedEntity extends Entity{
|
||||||
* For all data in the class, infer their types.
|
* For all data in the class, infer their types.
|
||||||
* Should be override in sub-classes
|
* Should be override in sub-classes
|
||||||
*/
|
*/
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
Collection<Entity> typeParameterEntities = typeParametersToEntities(inferer);
|
Collection<Entity> typeParameterEntities = typeParametersToEntities(bindingResolver);
|
||||||
appendTypeParameters(typeParameterEntities);
|
appendTypeParameters(typeParameterEntities);
|
||||||
// if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py")
|
// if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py")
|
||||||
// ) {
|
// ) {
|
||||||
// System.out.print("dd");
|
// System.out.print("dd");
|
||||||
// }
|
// }
|
||||||
resolvedAnnotations = identiferToEntities(inferer, annotations);
|
resolvedAnnotations = identiferToEntities(bindingResolver, annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Collection<Entity> typeParametersToEntities(Inferer inferer) {
|
private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver) {
|
||||||
ArrayList<Entity> r = new ArrayList<>();
|
ArrayList<Entity> r = new ArrayList<>();
|
||||||
for (GenericName typeParameter:this.getRawName().getArguments()) {
|
for (GenericName typeParameter:this.getRawName().getArguments()) {
|
||||||
toEntityList(inferer, r,typeParameter);
|
toEntityList(bindingResolver, r,typeParameter);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void toEntityList(Inferer inferer, ArrayList<Entity> r, GenericName typeParameter) {
|
protected void toEntityList(IBindingResolver bindingResolver, ArrayList<Entity> r, GenericName typeParameter) {
|
||||||
Entity entity = resolveEntity(inferer, typeParameter);
|
Entity entity = resolveEntity(bindingResolver, typeParameter);
|
||||||
if (entity != null)
|
if (entity != null)
|
||||||
r.add(entity);
|
r.add(entity);
|
||||||
for (GenericName arg: typeParameter.getArguments()) {
|
for (GenericName arg: typeParameter.getArguments()) {
|
||||||
toEntityList(inferer,r,arg);
|
toEntityList(bindingResolver,r,arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,24 +120,24 @@ public abstract class DecoratedEntity extends Entity{
|
||||||
/**
|
/**
|
||||||
* A common utility function used to transfer the identifiers
|
* A common utility function used to transfer the identifiers
|
||||||
* to types.
|
* to types.
|
||||||
* @param inferer - the inferer object
|
* @param bindingResolver - the inferer object
|
||||||
* @param identifiers - the identifiers will be translated
|
* @param identifiers - the identifiers will be translated
|
||||||
* @return The translated Types
|
* @return The translated Types
|
||||||
*/
|
*/
|
||||||
protected Collection<Entity> identiferToEntities(Inferer inferer, Collection<GenericName> identifiers) {
|
protected Collection<Entity> identiferToEntities(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||||
if (identifiers==null) return null;
|
if (identifiers==null) return null;
|
||||||
if (identifiers.size()==0) return null;
|
if (identifiers.size()==0) return null;
|
||||||
ArrayList<Entity> r = new ArrayList<>();
|
ArrayList<Entity> r = new ArrayList<>();
|
||||||
for (GenericName name : identifiers) {
|
for (GenericName name : identifiers) {
|
||||||
Entity entity = resolveEntity(inferer, name);
|
Entity entity = resolveEntity(bindingResolver, name);
|
||||||
if (entity != null)
|
if (entity != null)
|
||||||
r.add(entity);
|
r.add(entity);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entity resolveEntity(Inferer inferer, GenericName name) {
|
private Entity resolveEntity(IBindingResolver bindingResolver, GenericName name) {
|
||||||
Entity entity = inferer.resolveName(this, name, true);
|
Entity entity = bindingResolver.resolveName(this, name, true);
|
||||||
if (entity==null) {
|
if (entity==null) {
|
||||||
if (((ContainerEntity)getParent()).isGenericTypeParameter(name)) {
|
if (((ContainerEntity)getParent()).isGenericTypeParameter(name)) {
|
||||||
entity = TypeEntity.genericParameterType;
|
entity = TypeEntity.genericParameterType;
|
||||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import depends.relations.Relation;
|
import depends.relations.Relation;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -177,13 +177,13 @@ public abstract class Entity {
|
||||||
/**
|
/**
|
||||||
* Invoke inferer to resolve the entity type etc.
|
* Invoke inferer to resolve the entity type etc.
|
||||||
* */
|
* */
|
||||||
public void inferEntities(Inferer inferer) {
|
public void inferEntities(IBindingResolver bindingResolver) {
|
||||||
inferLocalLevelEntities(inferer);
|
inferLocalLevelEntities(bindingResolver);
|
||||||
for (Entity child:this.getChildren()) {
|
for (Entity child:this.getChildren()) {
|
||||||
child.inferEntities(inferer);
|
child.inferEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public abstract void inferLocalLevelEntities(Inferer inferer);
|
public abstract void inferLocalLevelEntities(IBindingResolver bindingResolver);
|
||||||
|
|
||||||
public TypeEntity getType() {
|
public TypeEntity getType() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -25,7 +25,7 @@ SOFTWARE.
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -121,9 +121,9 @@ public class Expression implements Serializable{
|
||||||
* Set type of the expression
|
* Set type of the expression
|
||||||
* @param type
|
* @param type
|
||||||
* @param referredEntity
|
* @param referredEntity
|
||||||
* @param inferer
|
* @param bindingResolver
|
||||||
*/
|
*/
|
||||||
public void setType(TypeEntity type, Entity referredEntity, Inferer inferer) {
|
public void setType(TypeEntity type, Entity referredEntity, IBindingResolver bindingResolver) {
|
||||||
if (this.getReferredEntity()==null && referredEntity!=null) {
|
if (this.getReferredEntity()==null && referredEntity!=null) {
|
||||||
this.setReferredEntity(referredEntity);
|
this.setReferredEntity(referredEntity);
|
||||||
}
|
}
|
||||||
|
@ -147,16 +147,15 @@ public class Expression implements Serializable{
|
||||||
this.setReferredEntity(this.type);
|
this.setReferredEntity(this.type);
|
||||||
|
|
||||||
if (changedType)
|
if (changedType)
|
||||||
deduceTheParentType(inferer);
|
deduceTheParentType(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deduce type of parent based on child's type
|
* deduce type of parent based on child's type
|
||||||
* @param expressionList
|
* @param bindingResolver
|
||||||
* @param inferer
|
|
||||||
*/
|
*/
|
||||||
private void deduceTheParentType(Inferer inferer) {
|
private void deduceTheParentType(IBindingResolver bindingResolver) {
|
||||||
if (this.type==null) return;
|
if (this.type==null) return;
|
||||||
if (this.parent==null) return;
|
if (this.parent==null) return;
|
||||||
Expression parent = this.parent;
|
Expression parent = this.parent;
|
||||||
|
@ -167,13 +166,13 @@ public class Expression implements Serializable{
|
||||||
|
|
||||||
//if child is a built-in/external type, then parent must also a built-in/external type
|
//if child is a built-in/external type, then parent must also a built-in/external type
|
||||||
if (this.type.equals(TypeEntity.buildInType)) {
|
if (this.type.equals(TypeEntity.buildInType)) {
|
||||||
parent.setType(TypeEntity.buildInType,TypeEntity.buildInType,inferer);
|
parent.setType(TypeEntity.buildInType,TypeEntity.buildInType, bindingResolver);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if it is a logic expression, the return type/type is boolean. */
|
/* if it is a logic expression, the return type/type is boolean. */
|
||||||
if (parent.isLogic) {
|
if (parent.isLogic) {
|
||||||
parent.setType(TypeEntity.buildInType,null,inferer);
|
parent.setType(TypeEntity.buildInType,null, bindingResolver);
|
||||||
}
|
}
|
||||||
/* if it is a.b, and we already get a's type, b's type could be identified easily */
|
/* if it is a.b, and we already get a's type, b's type could be identified easily */
|
||||||
else if (parent.isDot) {
|
else if (parent.isDot) {
|
||||||
|
@ -184,15 +183,15 @@ public class Expression implements Serializable{
|
||||||
if (funcs.size()>0) {
|
if (funcs.size()>0) {
|
||||||
Entity func = funcs.get(0);
|
Entity func = funcs.get(0);
|
||||||
if (funcs.size()>1) {
|
if (funcs.size()>1) {
|
||||||
MultiDeclareEntities m = new MultiDeclareEntities(func, inferer.getRepo().generateId());
|
MultiDeclareEntities m = new MultiDeclareEntities(func, bindingResolver.getRepo().generateId());
|
||||||
inferer.getRepo().add(m);
|
bindingResolver.getRepo().add(m);
|
||||||
for (int i=1;i<funcs.size();i++) {
|
for (int i=1;i<funcs.size();i++) {
|
||||||
m.add(funcs.get(i));
|
m.add(funcs.get(i));
|
||||||
}
|
}
|
||||||
parent.setType(func.getType(), m,inferer);
|
parent.setType(func.getType(), m, bindingResolver);
|
||||||
parent.setReferredEntity(m);
|
parent.setReferredEntity(m);
|
||||||
}else {
|
}else {
|
||||||
parent.setType(func.getType(), func,inferer);
|
parent.setType(func.getType(), func, bindingResolver);
|
||||||
parent.setReferredEntity(func);
|
parent.setReferredEntity(func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,35 +199,35 @@ public class Expression implements Serializable{
|
||||||
}else {
|
}else {
|
||||||
Entity var = this.getType().lookupVarInVisibleScope(parent.identifier);
|
Entity var = this.getType().lookupVarInVisibleScope(parent.identifier);
|
||||||
if (var!=null) {
|
if (var!=null) {
|
||||||
parent.setType(var.getType(),var, inferer);
|
parent.setType(var.getType(),var, bindingResolver);
|
||||||
parent.setReferredEntity(var);
|
parent.setReferredEntity(var);
|
||||||
}else {
|
}else {
|
||||||
List<Entity> funcs = this.getType().lookupFunctionInVisibleScope(parent.identifier);
|
List<Entity> funcs = this.getType().lookupFunctionInVisibleScope(parent.identifier);
|
||||||
if (funcs!=null) {
|
if (funcs!=null) {
|
||||||
Entity func = funcs.get(0);
|
Entity func = funcs.get(0);
|
||||||
if (funcs.size()>1) {
|
if (funcs.size()>1) {
|
||||||
MultiDeclareEntities m = new MultiDeclareEntities(func, inferer.getRepo().generateId());
|
MultiDeclareEntities m = new MultiDeclareEntities(func, bindingResolver.getRepo().generateId());
|
||||||
inferer.getRepo().add(m);
|
bindingResolver.getRepo().add(m);
|
||||||
|
|
||||||
for (int i=1;i<funcs.size();i++) {
|
for (int i=1;i<funcs.size();i++) {
|
||||||
m.add(funcs.get(i));
|
m.add(funcs.get(i));
|
||||||
}
|
}
|
||||||
parent.setType(func.getType(), m,inferer);
|
parent.setType(func.getType(), m, bindingResolver);
|
||||||
parent.setReferredEntity(m);
|
parent.setReferredEntity(m);
|
||||||
}else {
|
}else {
|
||||||
parent.setType(func.getType(), func,inferer);
|
parent.setType(func.getType(), func, bindingResolver);
|
||||||
parent.setReferredEntity(func);
|
parent.setReferredEntity(func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parent.getType()==null) {
|
if (parent.getType()==null) {
|
||||||
parent.setType(inferer.inferTypeFromName(this.getType(), parent.identifier),null,inferer);
|
parent.setType(bindingResolver.inferTypeFromName(this.getType(), parent.identifier),null, bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if other situation, simple make the parent and child type same */
|
/* if other situation, simple make the parent and child type same */
|
||||||
else {
|
else {
|
||||||
parent.setType(type, null, inferer);
|
parent.setType(type, null, bindingResolver);
|
||||||
}
|
}
|
||||||
if (parent.getReferredEntity()==null)
|
if (parent.getReferredEntity()==null)
|
||||||
parent.setReferredEntity(parent.type);
|
parent.setReferredEntity(parent.type);
|
||||||
|
|
|
@ -24,14 +24,10 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import depends.importtypes.Import;
|
import depends.importtypes.Import;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class FileEntity extends TypeEntity {
|
public class FileEntity extends TypeEntity {
|
||||||
private List<Import> importedNames = new ArrayList<>();
|
private List<Import> importedNames = new ArrayList<>();
|
||||||
|
@ -95,12 +91,12 @@ public class FileEntity extends TypeEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
this.importedRelationEntities = inferer.getImportedRelationEntities(importedNames);
|
this.importedRelationEntities = bindingResolver.getImportedRelationEntities(importedNames);
|
||||||
this.importedTypes = inferer.getImportedTypes(importedNames,this);
|
this.importedTypes = bindingResolver.getImportedTypes(importedNames,this);
|
||||||
this.importedFiles = inferer.getImportedFiles(importedNames);
|
this.importedFiles = bindingResolver.getImportedFiles(importedNames);
|
||||||
|
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInProjectScope() {
|
public boolean isInProjectScope() {
|
||||||
|
|
|
@ -24,12 +24,12 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public class FunctionEntity extends ContainerEntity{
|
public class FunctionEntity extends ContainerEntity{
|
||||||
private List<GenericName> returnTypeIdentifiers = new ArrayList<>();
|
private List<GenericName> returnTypeIdentifiers = new ArrayList<>();
|
||||||
Collection<VarEntity> parameters;
|
Collection<VarEntity> parameters;
|
||||||
|
@ -79,28 +79,28 @@ public class FunctionEntity extends ContainerEntity{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
for (VarEntity param:parameters) {
|
for (VarEntity param:parameters) {
|
||||||
param.fillCandidateTypes(inferer);
|
param.fillCandidateTypes(bindingResolver);
|
||||||
param.inferLocalLevelEntities(inferer);
|
param.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
if (returnTypes.size()<returnTypeIdentifiers.size()) {
|
if (returnTypes.size()<returnTypeIdentifiers.size()) {
|
||||||
returnTypes = identiferToEntities(inferer,this.returnTypeIdentifiers);
|
returnTypes = identiferToEntities(bindingResolver,this.returnTypeIdentifiers);
|
||||||
for ( GenericName returnTypeName: returnTypeIdentifiers) {
|
for ( GenericName returnTypeName: returnTypeIdentifiers) {
|
||||||
Collection<Entity> typeEntities = typeParametersToEntities(inferer, returnTypeName);
|
Collection<Entity> typeEntities = typeParametersToEntities(bindingResolver, returnTypeName);
|
||||||
this.appendTypeParameters(typeEntities);
|
this.appendTypeParameters(typeEntities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (throwTypes.size()<throwTypesIdentifiers.size())
|
if (throwTypes.size()<throwTypesIdentifiers.size())
|
||||||
throwTypes = identiferToEntities(inferer,this.throwTypesIdentifiers);
|
throwTypes = identiferToEntities(bindingResolver,this.throwTypesIdentifiers);
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Collection<Entity> typeParametersToEntities(Inferer inferer,GenericName name) {
|
private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver, GenericName name) {
|
||||||
ArrayList<Entity> r = new ArrayList<>();
|
ArrayList<Entity> r = new ArrayList<>();
|
||||||
for (GenericName typeParameter:name.getArguments()) {
|
for (GenericName typeParameter:name.getArguments()) {
|
||||||
toEntityList(inferer, r,typeParameter);
|
toEntityList(bindingResolver, r,typeParameter);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class FunctionEntityImpl extends FunctionEntity {
|
public class FunctionEntityImpl extends FunctionEntity {
|
||||||
Entity implementedFunction = null;
|
Entity implementedFunction = null;
|
||||||
|
@ -11,9 +11,9 @@ public class FunctionEntityImpl extends FunctionEntity {
|
||||||
super(simpleName,parent,id,returnType);
|
super(simpleName,parent,id,returnType);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
implementedFunction = inferer.lookupTypeInImported((FileEntity)(getAncestorOfType(FileEntity.class)),this.getQualifiedName());
|
implementedFunction = bindingResolver.lookupTypeInImported((FileEntity)(getAncestorOfType(FileEntity.class)),this.getQualifiedName());
|
||||||
}
|
}
|
||||||
public Entity getImplemented() {
|
public Entity getImplemented() {
|
||||||
return implementedFunction;
|
return implementedFunction;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultiDeclareEntity is a special container, which is used as a wrapper
|
* MultiDeclareEntity is a special container, which is used as a wrapper
|
||||||
|
@ -47,9 +47,9 @@ public class MultiDeclareEntities extends ContainerEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
for (Entity entity:entities) {
|
for (Entity entity:entities) {
|
||||||
entity.inferLocalLevelEntities(inferer);
|
entity.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -46,9 +46,9 @@ public class TypeEntity extends ContainerEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
inheritedTypes = new ArrayList<>();
|
inheritedTypes = new ArrayList<>();
|
||||||
Collection<Entity> r = identiferToEntities(inferer, this.inhertedTypeIdentifiers);
|
Collection<Entity> r = identiferToEntities(bindingResolver, this.inhertedTypeIdentifiers);
|
||||||
if (r!=null) {
|
if (r!=null) {
|
||||||
r.forEach(item -> {
|
r.forEach(item -> {
|
||||||
Entity typeItem = getTypeEntity(item);
|
Entity typeItem = getTypeEntity(item);
|
||||||
|
@ -62,7 +62,7 @@ public class TypeEntity extends ContainerEntity {
|
||||||
inheritedTypes.remove(this);
|
inheritedTypes.remove(this);
|
||||||
|
|
||||||
implementedTypes = new ArrayList<>();
|
implementedTypes = new ArrayList<>();
|
||||||
r = identiferToEntities(inferer, this.implementedIdentifiers);
|
r = identiferToEntities(bindingResolver, this.implementedIdentifiers);
|
||||||
if (r!=null) {
|
if (r!=null) {
|
||||||
r.forEach(item -> {
|
r.forEach(item -> {
|
||||||
Entity typeItem = getTypeEntity(item);
|
Entity typeItem = getTypeEntity(item);
|
||||||
|
@ -76,7 +76,7 @@ public class TypeEntity extends ContainerEntity {
|
||||||
implementedTypes.remove(this);
|
implementedTypes.remove(this);
|
||||||
if (inheritedTypes.size() > 0)
|
if (inheritedTypes.size() > 0)
|
||||||
inheritedType = inheritedTypes.iterator().next();
|
inheritedType = inheritedTypes.iterator().next();
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entity getTypeEntity(Entity item) {
|
private Entity getTypeEntity(Entity item) {
|
||||||
|
|
|
@ -24,11 +24,11 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.entity;
|
package depends.entity;
|
||||||
|
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public class VarEntity extends ContainerEntity {
|
public class VarEntity extends ContainerEntity {
|
||||||
private GenericName rawType;
|
private GenericName rawType;
|
||||||
private TypeEntity type;
|
private TypeEntity type;
|
||||||
|
@ -59,9 +59,9 @@ public class VarEntity extends ContainerEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inferLocalLevelEntities(Inferer inferer) {
|
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||||
super.inferLocalLevelEntities(inferer);
|
super.inferLocalLevelEntities(bindingResolver);
|
||||||
Entity entity = inferer.resolveName(this, rawType, true);
|
Entity entity = bindingResolver.resolveName(this, rawType, true);
|
||||||
if (entity!=null) {
|
if (entity!=null) {
|
||||||
this.setActualReferTo(entity);
|
this.setActualReferTo(entity);
|
||||||
type = entity.getType();
|
type = entity.getType();
|
||||||
|
@ -72,7 +72,7 @@ public class VarEntity extends ContainerEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type==null) {
|
if (type==null) {
|
||||||
fillCandidateTypes(inferer);
|
fillCandidateTypes(bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,16 +90,16 @@ public class VarEntity extends ContainerEntity {
|
||||||
this.functionCalls.add(new FunctionCall(fname));
|
this.functionCalls.add(new FunctionCall(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillCandidateTypes(Inferer inferer) {
|
public void fillCandidateTypes(IBindingResolver bindingResolver) {
|
||||||
if (!inferer.isEagerExpressionResolve()) return;
|
if (!bindingResolver.isEagerExpressionResolve()) return;
|
||||||
if (type!=null && !(type instanceof CandidateTypes)) return ; //it is a strong type lang, do not need deduce candidate types
|
if (type!=null && !(type instanceof CandidateTypes)) return ; //it is a strong type lang, do not need deduce candidate types
|
||||||
if (functionCalls==null) return;
|
if (functionCalls==null) return;
|
||||||
if (functionCalls.size()==0) return; //no information avaliable for type deduction
|
if (functionCalls.size()==0) return; //no information avaliable for type deduction
|
||||||
if (this.rawType==null) {
|
if (this.rawType==null) {
|
||||||
List<TypeEntity> candidateTypes = inferer.calculateCandidateTypes(this,this.functionCalls);
|
List<TypeEntity> candidateTypes = bindingResolver.calculateCandidateTypes(this,this.functionCalls);
|
||||||
if (candidateTypes.size()>0) {
|
if (candidateTypes.size()>0) {
|
||||||
this.type = new CandidateTypes(candidateTypes,inferer.getRepo().generateId());
|
this.type = new CandidateTypes(candidateTypes, bindingResolver.getRepo().generateId());
|
||||||
inferer.getRepo().add(this.type);
|
bindingResolver.getRepo().add(this.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import depends.entity.repo.BuiltInType;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.entity.repo.InMemoryEntityRepo;
|
import depends.entity.repo.InMemoryEntityRepo;
|
||||||
import depends.relations.ImportLookupStrategy;
|
import depends.relations.ImportLookupStrategy;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import multilang.depends.util.file.FileTraversal;
|
import multilang.depends.util.file.FileTraversal;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
@ -83,7 +83,7 @@ abstract public class AbstractLangProcessor {
|
||||||
*/
|
*/
|
||||||
public abstract FileParser createFileParser(String fileFullPath);
|
public abstract FileParser createFileParser(String fileFullPath);
|
||||||
|
|
||||||
public Inferer inferer;
|
public IBindingResolver bindingResolver;
|
||||||
protected EntityRepo entityRepo;
|
protected EntityRepo entityRepo;
|
||||||
protected String inputSrcPath;
|
protected String inputSrcPath;
|
||||||
public String[] includeDirs;
|
public String[] includeDirs;
|
||||||
|
@ -102,13 +102,13 @@ abstract public class AbstractLangProcessor {
|
||||||
*
|
*
|
||||||
* @param inputDir
|
* @param inputDir
|
||||||
* @param includeDir
|
* @param includeDir
|
||||||
* @param inferer
|
* @param bindingResolver
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public EntityRepo buildDependencies(String inputDir, String[] includeDir, Inferer inferer) {
|
public EntityRepo buildDependencies(String inputDir, String[] includeDir, IBindingResolver bindingResolver) {
|
||||||
this.inputSrcPath = inputDir;
|
this.inputSrcPath = inputDir;
|
||||||
this.includeDirs = includeDir;
|
this.includeDirs = includeDir;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
logger.info("Start parsing files...");
|
logger.info("Start parsing files...");
|
||||||
parseAllFiles();
|
parseAllFiles();
|
||||||
markAllEntitiesScope();
|
markAllEntitiesScope();
|
||||||
|
@ -144,7 +144,7 @@ abstract public class AbstractLangProcessor {
|
||||||
*/
|
*/
|
||||||
public void resolveBindings() {
|
public void resolveBindings() {
|
||||||
System.out.println("Resolve types and bindings of variables, methods and expressions....");
|
System.out.println("Resolve types and bindings of variables, methods and expressions....");
|
||||||
this.potentialExternalDependencies = inferer.resolveAllBindings(this);
|
this.potentialExternalDependencies = bindingResolver.resolveAllBindings(this.isEagerExpressionResolve());
|
||||||
if (getExternalDependencies().size() > 0) {
|
if (getExternalDependencies().size() > 0) {
|
||||||
System.out.println("There are " + getExternalDependencies().size() + " items are potential external dependencies.");
|
System.out.println("There are " + getExternalDependencies().size() + " items are potential external dependencies.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import depends.entity.*;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.entity.repo.IdGenerator;
|
import depends.entity.repo.IdGenerator;
|
||||||
import depends.importtypes.Import;
|
import depends.importtypes.Import;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,14 +40,14 @@ public abstract class HandlerContext {
|
||||||
protected IdGenerator idGenerator;
|
protected IdGenerator idGenerator;
|
||||||
|
|
||||||
protected FileEntity currentFileEntity;
|
protected FileEntity currentFileEntity;
|
||||||
protected Inferer inferer;
|
protected IBindingResolver bindingResolver;
|
||||||
|
|
||||||
|
|
||||||
public HandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
public HandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.idGenerator = entityRepo;
|
this.idGenerator = entityRepo;
|
||||||
entityStack = new Stack<Entity>();
|
entityStack = new Stack<Entity>();
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileEntity startFile(String fileName) {
|
public FileEntity startFile(String fileName) {
|
||||||
|
@ -312,7 +312,7 @@ public abstract class HandlerContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private VarEntity getVarInLocalFile(ContainerEntity container, GenericName varName) {
|
private VarEntity getVarInLocalFile(ContainerEntity container, GenericName varName) {
|
||||||
Entity entity = inferer.resolveName(container, varName, false);
|
Entity entity = bindingResolver.resolveName(container, varName, false);
|
||||||
if (entity ==null ) return null;
|
if (entity ==null ) return null;
|
||||||
if (!entity.getAncestorOfType(FileEntity.class).equals(currentFileEntity)) return null;
|
if (!entity.getAncestorOfType(FileEntity.class).equals(currentFileEntity)) return null;
|
||||||
if (entity instanceof VarEntity) return (VarEntity)entity;
|
if (entity instanceof VarEntity) return (VarEntity)entity;
|
||||||
|
@ -320,7 +320,7 @@ public abstract class HandlerContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity foundEntityWithName(GenericName rawName) {
|
public Entity foundEntityWithName(GenericName rawName) {
|
||||||
return inferer.resolveName(lastContainer(), rawName, true);
|
return bindingResolver.resolveName(lastContainer(), rawName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToRepo(Entity entity) {
|
public void addToRepo(Entity entity) {
|
||||||
|
|
|
@ -25,12 +25,11 @@ SOFTWARE.
|
||||||
package depends.extractor.cpp;
|
package depends.extractor.cpp;
|
||||||
|
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public abstract class CppFileParser implements depends.extractor.FileParser {
|
public abstract class CppFileParser implements depends.extractor.FileParser {
|
||||||
protected String fileFullPath;
|
protected String fileFullPath;
|
||||||
protected EntityRepo entityRepo;
|
protected EntityRepo entityRepo;
|
||||||
public CppFileParser(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
public CppFileParser(String fileFullPath, EntityRepo entityRepo) {
|
||||||
this.fileFullPath = fileFullPath;
|
this.fileFullPath = fileFullPath;
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,12 @@ package depends.extractor.cpp;
|
||||||
import depends.entity.*;
|
import depends.entity.*;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.HandlerContext;
|
import depends.extractor.HandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class CppHandlerContext extends HandlerContext {
|
public class CppHandlerContext extends HandlerContext {
|
||||||
|
|
||||||
public CppHandlerContext(EntityRepo entityRepo,Inferer inferer) {
|
public CppHandlerContext(EntityRepo entityRepo, IBindingResolver IBindingResolver) {
|
||||||
super(entityRepo,inferer);
|
super(entityRepo, IBindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity foundNamespace(String nampespaceName, int startingLineNumber) {
|
public Entity foundNamespace(String nampespaceName, int startingLineNumber) {
|
||||||
|
|
|
@ -56,12 +56,12 @@ public class CppImportLookupStrategy extends ImportLookupStrategy {
|
||||||
if (importedItem instanceof FileEntity) {
|
if (importedItem instanceof FileEntity) {
|
||||||
FileEntity importedFile = (FileEntity) repo.getEntity(file);
|
FileEntity importedFile = (FileEntity) repo.getEntity(file);
|
||||||
if (importedFile==null) continue;
|
if (importedFile==null) continue;
|
||||||
Entity entity = inferer.resolveName(importedFile,GenericName.build(name), false);
|
Entity entity = bindingResolver.resolveName(importedFile,GenericName.build(name), false);
|
||||||
if (entity!=null) return entity;
|
if (entity!=null) return entity;
|
||||||
Collection<Entity> namespaces = fileEntity.getImportedTypes();
|
Collection<Entity> namespaces = fileEntity.getImportedTypes();
|
||||||
for (Entity ns:namespaces) {
|
for (Entity ns:namespaces) {
|
||||||
String nameWithPrefix = ns.getQualifiedName() + "." + name;
|
String nameWithPrefix = ns.getQualifiedName() + "." + name;
|
||||||
entity = inferer.resolveName(importedFile,GenericName.build(nameWithPrefix), false);
|
entity = bindingResolver.resolveName(importedFile,GenericName.build(nameWithPrefix), false);
|
||||||
if (entity!=null) return entity;
|
if (entity!=null) return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class CppProcessor extends AbstractLangProcessor {
|
||||||
if (preprocessorHandler==null) {
|
if (preprocessorHandler==null) {
|
||||||
preprocessorHandler = new PreprocessorHandler(super.inputSrcPath,super.includePaths());
|
preprocessorHandler = new PreprocessorHandler(super.inputSrcPath,super.includePaths());
|
||||||
}
|
}
|
||||||
return new CdtCppFileParser(fileFullPath, entityRepo, preprocessorHandler, inferer, macroRepo);
|
return new CdtCppFileParser(fileFullPath, entityRepo, preprocessorHandler, bindingResolver, macroRepo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.FileEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.cpp.CppFileParser;
|
import depends.extractor.cpp.CppFileParser;
|
||||||
import depends.extractor.cpp.MacroRepo;
|
import depends.extractor.cpp.MacroRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ import java.util.Map;
|
||||||
public class CdtCppFileParser extends CppFileParser {
|
public class CdtCppFileParser extends CppFileParser {
|
||||||
|
|
||||||
private PreprocessorHandler preprocessorHandler ;
|
private PreprocessorHandler preprocessorHandler ;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
private MacroRepo macroRepo;
|
private MacroRepo macroRepo;
|
||||||
|
|
||||||
public CdtCppFileParser(String fileFullPath, EntityRepo entityRepo,PreprocessorHandler preprocessorHandler, Inferer inferer, MacroRepo macroRepo) {
|
public CdtCppFileParser(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler, IBindingResolver bindingResolver, MacroRepo macroRepo) {
|
||||||
super(fileFullPath, entityRepo,inferer);
|
super(fileFullPath, entityRepo);
|
||||||
this.preprocessorHandler = preprocessorHandler;
|
this.preprocessorHandler = preprocessorHandler;
|
||||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.macroRepo= macroRepo;
|
this.macroRepo= macroRepo;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,11 +73,11 @@ public class CdtCppFileParser extends CppFileParser {
|
||||||
if (fileFullPath.contains("regex.h")){
|
if (fileFullPath.contains("regex.h")){
|
||||||
System.out.println("stop");
|
System.out.println("stop");
|
||||||
}
|
}
|
||||||
CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler,inferer);
|
CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler, bindingResolver);
|
||||||
IASTTranslationUnit tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
|
IASTTranslationUnit tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
|
||||||
boolean containsIncludes = false;
|
boolean containsIncludes = false;
|
||||||
for (String incl:preprocessorHandler.getDirectIncludedFiles(tu.getAllPreprocessorStatements(),fileFullPath)) {
|
for (String incl:preprocessorHandler.getDirectIncludedFiles(tu.getAllPreprocessorStatements(),fileFullPath)) {
|
||||||
CdtCppFileParser importedParser = new CdtCppFileParser(incl, entityRepo, preprocessorHandler,inferer,macroRepo);
|
CdtCppFileParser importedParser = new CdtCppFileParser(incl, entityRepo, preprocessorHandler, bindingResolver,macroRepo);
|
||||||
importedParser.parse(false,macroMap);
|
importedParser.parse(false,macroMap);
|
||||||
Map<String, String> macros = macroRepo.get(incl);
|
Map<String, String> macros = macroRepo.get(incl);
|
||||||
if (macros!=null)
|
if (macros!=null)
|
||||||
|
|
|
@ -31,7 +31,7 @@ import depends.extractor.cpp.CppHandlerContext;
|
||||||
import depends.importtypes.ExactMatchImport;
|
import depends.importtypes.ExactMatchImport;
|
||||||
import depends.importtypes.FileImport;
|
import depends.importtypes.FileImport;
|
||||||
import depends.importtypes.PackageWildCardImport;
|
import depends.importtypes.PackageWildCardImport;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.eclipse.cdt.core.dom.ast.*;
|
import org.eclipse.cdt.core.dom.ast.*;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
|
@ -50,17 +50,17 @@ public class CppVisitor extends ASTVisitor {
|
||||||
private CppHandlerContext context;
|
private CppHandlerContext context;
|
||||||
private IdGenerator idGenerator;
|
private IdGenerator idGenerator;
|
||||||
private PreprocessorHandler preprocessorHandler;
|
private PreprocessorHandler preprocessorHandler;
|
||||||
Inferer inferer;
|
IBindingResolver bindingResolver;
|
||||||
private ExpressionUsage expressionUsage;
|
private ExpressionUsage expressionUsage;
|
||||||
HashSet<String> file;
|
HashSet<String> file;
|
||||||
public CppVisitor(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler,Inferer inferer) {
|
public CppVisitor(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler, IBindingResolver bindingResolver) {
|
||||||
super(true);
|
super(true);
|
||||||
this.shouldVisitAmbiguousNodes = true;
|
this.shouldVisitAmbiguousNodes = true;
|
||||||
this.shouldVisitImplicitNames = true;
|
this.shouldVisitImplicitNames = true;
|
||||||
this.includeInactiveNodes = true;
|
this.includeInactiveNodes = true;
|
||||||
this.context = new CppHandlerContext(entityRepo,inferer);
|
this.context = new CppHandlerContext(entityRepo, bindingResolver);
|
||||||
idGenerator = entityRepo;
|
idGenerator = entityRepo;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.preprocessorHandler = preprocessorHandler;
|
this.preprocessorHandler = preprocessorHandler;
|
||||||
expressionUsage = new ExpressionUsage(context,entityRepo);
|
expressionUsage = new ExpressionUsage(context,entityRepo);
|
||||||
file = new HashSet<>();
|
file = new HashSet<>();
|
||||||
|
|
|
@ -27,7 +27,7 @@ package depends.extractor.golang;
|
||||||
import depends.entity.Entity;
|
import depends.entity.Entity;
|
||||||
import depends.entity.FileEntity;
|
import depends.entity.FileEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
@ -43,11 +43,11 @@ import java.io.IOException;
|
||||||
public class GoFileParser implements depends.extractor.FileParser{
|
public class GoFileParser implements depends.extractor.FileParser{
|
||||||
private String fileFullPath;
|
private String fileFullPath;
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
public GoFileParser(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
public GoFileParser(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.fileFullPath = fileFullPath;
|
this.fileFullPath = fileFullPath;
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +59,7 @@ public class GoFileParser implements depends.extractor.FileParser{
|
||||||
GoParser parser = new GoParser(tokens);
|
GoParser parser = new GoParser(tokens);
|
||||||
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
||||||
parser.setInterpreter(interpreter);
|
parser.setInterpreter(interpreter);
|
||||||
GoListener bridge = new GoListener(fileFullPath, entityRepo,inferer);
|
GoListener bridge = new GoListener(fileFullPath, entityRepo, bindingResolver);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
try {
|
try {
|
||||||
walker.walk(bridge, parser.sourceFile());
|
walker.walk(bridge, parser.sourceFile());
|
||||||
|
|
|
@ -28,12 +28,12 @@ import depends.entity.Entity;
|
||||||
import depends.entity.PackageEntity;
|
import depends.entity.PackageEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.HandlerContext;
|
import depends.extractor.HandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class GoHandlerContext extends HandlerContext {
|
public class GoHandlerContext extends HandlerContext {
|
||||||
|
|
||||||
public GoHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
public GoHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
super(entityRepo,inferer);
|
super(entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity foundPackageDeclaration(String packageName){
|
public Entity foundPackageDeclaration(String packageName){
|
||||||
|
|
|
@ -4,7 +4,7 @@ import depends.entity.FunctionEntity;
|
||||||
import depends.entity.GenericName;
|
import depends.entity.GenericName;
|
||||||
import depends.entity.VarEntity;
|
import depends.entity.VarEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -17,8 +17,8 @@ public class GoListener extends GoParserBaseListener {
|
||||||
super.enterSourceFile(ctx);
|
super.enterSourceFile(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
public GoListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
context = new GoHandlerContext(entityRepo,inferer);
|
context = new GoHandlerContext(entityRepo, bindingResolver);
|
||||||
context.startFile(fileFullPath);
|
context.startFile(fileFullPath);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class GoProcessor extends AbstractLangProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
return new GoFileParser(fileFullPath, entityRepo, inferer);
|
return new GoFileParser(fileFullPath, entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,8 +24,10 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.extractor.java;
|
package depends.extractor.java;
|
||||||
|
|
||||||
import java.io.IOException;
|
import depends.entity.Entity;
|
||||||
|
import depends.entity.FileEntity;
|
||||||
|
import depends.entity.repo.EntityRepo;
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
@ -35,22 +37,17 @@ import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
||||||
import org.antlr.v4.runtime.atn.PredictionContextCache;
|
import org.antlr.v4.runtime.atn.PredictionContextCache;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
|
||||||
import depends.entity.Entity;
|
import java.io.IOException;
|
||||||
import depends.entity.FileEntity;
|
|
||||||
import depends.entity.repo.EntityRepo;
|
|
||||||
import depends.extractor.java.JavaLexer;
|
|
||||||
import depends.extractor.java.JavaParser;
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
|
|
||||||
public class JavaFileParser implements depends.extractor.FileParser{
|
public class JavaFileParser implements depends.extractor.FileParser{
|
||||||
private String fileFullPath;
|
private String fileFullPath;
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
public JavaFileParser(String fileFullPath,EntityRepo entityRepo, Inferer inferer) {
|
public JavaFileParser(String fileFullPath,EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.fileFullPath = fileFullPath;
|
this.fileFullPath = fileFullPath;
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,7 +59,7 @@ public class JavaFileParser implements depends.extractor.FileParser{
|
||||||
JavaParser parser = new JavaParser(tokens);
|
JavaParser parser = new JavaParser(tokens);
|
||||||
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
||||||
parser.setInterpreter(interpreter);
|
parser.setInterpreter(interpreter);
|
||||||
JavaListener bridge = new JavaListener(fileFullPath, entityRepo,inferer);
|
JavaListener bridge = new JavaListener(fileFullPath, entityRepo, bindingResolver);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
try {
|
try {
|
||||||
walker.walk(bridge, parser.compilationUnit());
|
walker.walk(bridge, parser.compilationUnit());
|
||||||
|
|
|
@ -28,12 +28,12 @@ import depends.entity.Entity;
|
||||||
import depends.entity.PackageEntity;
|
import depends.entity.PackageEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.HandlerContext;
|
import depends.extractor.HandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class JavaHandlerContext extends HandlerContext {
|
public class JavaHandlerContext extends HandlerContext {
|
||||||
|
|
||||||
public JavaHandlerContext(EntityRepo entityRepo,Inferer inferer) {
|
public JavaHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
super(entityRepo,inferer);
|
super(entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity foundNewPackage(String packageName) {
|
public Entity foundNewPackage(String packageName) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.java.JavaParser.*;
|
import depends.extractor.java.JavaParser.*;
|
||||||
import depends.extractor.java.context.*;
|
import depends.extractor.java.context.*;
|
||||||
import depends.importtypes.ExactMatchImport;
|
import depends.importtypes.ExactMatchImport;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,8 +40,8 @@ public class JavaListener extends JavaParserBaseListener {
|
||||||
private final ExpressionUsage expressionUsage;
|
private final ExpressionUsage expressionUsage;
|
||||||
private final EntityRepo entityRepo;
|
private final EntityRepo entityRepo;
|
||||||
|
|
||||||
public JavaListener(String fileFullPath, EntityRepo entityRepo,Inferer inferer) {
|
public JavaListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.context = new JavaHandlerContext(entityRepo,inferer);
|
this.context = new JavaHandlerContext(entityRepo, bindingResolver);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
annotationProcessor = new AnnotationProcessor();
|
annotationProcessor = new AnnotationProcessor();
|
||||||
expressionUsage = new ExpressionUsage(context,entityRepo);
|
expressionUsage = new ExpressionUsage(context,entityRepo);
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class JavaProcessor extends AbstractLangProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
return new JavaFileParser(fileFullPath,entityRepo, inferer);
|
return new JavaFileParser(fileFullPath,entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package depends.extractor.kotlin;
|
package depends.extractor.kotlin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import depends.entity.repo.EntityRepo;
|
||||||
|
import depends.extractor.FileParser;
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
|
||||||
import depends.entity.repo.EntityRepo;
|
import java.io.IOException;
|
||||||
import depends.extractor.FileParser;
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public class KotlinFileParser implements FileParser {
|
public class KotlinFileParser implements FileParser {
|
||||||
|
|
||||||
|
@ -20,18 +19,18 @@ public class KotlinFileParser implements FileParser {
|
||||||
Lexer lexer = new KotlinLexer(input);
|
Lexer lexer = new KotlinLexer(input);
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
KotlinParser parser = new KotlinParser(tokens);
|
KotlinParser parser = new KotlinParser(tokens);
|
||||||
KotlinListener bridge = new KotlinListener(fileFullPath, entityRepo,inferer);
|
KotlinListener bridge = new KotlinListener(fileFullPath, entityRepo, bindingResolver);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
walker.walk(bridge, parser.kotlinFile());
|
walker.walk(bridge, parser.kotlinFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fileFullPath;
|
private String fileFullPath;
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
public KotlinFileParser(String fileFullPath,EntityRepo entityRepo, Inferer inferer) {
|
public KotlinFileParser(String fileFullPath,EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.fileFullPath = fileFullPath;
|
this.fileFullPath = fileFullPath;
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ package depends.extractor.kotlin;
|
||||||
|
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.java.JavaHandlerContext;
|
import depends.extractor.java.JavaHandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class KotlinHandlerContext extends JavaHandlerContext {
|
public class KotlinHandlerContext extends JavaHandlerContext {
|
||||||
|
|
||||||
public KotlinHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
public KotlinHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
super(entityRepo,inferer);
|
super(entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.kotlin.KotlinParser.ImportHeaderContext;
|
import depends.extractor.kotlin.KotlinParser.ImportHeaderContext;
|
||||||
import depends.extractor.kotlin.KotlinParser.PackageHeaderContext;
|
import depends.extractor.kotlin.KotlinParser.PackageHeaderContext;
|
||||||
import depends.importtypes.ExactMatchImport;
|
import depends.importtypes.ExactMatchImport;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class KotlinListener extends KotlinParserBaseListener {
|
public class KotlinListener extends KotlinParserBaseListener {
|
||||||
|
|
||||||
private KotlinHandlerContext context;
|
private KotlinHandlerContext context;
|
||||||
|
|
||||||
public KotlinListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
public KotlinListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
this.context = new KotlinHandlerContext(entityRepo,inferer);
|
this.context = new KotlinHandlerContext(entityRepo, bindingResolver);
|
||||||
context.startFile(fileFullPath);
|
context.startFile(fileFullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class KotlinProcessor extends AbstractLangProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
return new KotlinFileParser(fileFullPath,entityRepo, inferer);
|
return new KotlinFileParser(fileFullPath,entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,7 +33,6 @@ import depends.entity.Entity;
|
||||||
import depends.entity.FileEntity;
|
import depends.entity.FileEntity;
|
||||||
import depends.entity.GenericName;
|
import depends.entity.GenericName;
|
||||||
import depends.entity.TypeEntity;
|
import depends.entity.TypeEntity;
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public class PomArtifactEntity extends TypeEntity {
|
public class PomArtifactEntity extends TypeEntity {
|
||||||
HashMap<String,String> properties;
|
HashMap<String,String> properties;
|
||||||
|
|
|
@ -24,23 +24,22 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.extractor.pom;
|
package depends.extractor.pom;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.CharStream;
|
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
|
||||||
import org.antlr.v4.runtime.Lexer;
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
|
||||||
|
|
||||||
import depends.entity.Entity;
|
import depends.entity.Entity;
|
||||||
import depends.entity.FileEntity;
|
import depends.entity.FileEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.FileParser;
|
import depends.extractor.FileParser;
|
||||||
import depends.extractor.xml.XMLLexer;
|
import depends.extractor.xml.XMLLexer;
|
||||||
import depends.extractor.xml.XMLParser;
|
import depends.extractor.xml.XMLParser;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
import org.antlr.v4.runtime.Lexer;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PomFileParser implements FileParser {
|
public class PomFileParser implements FileParser {
|
||||||
|
|
||||||
|
@ -48,14 +47,14 @@ public class PomFileParser implements FileParser {
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private PomProcessor parseCreator;
|
private PomProcessor parseCreator;
|
||||||
private List<String> includePaths;
|
private List<String> includePaths;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
|
|
||||||
public PomFileParser(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor pomProcessor,Inferer inferer) {
|
public PomFileParser(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor pomProcessor, IBindingResolver bindingResolver) {
|
||||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.parseCreator = pomProcessor;
|
this.parseCreator = pomProcessor;
|
||||||
this.includePaths = includePaths;
|
this.includePaths = includePaths;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +69,7 @@ public class PomFileParser implements FileParser {
|
||||||
Lexer lexer = new XMLLexer(input);
|
Lexer lexer = new XMLLexer(input);
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
XMLParser parser = new XMLParser(tokens);
|
XMLParser parser = new XMLParser(tokens);
|
||||||
PomListener bridge = new PomListener(fileFullPath, entityRepo, includePaths,parseCreator,inferer);
|
PomListener bridge = new PomListener(fileFullPath, entityRepo, includePaths,parseCreator, bindingResolver);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
walker.walk(bridge, parser.document());
|
walker.walk(bridge, parser.document());
|
||||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||||
|
|
|
@ -31,7 +31,7 @@ import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.FileParser;
|
import depends.extractor.FileParser;
|
||||||
import depends.extractor.xml.XMLParser.ElementContext;
|
import depends.extractor.xml.XMLParser.ElementContext;
|
||||||
import depends.extractor.xml.XMLParserBaseListener;
|
import depends.extractor.xml.XMLParserBaseListener;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -46,16 +46,16 @@ public class PomListener extends XMLParserBaseListener {
|
||||||
private PomParent pomParent;
|
private PomParent pomParent;
|
||||||
private PomProcessor parseCreator;
|
private PomProcessor parseCreator;
|
||||||
private List<String> includePaths;
|
private List<String> includePaths;
|
||||||
private Inferer inferer;
|
private IBindingResolver IBindingResolver;
|
||||||
private Stack<PomCoords> pomCoords= new Stack<>();
|
private Stack<PomCoords> pomCoords= new Stack<>();
|
||||||
|
|
||||||
public PomListener(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor parseCreator,
|
public PomListener(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor parseCreator,
|
||||||
Inferer inferer) {
|
IBindingResolver bindingResolver) {
|
||||||
this.context = new PomHandlerContext(entityRepo);
|
this.context = new PomHandlerContext(entityRepo);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.parseCreator = parseCreator;
|
this.parseCreator = parseCreator;
|
||||||
this.includePaths = includePaths;
|
this.includePaths = includePaths;
|
||||||
this.inferer = inferer;
|
this.IBindingResolver = bindingResolver;
|
||||||
context.startFile(fileFullPath);
|
context.startFile(fileFullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class PomListener extends XMLParserBaseListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pomCoords.pop();
|
pomCoords.pop();
|
||||||
context.currentFile().inferLocalLevelEntities(inferer);
|
context.currentFile().inferLocalLevelEntities(IBindingResolver);
|
||||||
}
|
}
|
||||||
super.exitElement(ctx);
|
super.exitElement(ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class PomProcessor extends AbstractLangProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
return new PomFileParser(fileFullPath,entityRepo,includePaths(),this,inferer);
|
return new PomFileParser(fileFullPath,entityRepo,includePaths(),this, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package depends.extractor.python;
|
package depends.extractor.python;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import depends.entity.FileEntity;
|
|
||||||
import depends.entity.FunctionCall;
|
import depends.entity.FunctionCall;
|
||||||
import depends.entity.FunctionEntity;
|
import depends.entity.FunctionEntity;
|
||||||
import depends.entity.GenericName;
|
import depends.entity.GenericName;
|
||||||
|
|
|
@ -6,12 +6,12 @@ import depends.entity.GenericName;
|
||||||
import depends.entity.PackageEntity;
|
import depends.entity.PackageEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.HandlerContext;
|
import depends.extractor.HandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
|
||||||
public class PythonHandlerContext extends HandlerContext {
|
public class PythonHandlerContext extends HandlerContext {
|
||||||
|
|
||||||
public PythonHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
public PythonHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||||
super(entityRepo, inferer);
|
super(entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,7 +6,7 @@ import depends.extractor.HandlerContext;
|
||||||
import depends.extractor.python.PythonHandlerContext;
|
import depends.extractor.python.PythonHandlerContext;
|
||||||
import depends.extractor.python.PythonParser.*;
|
import depends.extractor.python.PythonParser.*;
|
||||||
import depends.extractor.python.PythonParserBaseVisitor;
|
import depends.extractor.python.PythonParserBaseVisitor;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
import org.antlr.v4.runtime.RuleContext;
|
import org.antlr.v4.runtime.RuleContext;
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ public class ExpressionUsage {
|
||||||
HandlerContext context;
|
HandlerContext context;
|
||||||
IdGenerator idGenerator;
|
IdGenerator idGenerator;
|
||||||
private boolean exprStarted=false;
|
private boolean exprStarted=false;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
public ExpressionUsage(PythonHandlerContext context, IdGenerator idGenerator, Inferer inferer) {
|
public ExpressionUsage(PythonHandlerContext context, IdGenerator idGenerator, IBindingResolver bindingResolver) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.idGenerator = idGenerator;
|
this.idGenerator = idGenerator;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,7 +207,7 @@ public class ExpressionUsage {
|
||||||
Entity typeEntity = context.foundEntityWithName(funcName);
|
Entity typeEntity = context.foundEntityWithName(funcName);
|
||||||
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
||||||
theExpression.setCreate(true);
|
theExpression.setCreate(true);
|
||||||
theExpression.setType(typeEntity.getType(), typeEntity, inferer);
|
theExpression.setType(typeEntity.getType(), typeEntity, bindingResolver);
|
||||||
theExpression.setRawType(typeEntity.getRawName());
|
theExpression.setRawType(typeEntity.getRawName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ public class ExpressionUsage {
|
||||||
Entity typeEntity = context.foundEntityWithName(funcName);
|
Entity typeEntity = context.foundEntityWithName(funcName);
|
||||||
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
||||||
theExpression.getParent().setCreate(true);
|
theExpression.getParent().setCreate(true);
|
||||||
theExpression.setType(typeEntity.getType(), typeEntity, inferer);
|
theExpression.setType(typeEntity.getType(), typeEntity, bindingResolver);
|
||||||
theExpression.getParent().setRawType(typeEntity.getRawName());
|
theExpression.getParent().setRawType(typeEntity.getRawName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import depends.extractor.python.PythonParser.*;
|
||||||
import depends.extractor.python.PythonParserBaseListener;
|
import depends.extractor.python.PythonParserBaseListener;
|
||||||
import depends.extractor.ruby.IncludedFileLocator;
|
import depends.extractor.ruby.IncludedFileLocator;
|
||||||
import depends.importtypes.FileImport;
|
import depends.importtypes.FileImport;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
|
|
||||||
|
@ -23,15 +23,15 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
||||||
private final EntityRepo entityRepo;
|
private final EntityRepo entityRepo;
|
||||||
private final IncludedFileLocator includeFileLocator;
|
private final IncludedFileLocator includeFileLocator;
|
||||||
private final PythonProcessor pythonProcessor;
|
private final PythonProcessor pythonProcessor;
|
||||||
private final Inferer inferer;
|
private final IBindingResolver bindingResolver;
|
||||||
public PythonCodeListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer,
|
public PythonCodeListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver,
|
||||||
IncludedFileLocator includeFileLocator, PythonProcessor pythonProcessor) {
|
IncludedFileLocator includeFileLocator, PythonProcessor pythonProcessor) {
|
||||||
this.context = new PythonHandlerContext(entityRepo, inferer);
|
this.context = new PythonHandlerContext(entityRepo, bindingResolver);
|
||||||
this.expressionUsage = new ExpressionUsage(context, entityRepo, inferer);
|
this.expressionUsage = new ExpressionUsage(context, entityRepo, bindingResolver);
|
||||||
FileEntity fileEntity = context.startFile(fileFullPath);
|
FileEntity fileEntity = context.startFile(fileFullPath);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.includeFileLocator = includeFileLocator;
|
this.includeFileLocator = includeFileLocator;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.pythonProcessor = pythonProcessor;
|
this.pythonProcessor = pythonProcessor;
|
||||||
|
|
||||||
String dir = FileUtil.uniqFilePath(FileUtil.getLocatedDir(fileFullPath));
|
String dir = FileUtil.uniqFilePath(FileUtil.getLocatedDir(fileFullPath));
|
||||||
|
@ -117,7 +117,7 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
||||||
if (FileUtil.existFile(fullName) && !(FileUtil.isDirectory(fullName))) {
|
if (FileUtil.existFile(fullName) && !(FileUtil.isDirectory(fullName))) {
|
||||||
context.foundNewImport(new FileImport(fullName));
|
context.foundNewImport(new FileImport(fullName));
|
||||||
}
|
}
|
||||||
Entity itemEntity = inferer.resolveName(entityRepo.getEntity(fullName), GenericName.build(name), true);
|
Entity itemEntity = bindingResolver.resolveName(entityRepo.getEntity(fullName), GenericName.build(name), true);
|
||||||
if (itemEntity != null) {
|
if (itemEntity != null) {
|
||||||
context.foundNewAlias(GenericName.build(alias), itemEntity);
|
context.foundNewAlias(GenericName.build(alias), itemEntity);
|
||||||
context.foundNewImport(new NameAliasImport(itemEntity.getQualifiedName(), itemEntity, alias));
|
context.foundNewImport(new NameAliasImport(itemEntity.getQualifiedName(), itemEntity, alias));
|
||||||
|
@ -183,7 +183,7 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visitIncludedFile(String fullName) {
|
private void visitIncludedFile(String fullName) {
|
||||||
PythonFileParser importedParser = new PythonFileParser(fullName, entityRepo, includeFileLocator, inferer,
|
PythonFileParser importedParser = new PythonFileParser(fullName, entityRepo, includeFileLocator, bindingResolver,
|
||||||
pythonProcessor);
|
pythonProcessor);
|
||||||
try {
|
try {
|
||||||
importedParser.parse();
|
importedParser.parse();
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
package depends.extractor.python.union;
|
package depends.extractor.python.union;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.CharStream;
|
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
|
||||||
import org.antlr.v4.runtime.Lexer;
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
|
||||||
|
|
||||||
import depends.entity.Entity;
|
import depends.entity.Entity;
|
||||||
import depends.entity.FileEntity;
|
import depends.entity.FileEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
|
@ -15,21 +7,28 @@ import depends.extractor.FileParser;
|
||||||
import depends.extractor.python.PythonLexer;
|
import depends.extractor.python.PythonLexer;
|
||||||
import depends.extractor.python.PythonParser;
|
import depends.extractor.python.PythonParser;
|
||||||
import depends.extractor.ruby.IncludedFileLocator;
|
import depends.extractor.ruby.IncludedFileLocator;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
import org.antlr.v4.runtime.Lexer;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PythonFileParser implements FileParser {
|
public class PythonFileParser implements FileParser {
|
||||||
|
|
||||||
private String fileFullPath;
|
private String fileFullPath;
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
private IncludedFileLocator includeFileLocator;
|
private IncludedFileLocator includeFileLocator;
|
||||||
private PythonProcessor processor;
|
private PythonProcessor processor;
|
||||||
|
|
||||||
public PythonFileParser(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includeFileLocator,
|
public PythonFileParser(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includeFileLocator,
|
||||||
Inferer inferer, PythonProcessor pythonProcessor) {
|
IBindingResolver bindingResolver, PythonProcessor pythonProcessor) {
|
||||||
this.fileFullPath = fileFullPath;
|
this.fileFullPath = fileFullPath;
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.includeFileLocator = includeFileLocator;
|
this.includeFileLocator = includeFileLocator;
|
||||||
this.processor = pythonProcessor;
|
this.processor = pythonProcessor;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,7 @@ public class PythonFileParser implements FileParser {
|
||||||
|
|
||||||
|
|
||||||
PythonParser parser = new PythonParser(tokens);
|
PythonParser parser = new PythonParser(tokens);
|
||||||
PythonCodeListener bridge = new PythonCodeListener(fileFullPath, entityRepo,inferer, includeFileLocator, processor);
|
PythonCodeListener bridge = new PythonCodeListener(fileFullPath, entityRepo, bindingResolver, includeFileLocator, processor);
|
||||||
ParseTreeWalker walker = new ParseTreeWalker();
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
walker.walk(bridge, parser.file_input());
|
walker.walk(bridge, parser.file_input());
|
||||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class PythonProcessor extends BasePythonProcessor {
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
IncludedFileLocator includeFileLocator = new IncludedFileLocator(super.includePaths());
|
IncludedFileLocator includeFileLocator = new IncludedFileLocator(super.includePaths());
|
||||||
return new PythonFileParser(fileFullPath,entityRepo,includeFileLocator,inferer,this);
|
return new PythonFileParser(fileFullPath,entityRepo,includeFileLocator, bindingResolver,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import depends.extractor.FileParser;
|
||||||
import depends.extractor.HandlerContext;
|
import depends.extractor.HandlerContext;
|
||||||
import depends.extractor.ParserCreator;
|
import depends.extractor.ParserCreator;
|
||||||
import depends.importtypes.FileImport;
|
import depends.importtypes.FileImport;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import multilang.depends.util.file.FileUtil;
|
import multilang.depends.util.file.FileUtil;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -41,11 +41,11 @@ public class RubyHandlerContext extends HandlerContext {
|
||||||
|
|
||||||
private IncludedFileLocator includedFileLocator;
|
private IncludedFileLocator includedFileLocator;
|
||||||
private ParserCreator parserCreator;
|
private ParserCreator parserCreator;
|
||||||
public RubyHandlerContext(EntityRepo entityRepo,
|
public RubyHandlerContext(EntityRepo entityRepo,
|
||||||
IncludedFileLocator includedFileLocator,
|
IncludedFileLocator includedFileLocator,
|
||||||
ExecutorService executorService,
|
ExecutorService executorService,
|
||||||
Inferer inferer, ParserCreator parserCreator) {
|
IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||||
super(entityRepo,inferer);
|
super(entityRepo, bindingResolver);
|
||||||
this.includedFileLocator = includedFileLocator;
|
this.includedFileLocator = includedFileLocator;
|
||||||
this.parserCreator = parserCreator;
|
this.parserCreator = parserCreator;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class RubyProcessor extends AbstractLangProcessor implements ParserCreato
|
||||||
@Override
|
@Override
|
||||||
public FileParser createFileParser(String fileFullPath) {
|
public FileParser createFileParser(String fileFullPath) {
|
||||||
executor = Executors.newSingleThreadExecutor();
|
executor = Executors.newSingleThreadExecutor();
|
||||||
return new JRubyFileParser(fileFullPath,entityRepo,executor,new IncludedFileLocator(super.includePaths()),inferer,this);
|
return new JRubyFileParser(fileFullPath,entityRepo,executor,new IncludedFileLocator(super.includePaths()), bindingResolver,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ package depends.extractor.ruby.jruby;
|
||||||
import depends.entity.*;
|
import depends.entity.*;
|
||||||
import depends.entity.repo.IdGenerator;
|
import depends.entity.repo.IdGenerator;
|
||||||
import depends.extractor.ruby.RubyHandlerContext;
|
import depends.extractor.ruby.RubyHandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.jrubyparser.ast.*;
|
import org.jrubyparser.ast.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,14 +35,14 @@ import java.util.List;
|
||||||
public class ExpressionUsage {
|
public class ExpressionUsage {
|
||||||
RubyHandlerContext context;
|
RubyHandlerContext context;
|
||||||
IdGenerator idGenerator;
|
IdGenerator idGenerator;
|
||||||
Inferer inferer;
|
IBindingResolver bindingResolver;
|
||||||
private RubyParserHelper helper;
|
private RubyParserHelper helper;
|
||||||
|
|
||||||
public ExpressionUsage(RubyHandlerContext context, IdGenerator idGenerator, RubyParserHelper helper,
|
public ExpressionUsage(RubyHandlerContext context, IdGenerator idGenerator, RubyParserHelper helper,
|
||||||
Inferer inferer) {
|
IBindingResolver bindingResolver) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.idGenerator = idGenerator;
|
this.idGenerator = idGenerator;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,14 @@ SOFTWARE.
|
||||||
|
|
||||||
package depends.extractor.ruby.jruby;
|
package depends.extractor.ruby.jruby;
|
||||||
|
|
||||||
import java.io.IOException;
|
import depends.entity.Entity;
|
||||||
import java.io.StringReader;
|
import depends.entity.FileEntity;
|
||||||
import java.util.concurrent.ExecutorService;
|
import depends.entity.repo.EntityRepo;
|
||||||
|
import depends.extractor.FileParser;
|
||||||
|
import depends.extractor.ParserCreator;
|
||||||
|
import depends.extractor.ruby.IncludedFileLocator;
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
|
import multilang.depends.util.file.FileUtil;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.jrubyparser.CompatVersion;
|
import org.jrubyparser.CompatVersion;
|
||||||
|
@ -35,31 +39,26 @@ import org.jrubyparser.Parser;
|
||||||
import org.jrubyparser.ast.Node;
|
import org.jrubyparser.ast.Node;
|
||||||
import org.jrubyparser.parser.ParserConfiguration;
|
import org.jrubyparser.parser.ParserConfiguration;
|
||||||
|
|
||||||
import depends.entity.Entity;
|
import java.io.IOException;
|
||||||
import depends.entity.FileEntity;
|
import java.io.StringReader;
|
||||||
import depends.entity.repo.EntityRepo;
|
import java.util.concurrent.ExecutorService;
|
||||||
import depends.extractor.FileParser;
|
|
||||||
import depends.extractor.ParserCreator;
|
|
||||||
import depends.extractor.ruby.IncludedFileLocator;
|
|
||||||
import depends.relations.Inferer;
|
|
||||||
import multilang.depends.util.file.FileUtil;
|
|
||||||
public class JRubyFileParser implements FileParser {
|
public class JRubyFileParser implements FileParser {
|
||||||
private String fileFullPath;
|
private String fileFullPath;
|
||||||
private EntityRepo entityRepo;
|
private EntityRepo entityRepo;
|
||||||
private ExecutorService executor;
|
private ExecutorService executor;
|
||||||
private IncludedFileLocator includesFileLocator;
|
private IncludedFileLocator includesFileLocator;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
private ParserCreator parserCreator;
|
private ParserCreator parserCreator;
|
||||||
|
|
||||||
public JRubyFileParser(String fileFullPath, EntityRepo entityRepo,
|
public JRubyFileParser(String fileFullPath, EntityRepo entityRepo,
|
||||||
ExecutorService executorService,
|
ExecutorService executorService,
|
||||||
IncludedFileLocator includesFileLocator,
|
IncludedFileLocator includesFileLocator,
|
||||||
Inferer inferer, ParserCreator parserCreator) {
|
IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||||
this.entityRepo = entityRepo;
|
this.entityRepo = entityRepo;
|
||||||
this.executor = executorService;
|
this.executor = executorService;
|
||||||
this.includesFileLocator = includesFileLocator;
|
this.includesFileLocator = includesFileLocator;
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.parserCreator = parserCreator;
|
this.parserCreator = parserCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ public class JRubyFileParser implements FileParser {
|
||||||
ParserConfiguration config = new ParserConfiguration(0, version);
|
ParserConfiguration config = new ParserConfiguration(0, version);
|
||||||
try {
|
try {
|
||||||
Node node = rubyParser.parse("<code>", in, config);
|
Node node = rubyParser.parse("<code>", in, config);
|
||||||
JRubyVisitor parser = new JRubyVisitor(fileFullPath, entityRepo, includesFileLocator,executor,inferer,parserCreator);
|
JRubyVisitor parser = new JRubyVisitor(fileFullPath, entityRepo, includesFileLocator,executor, bindingResolver,parserCreator);
|
||||||
node.accept(parser);
|
node.accept(parser);
|
||||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||||
((FileEntity)fileEntity).cacheAllExpressions();
|
((FileEntity)fileEntity).cacheAllExpressions();
|
||||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.repo.EntityRepo;
|
||||||
import depends.extractor.ParserCreator;
|
import depends.extractor.ParserCreator;
|
||||||
import depends.extractor.ruby.IncludedFileLocator;
|
import depends.extractor.ruby.IncludedFileLocator;
|
||||||
import depends.extractor.ruby.RubyHandlerContext;
|
import depends.extractor.ruby.RubyHandlerContext;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.IBindingResolver;
|
||||||
import org.jrubyparser.ast.*;
|
import org.jrubyparser.ast.*;
|
||||||
import org.jrubyparser.util.NoopVisitor;
|
import org.jrubyparser.util.NoopVisitor;
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class JRubyVisitor extends NoopVisitor {
|
||||||
private ExpressionUsage expressionUsage;
|
private ExpressionUsage expressionUsage;
|
||||||
|
|
||||||
public JRubyVisitor(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includedFileLocator,
|
public JRubyVisitor(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includedFileLocator,
|
||||||
ExecutorService executorService, Inferer inferer, ParserCreator parserCreator) {
|
ExecutorService executorService, IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||||
this.context = new RubyHandlerContext(entityRepo, includedFileLocator, executorService, inferer, parserCreator);
|
this.context = new RubyHandlerContext(entityRepo, includedFileLocator, executorService, bindingResolver, parserCreator);
|
||||||
expressionUsage = new ExpressionUsage(context, entityRepo, helper, inferer);
|
expressionUsage = new ExpressionUsage(context, entityRepo, helper, bindingResolver);
|
||||||
context.startFile(fileFullPath);
|
context.startFile(fileFullPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,10 @@ SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package depends.relations;
|
package depends.relations;
|
||||||
|
|
||||||
import depends.entity.*;
|
import depends.entity.*;
|
||||||
import depends.entity.repo.BuiltInType;
|
import depends.entity.repo.BuiltInType;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.entity.repo.NullBuiltInType;
|
import depends.entity.repo.NullBuiltInType;
|
||||||
import depends.extractor.AbstractLangProcessor;
|
|
||||||
import depends.extractor.UnsolvedBindings;
|
import depends.extractor.UnsolvedBindings;
|
||||||
import depends.importtypes.Import;
|
import depends.importtypes.Import;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -37,7 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Inferer {
|
public class BindingResolver implements IBindingResolver{
|
||||||
|
|
||||||
private BuiltInType buildInTypeManager = new NullBuiltInType();
|
private BuiltInType buildInTypeManager = new NullBuiltInType();
|
||||||
private ImportLookupStrategy importLookupStrategy;
|
private ImportLookupStrategy importLookupStrategy;
|
||||||
|
@ -47,31 +45,26 @@ public class Inferer {
|
||||||
private boolean eagerExpressionResolve = false;
|
private boolean eagerExpressionResolve = false;
|
||||||
private boolean isCollectUnsolvedBindings = false;
|
private boolean isCollectUnsolvedBindings = false;
|
||||||
private boolean isDuckTypingDeduce = true;
|
private boolean isDuckTypingDeduce = true;
|
||||||
private static Logger logger = LoggerFactory.getLogger(Inferer.class);
|
private static Logger logger = LoggerFactory.getLogger(IBindingResolver.class);
|
||||||
|
|
||||||
public Inferer(EntityRepo repo, ImportLookupStrategy importLookupStrategy, BuiltInType buildInTypeManager,
|
public BindingResolver(EntityRepo repo, ImportLookupStrategy importLookupStrategy, BuiltInType buildInTypeManager,
|
||||||
boolean isCollectUnsolvedBindings, boolean isDuckTypingDeduce) {
|
boolean isCollectUnsolvedBindings, boolean isDuckTypingDeduce) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.importLookupStrategy = importLookupStrategy;
|
this.importLookupStrategy = importLookupStrategy;
|
||||||
this.buildInTypeManager = buildInTypeManager;
|
this.buildInTypeManager = buildInTypeManager;
|
||||||
this.isCollectUnsolvedBindings = isCollectUnsolvedBindings;
|
this.isCollectUnsolvedBindings = isCollectUnsolvedBindings;
|
||||||
this.isDuckTypingDeduce = isDuckTypingDeduce;
|
this.isDuckTypingDeduce = isDuckTypingDeduce;
|
||||||
unsolvedSymbols= new HashSet<>();
|
unsolvedSymbols= new HashSet<>();
|
||||||
importLookupStrategy.setInferer(this);
|
importLookupStrategy.setBindingResolver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Resolve all bindings
|
public Set<UnsolvedBindings> resolveAllBindings(boolean isEagerExpressionResolve) {
|
||||||
* - Firstly, we resolve all types from there names.
|
|
||||||
* - Secondly, we resolve all expressions (expression will use type infomation of previous step
|
|
||||||
* @param langProcessor
|
|
||||||
*/
|
|
||||||
public Set<UnsolvedBindings> resolveAllBindings(AbstractLangProcessor langProcessor) {
|
|
||||||
System.out.println("Resolve type bindings....");
|
System.out.println("Resolve type bindings....");
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("Resolve type bindings...");
|
logger.info("Resolve type bindings...");
|
||||||
}
|
}
|
||||||
resolveTypes(langProcessor.isEagerExpressionResolve());
|
resolveTypes(isEagerExpressionResolve);
|
||||||
System.out.println("Dependency analaysing....");
|
System.out.println("Dependency analaysing....");
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("Dependency analaysing...");
|
logger.info("Dependency analaysing...");
|
||||||
|
@ -90,26 +83,13 @@ public class Inferer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For types start with the prefix, it will be treated as built-in type
|
@Override
|
||||||
* For example, java.io.* in Java, or __ in C/C++
|
|
||||||
* @param prefix
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isBuiltInTypePrefix(String prefix) {
|
|
||||||
return buildInTypeManager.isBuiltInTypePrefix(prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Different languages have different strategy on how to compute the imported types
|
|
||||||
* and the imported files.
|
|
||||||
* For example, in C/C++, both imported types (using namespace, using <type>) and imported files exists.
|
|
||||||
* while in java, only 'import class/function, or import wildcard class.* package.* exists.
|
|
||||||
*/
|
|
||||||
public Collection<Entity> getImportedRelationEntities(List<Import> importedNames) {
|
public Collection<Entity> getImportedRelationEntities(List<Import> importedNames) {
|
||||||
return importLookupStrategy.getImportedRelationEntities(importedNames);
|
return importLookupStrategy.getImportedRelationEntities(importedNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<Entity> getImportedTypes(List<Import> importedNames, FileEntity fileEntity) {
|
public Collection<Entity> getImportedTypes(List<Import> importedNames, FileEntity fileEntity) {
|
||||||
HashSet<UnsolvedBindings> unsolved = new HashSet<UnsolvedBindings>();
|
HashSet<UnsolvedBindings> unsolved = new HashSet<UnsolvedBindings>();
|
||||||
Collection<Entity> result = importLookupStrategy.getImportedTypes(importedNames,unsolved);
|
Collection<Entity> result = importLookupStrategy.getImportedTypes(importedNames,unsolved);
|
||||||
|
@ -124,22 +104,13 @@ public class Inferer {
|
||||||
if (!isCollectUnsolvedBindings) return;
|
if (!isCollectUnsolvedBindings) return;
|
||||||
this.unsolvedSymbols.add(item);
|
this.unsolvedSymbols.add(item);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public Collection<Entity> getImportedFiles(List<Import> importedNames) {
|
public Collection<Entity> getImportedFiles(List<Import> importedNames) {
|
||||||
return importLookupStrategy.getImportedFiles(importedNames);
|
return importLookupStrategy.getImportedFiles(importedNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* By given raw name, to infer the type of the name
|
@Override
|
||||||
* for example
|
|
||||||
* (It is just a wrapper of resolve name)
|
|
||||||
* if it is a class, the class is the type
|
|
||||||
* if it is a function, the return type is the type
|
|
||||||
* if it is a variable, type of variable is the type
|
|
||||||
* @param fromEntity
|
|
||||||
* @param rawName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public TypeEntity inferTypeFromName(Entity fromEntity, GenericName rawName) {
|
public TypeEntity inferTypeFromName(Entity fromEntity, GenericName rawName) {
|
||||||
Entity data = resolveName(fromEntity, rawName, true);
|
Entity data = resolveName(fromEntity, rawName, true);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
|
@ -147,13 +118,8 @@ public class Inferer {
|
||||||
return data.getType();
|
return data.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* By given raw name, to infer the entity of the name
|
@Override
|
||||||
* @param fromEntity
|
|
||||||
* @param rawName
|
|
||||||
* @param searchImport
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Entity resolveName(Entity fromEntity, GenericName rawName, boolean searchImport) {
|
public Entity resolveName(Entity fromEntity, GenericName rawName, boolean searchImport) {
|
||||||
if (rawName==null) return null;
|
if (rawName==null) return null;
|
||||||
Entity entity = resolveNameInternal(fromEntity,rawName,searchImport);
|
Entity entity = resolveNameInternal(fromEntity,rawName,searchImport);
|
||||||
|
@ -262,6 +228,7 @@ public class Inferer {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Entity lookupTypeInImported(FileEntity fileEntity, String name) {
|
public Entity lookupTypeInImported(FileEntity fileEntity, String name) {
|
||||||
if (fileEntity == null)
|
if (fileEntity == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -290,13 +257,8 @@ public class Inferer {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deduce type based on function calls
|
@Override
|
||||||
* If the function call is a subset of a type, then the type could be a candidate of the var's type
|
|
||||||
* @param fromEntity
|
|
||||||
* @param functionCalls
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<TypeEntity> calculateCandidateTypes(VarEntity fromEntity, List<FunctionCall> functionCalls) {
|
public List<TypeEntity> calculateCandidateTypes(VarEntity fromEntity, List<FunctionCall> functionCalls) {
|
||||||
if (buildInTypeManager.isBuildInTypeMethods(functionCalls)) {
|
if (buildInTypeManager.isBuildInTypeMethods(functionCalls)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -323,16 +285,14 @@ public class Inferer {
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isEagerExpressionResolve() {
|
public boolean isEagerExpressionResolve() {
|
||||||
return eagerExpressionResolve;
|
return eagerExpressionResolve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public EntityRepo getRepo() {
|
public EntityRepo getRepo() {
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCollectUnsolvedBindings(boolean isCollectUnsolvedBindings) {
|
|
||||||
this.isCollectUnsolvedBindings = isCollectUnsolvedBindings;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package depends.relations;
|
||||||
|
|
||||||
|
import depends.entity.*;
|
||||||
|
import depends.entity.repo.EntityRepo;
|
||||||
|
import depends.extractor.UnsolvedBindings;
|
||||||
|
import depends.importtypes.Import;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface IBindingResolver {
|
||||||
|
/**
|
||||||
|
* Resolve all bindings
|
||||||
|
* - Firstly, we resolve all types from there names.
|
||||||
|
* - Secondly, we resolve all expressions (expression will use type infomation of previous step
|
||||||
|
*/
|
||||||
|
Set<UnsolvedBindings> resolveAllBindings(boolean isEagerExpressionResolve);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different languages have different strategy on how to compute the imported types
|
||||||
|
* and the imported files.
|
||||||
|
* For example, in C/C++, both imported types (using namespace, using <type>) and imported files exists.
|
||||||
|
* while in java, only 'import class/function, or import wildcard class.* package.* exists.
|
||||||
|
*/
|
||||||
|
Collection<Entity> getImportedRelationEntities(List<Import> importedNames);
|
||||||
|
|
||||||
|
Collection<Entity> getImportedTypes(List<Import> importedNames, FileEntity fileEntity);
|
||||||
|
|
||||||
|
Collection<Entity> getImportedFiles(List<Import> importedNames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By given raw name, to infer the type of the name
|
||||||
|
* for example
|
||||||
|
* (It is just a wrapper of resolve name)
|
||||||
|
* if it is a class, the class is the type
|
||||||
|
* if it is a function, the return type is the type
|
||||||
|
* if it is a variable, type of variable is the type
|
||||||
|
* @param fromEntity
|
||||||
|
* @param rawName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
TypeEntity inferTypeFromName(Entity fromEntity, GenericName rawName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By given raw name, to infer the entity of the name
|
||||||
|
* @param fromEntity
|
||||||
|
* @param rawName
|
||||||
|
* @param searchImport
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Entity resolveName(Entity fromEntity, GenericName rawName, boolean searchImport);
|
||||||
|
|
||||||
|
Entity lookupTypeInImported(FileEntity fileEntity, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deduce type based on function calls
|
||||||
|
* If the function call is a subset of a type, then the type could be a candidate of the var's type
|
||||||
|
* @param fromEntity
|
||||||
|
* @param functionCalls
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TypeEntity> calculateCandidateTypes(VarEntity fromEntity, List<FunctionCall> functionCalls);
|
||||||
|
|
||||||
|
boolean isEagerExpressionResolve();
|
||||||
|
|
||||||
|
EntityRepo getRepo();
|
||||||
|
}
|
|
@ -40,8 +40,6 @@ public abstract class ImportLookupStrategy {
|
||||||
*
|
*
|
||||||
* @param name - the entity name
|
* @param name - the entity name
|
||||||
* @param fileEntity - the current file
|
* @param fileEntity - the current file
|
||||||
* @param repo - the whole entity repo, which could be used when necessary
|
|
||||||
* @param inferer - the inferer object, which could be used when necessary
|
|
||||||
* @return the founded entity, or null if not found.
|
* @return the founded entity, or null if not found.
|
||||||
*/
|
*/
|
||||||
public abstract Entity lookupImportedType(String name, FileEntity fileEntity);
|
public abstract Entity lookupImportedType(String name, FileEntity fileEntity);
|
||||||
|
@ -51,7 +49,6 @@ public abstract class ImportLookupStrategy {
|
||||||
* In C/CPP, it is calculated by the file name
|
* In C/CPP, it is calculated by the file name
|
||||||
* In Java, it is calculated by the imported types
|
* In Java, it is calculated by the imported types
|
||||||
* @param importedNames - the original name of the import relation
|
* @param importedNames - the original name of the import relation
|
||||||
* @param repo - entity repo
|
|
||||||
* @return the corresponding entities related with importedNames
|
* @return the corresponding entities related with importedNames
|
||||||
*/
|
*/
|
||||||
public abstract Collection<Entity> getImportedRelationEntities(List<Import> importedNames);
|
public abstract Collection<Entity> getImportedRelationEntities(List<Import> importedNames);
|
||||||
|
@ -59,7 +56,6 @@ public abstract class ImportLookupStrategy {
|
||||||
/**
|
/**
|
||||||
* The types been imported
|
* The types been imported
|
||||||
* @param importedNames
|
* @param importedNames
|
||||||
* @param repo
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract Collection<Entity> getImportedTypes(List<Import> importedNames,Set<UnsolvedBindings> unsolvedSymbols);
|
public abstract Collection<Entity> getImportedTypes(List<Import> importedNames,Set<UnsolvedBindings> unsolvedSymbols);
|
||||||
|
@ -67,7 +63,6 @@ public abstract class ImportLookupStrategy {
|
||||||
/**
|
/**
|
||||||
* The files been imported
|
* The files been imported
|
||||||
* @param importedNames
|
* @param importedNames
|
||||||
* @param repo
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract Collection<Entity> getImportedFiles(List<Import> importedNames);
|
public abstract Collection<Entity> getImportedFiles(List<Import> importedNames);
|
||||||
|
@ -78,12 +73,12 @@ public abstract class ImportLookupStrategy {
|
||||||
*/
|
*/
|
||||||
public abstract boolean supportGlobalNameLookup();
|
public abstract boolean supportGlobalNameLookup();
|
||||||
|
|
||||||
public void setInferer(Inferer inferer){
|
public void setBindingResolver(IBindingResolver bindingResolver){
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
}
|
}
|
||||||
public ImportLookupStrategy(EntityRepo repo){
|
public ImportLookupStrategy(EntityRepo repo){
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
}
|
}
|
||||||
protected EntityRepo repo;
|
protected EntityRepo repo;
|
||||||
protected Inferer inferer;
|
protected IBindingResolver bindingResolver;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,14 @@ import java.util.stream.Collectors;
|
||||||
public class RelationCounter {
|
public class RelationCounter {
|
||||||
|
|
||||||
private Collection<Entity> entities;
|
private Collection<Entity> entities;
|
||||||
private Inferer inferer;
|
private IBindingResolver bindingResolver;
|
||||||
private EntityRepo repo;
|
private EntityRepo repo;
|
||||||
private boolean callAsImpl;
|
private boolean callAsImpl;
|
||||||
private AbstractLangProcessor langProcessor;
|
private AbstractLangProcessor langProcessor;
|
||||||
|
|
||||||
public RelationCounter( EntityRepo repo, boolean callAsImpl, AbstractLangProcessor langProcessor,Inferer inferer) {
|
public RelationCounter(EntityRepo repo, boolean callAsImpl, AbstractLangProcessor langProcessor, IBindingResolver bindingResolver) {
|
||||||
this.entities = repo.getFileEntities();
|
this.entities = repo.getFileEntities();
|
||||||
this.inferer = inferer;
|
this.bindingResolver = bindingResolver;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.callAsImpl = callAsImpl;
|
this.callAsImpl = callAsImpl;
|
||||||
this.langProcessor = langProcessor;
|
this.langProcessor = langProcessor;
|
||||||
|
@ -93,9 +93,9 @@ public class RelationCounter {
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.reloadExpression(repo);
|
entity.reloadExpression(repo);
|
||||||
if (!inferer.isEagerExpressionResolve())
|
if (!bindingResolver.isEagerExpressionResolve())
|
||||||
{
|
{
|
||||||
entity.resolveExpressions(inferer);
|
entity.resolveExpressions(bindingResolver);
|
||||||
}
|
}
|
||||||
for (Expression expression:entity.expressionList()){
|
for (Expression expression:entity.expressionList()){
|
||||||
if (expression.isStatement()) {
|
if (expression.isStatement()) {
|
||||||
|
|
|
@ -5,7 +5,8 @@ import depends.entity.Entity;
|
||||||
import depends.entity.FunctionEntity;
|
import depends.entity.FunctionEntity;
|
||||||
import depends.entity.VarEntity;
|
import depends.entity.VarEntity;
|
||||||
import depends.entity.repo.EntityRepo;
|
import depends.entity.repo.EntityRepo;
|
||||||
import depends.relations.Inferer;
|
import depends.relations.BindingResolver;
|
||||||
|
import depends.relations.IBindingResolver;
|
||||||
import depends.relations.Relation;
|
import depends.relations.Relation;
|
||||||
import depends.relations.RelationCounter;
|
import depends.relations.RelationCounter;
|
||||||
import multilang.depends.util.file.TemporaryFile;
|
import multilang.depends.util.file.TemporaryFile;
|
||||||
|
@ -18,32 +19,32 @@ import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public abstract class ParserTest {
|
public abstract class ParserTest {
|
||||||
protected EntityRepo entityRepo ;
|
protected EntityRepo entityRepo ;
|
||||||
protected Inferer inferer ;
|
protected IBindingResolver bindingResolver;
|
||||||
protected AbstractLangProcessor langProcessor;
|
protected AbstractLangProcessor langProcessor;
|
||||||
|
|
||||||
protected void init(){
|
protected void init(){
|
||||||
entityRepo = langProcessor.getEntityRepo();
|
entityRepo = langProcessor.getEntityRepo();
|
||||||
inferer = new Inferer(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,false);
|
bindingResolver = new BindingResolver(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),true,false);
|
||||||
langProcessor.inferer = inferer;
|
langProcessor.bindingResolver = bindingResolver;
|
||||||
TemporaryFile.reset();
|
TemporaryFile.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init(boolean duckTypingDeduce){
|
protected void init(boolean duckTypingDeduce){
|
||||||
entityRepo = langProcessor.getEntityRepo();
|
entityRepo = langProcessor.getEntityRepo();
|
||||||
inferer = new Inferer(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,duckTypingDeduce);
|
bindingResolver = new BindingResolver(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,duckTypingDeduce);
|
||||||
langProcessor.inferer = inferer;
|
langProcessor.bindingResolver = bindingResolver;
|
||||||
TemporaryFile.reset();
|
TemporaryFile.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UnsolvedBindings> resolveAllBindings() {
|
public Set<UnsolvedBindings> resolveAllBindings() {
|
||||||
Set<UnsolvedBindings> result = inferer.resolveAllBindings(langProcessor);
|
Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve());
|
||||||
new RelationCounter(entityRepo,false,langProcessor,inferer).computeRelations();
|
new RelationCounter(entityRepo,false,langProcessor, bindingResolver).computeRelations();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<UnsolvedBindings> resolveAllBindings(boolean callAsImpl) {
|
protected Set<UnsolvedBindings> resolveAllBindings(boolean callAsImpl) {
|
||||||
Set<UnsolvedBindings> result = inferer.resolveAllBindings(langProcessor);
|
Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve());
|
||||||
new RelationCounter(entityRepo,callAsImpl,langProcessor,inferer).computeRelations();
|
new RelationCounter(entityRepo,callAsImpl,langProcessor, bindingResolver).computeRelations();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,6 @@ public abstract class CppParserTest extends ParserTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CppFileParser createParser(String src) {
|
public CppFileParser createParser(String src) {
|
||||||
return new CdtCppFileParser(src, entityRepo, preprocessorHandler,inferer,macroRepo );
|
return new CdtCppFileParser(src, entityRepo, preprocessorHandler, bindingResolver,macroRepo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ public abstract class GolangParserTest extends ParserTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoFileParser createParser(String src) {
|
public GoFileParser createParser(String src) {
|
||||||
return new GoFileParser(src,entityRepo, inferer);
|
return new GoFileParser(src,entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,6 @@ public abstract class JavaParserTest extends ParserTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
public JavaFileParser createParser(String src) {
|
public JavaFileParser createParser(String src) {
|
||||||
return new JavaFileParser(src,entityRepo, inferer);
|
return new JavaFileParser(src,entityRepo, bindingResolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ public class UnsolvedSymbolsTest extends JavaParserTest {
|
||||||
String src = "./src/test/resources/java-code-examples/UnsolvedSymbols/MissingImport.java";
|
String src = "./src/test/resources/java-code-examples/UnsolvedSymbols/MissingImport.java";
|
||||||
JavaFileParser parser = createParser(src);
|
JavaFileParser parser = createParser(src);
|
||||||
parser.parse();
|
parser.parse();
|
||||||
inferer.setCollectUnsolvedBindings(true);
|
|
||||||
Set<UnsolvedBindings> missing = resolveAllBindings();
|
Set<UnsolvedBindings> missing = resolveAllBindings();
|
||||||
assertEquals(1,missing.size());
|
assertEquals(1,missing.size());
|
||||||
assertEquals("a.b",missing.iterator().next().getRawName());
|
assertEquals("a.b",missing.iterator().next().getRawName());
|
||||||
|
|
|
@ -11,7 +11,6 @@ import depends.entity.FunctionEntity;
|
||||||
import depends.entity.TypeEntity;
|
import depends.entity.TypeEntity;
|
||||||
import depends.entity.VarEntity;
|
import depends.entity.VarEntity;
|
||||||
import depends.extractor.FileParser;
|
import depends.extractor.FileParser;
|
||||||
import depends.relations.Inferer;
|
|
||||||
|
|
||||||
public class RubyAssignedVariableTypeDedudceTest extends RubyParserTest {
|
public class RubyAssignedVariableTypeDedudceTest extends RubyParserTest {
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -9,7 +9,7 @@ import depends.deptypes.DependencyType;
|
||||||
import depends.entity.FunctionEntity;
|
import depends.entity.FunctionEntity;
|
||||||
import depends.extractor.FileParser;
|
import depends.extractor.FileParser;
|
||||||
|
|
||||||
public class RubyNameInfererTest extends RubyParserTest {
|
public class RubyNameIBindingResolverTest extends RubyParserTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
super.init();
|
super.init();
|
|
@ -17,7 +17,7 @@ public abstract class RubyParserTest extends ParserTest implements ParserCreator
|
||||||
|
|
||||||
public FileParser createFileParser(String src) {
|
public FileParser createFileParser(String src) {
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
return new JRubyFileParser(src,entityRepo, executor,new IncludedFileLocator(includePaths()), inferer, this);
|
return new JRubyFileParser(src,entityRepo, executor,new IncludedFileLocator(includePaths()), bindingResolver, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> includePaths() {
|
private List<String> includePaths() {
|
||||||
|
|
Loading…
Reference in New Issue