Skip to content

Commit

Permalink
A few parser things
Browse files Browse the repository at this point in the history
  • Loading branch information
Bl3nd committed Oct 13, 2024
1 parent c4ae849 commit 789ceda
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ else if (scope instanceof EnclosedExpr)
packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/');

// For this purpose, we do not care about its line, columnStart or columnEnd
container.putClassReference(className, new ClassReferenceLocation(getOwner(container), packageName,
container.putClassReference(className, new ClassReferenceLocation(className, packageName,
fieldValue.name, "reference", -1, -1, -1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.javaparser.ast.type.TypeParameter;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
Expand Down Expand Up @@ -294,7 +295,7 @@ public void visit(ClassOrInterfaceDeclaration n, Object arg)

ResolvedReferenceTypeDeclaration resolve = n.resolve();
this.classFileContainer.putClassReference(resolve.getName(),
new ClassReferenceLocation(getOwner(classFileContainer),
new ClassReferenceLocation(resolve.getName(),
resolve.getPackageName(), "", "declaration", value.line, value.columnStart, value.columnEnd + 1));
}
catch (Exception e)
Expand Down Expand Up @@ -343,9 +344,22 @@ public void visit(ClassOrInterfaceType n, Object arg)
if (qualifiedName.contains("."))
packagePath = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/');

this.classFileContainer.putClassReference(classValue.name,
new ClassReferenceLocation(getOwner(classFileContainer),
packagePath, "", "reference", classValue.line, classValue.columnStart, classValue.columnEnd + 1));
ClassOrInterfaceType classScope = n.getScope().orElse(null);
if (classScope == null)
{
this.classFileContainer.putClassReference(classValue.name,
new ClassReferenceLocation(classValue.name,
packagePath, "", "reference", classValue.line, classValue.columnStart,
classValue.columnEnd + 1));
}
else
{
packagePath = packagePath.substring(0, packagePath.lastIndexOf("/"));

this.classFileContainer.putClassReference(classValue.name,
new ClassReferenceLocation(classScope.getNameAsString(), packagePath, "", "reference",
classValue.line, classValue.columnStart, classValue.columnEnd + 1));
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -459,6 +473,19 @@ public void visit(DoStmt n, Object arg)
public void visit(EnumDeclaration n, Object arg)
{
super.visit(n, arg);

ResolvedEnumDeclaration resolve = n.resolve();

Range enumClassNameRange = n.getName().getRange().orElse(null);
if (enumClassNameRange == null)
return;

Value enumClassValue = new Value(n.getName(), enumClassNameRange);

this.classFileContainer.putClassReference(enumClassValue.name,
new ClassReferenceLocation(getOwner(classFileContainer), resolve.getPackageName(), "", "declaration",
enumClassValue.line, enumClassValue.columnStart, enumClassValue.columnEnd + 1));

n.getEntries().forEach(entry ->
{
SimpleName simpleName = entry.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.javaparser.ast.stmt.Statement;
import com.github.javaparser.ast.stmt.TryStmt;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
import com.github.javaparser.resolution.types.ResolvedType;
Expand Down Expand Up @@ -143,9 +144,14 @@ static void putClassResolvedValues(ClassFileContainer container, Expression visi
if (qualifiedName.contains("."))
packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/');

container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), packageName
ResolvedReferenceTypeDeclaration resolvedReferenceTypeDeclaration = resolvedType.asReferenceType().getTypeDeclaration().orElse(null);
assert resolvedReferenceTypeDeclaration != null;
if (resolvedReferenceTypeDeclaration.getClassName().contains("."))
packageName = packageName.substring(0, packageName.lastIndexOf('/'));

container.putClassReference(className, new ClassReferenceLocation(className, packageName
, fieldValue.name, "reference", scopeValue.line, scopeValue.columnStart, scopeValue.columnEnd + 1));
container.putField(fieldValue.name, new ClassFieldLocation(scopeValue.name, "reference", fieldValue.line,
container.putField(fieldValue.name, new ClassFieldLocation(className, "reference", fieldValue.line,
fieldValue.columnStart, fieldValue.columnEnd + 1));
}

Expand Down Expand Up @@ -174,7 +180,7 @@ static void putClassResolvedValues(ClassFileContainer container, Expression visi
if (qualifiedName.contains("."))
packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.')).replace('.', '/');

container.putClassReference(className, new ClassReferenceLocation(ParserUtil.getOwner(container), packageName
container.putClassReference(className, new ClassReferenceLocation(className, packageName
, "", "reference", scopeValue.line, scopeValue.columnStart, scopeValue.columnEnd + 1));
}

Expand Down

0 comments on commit 789ceda

Please sign in to comment.