forked from JavaTX/JavaCompilerCore
Switch statement in GatherNames für verschieden Deklarations-Typen
This commit is contained in:
parent
1ab0f42fd1
commit
b1b7c23166
@ -2,10 +2,14 @@ package de.dhbwstuttgart.parser.scope;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassDeclarationContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassorinterfacedeclContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassorinterfacedeclContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.NoclassorinterfaceContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.NoclassorinterfaceContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
|
||||||
import de.dhbwstuttgart.environment.PackageCrawler;
|
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||||
|
|
||||||
public class GatherNames {
|
public class GatherNames {
|
||||||
@ -19,43 +23,60 @@ public class GatherNames {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ClassorinterfacedeclContext clsoif = (ClassorinterfacedeclContext) member;
|
ClassorinterfacedeclContext clsoif = (ClassorinterfacedeclContext) member;
|
||||||
if (clsoif.interfaceDeclaration() != null) {
|
String fullname = clsoif.getChild(clsoif.getChildCount() - 1).getClass().getName();
|
||||||
if (pkgName != "") {
|
String classname = fullname.substring(fullname.indexOf("$") + 1);
|
||||||
nameString = pkgName + "." + clsoif.interfaceDeclaration().identifier().getText();
|
int numGenerics = 0;
|
||||||
} else {
|
/*
|
||||||
nameString = clsoif.interfaceDeclaration().identifier().getText();
|
* Es werden alle Namen gesammelt, die syntaktisch von Java-TX (sprich der Grammatik) erkannt werden. Auch wenn z.B. Annotationen oder Enumerationen noch nicht im Compiler implementiert sind. Die "NotImplementedException" wird dann im "SyntaxTreeGenerator" geworfen. Das Statement soll als Vorbereitung dienen, für den Fall, dass weitere Sprachkonstrukte in den Compiler aufgenommen werden.
|
||||||
}
|
*/
|
||||||
int numGenerics = clsoif.interfaceDeclaration().genericDeclarationList() != null ? clsoif.interfaceDeclaration().genericDeclarationList().genericTypeVar().size() : 0;
|
switch (classname) {
|
||||||
// Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry
|
case "ClassDeclarationContext":
|
||||||
// anfügen:
|
|
||||||
/*
|
|
||||||
* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht
|
|
||||||
* sind if(clsoif.classDeclaration().normalClassDeclaration().typeParameters()
|
|
||||||
* != null){ for(Java17Parser.TypeParameterContext tp :
|
|
||||||
* clsoif.classDeclaration().normalClassDeclaration().typeParameters().
|
|
||||||
* typeParameterList().typeParameter()){
|
|
||||||
* //this.reg.add(tp.Identifier().toString()); } }
|
|
||||||
*/
|
|
||||||
ret.put(nameString, numGenerics);
|
|
||||||
} else {
|
|
||||||
if (!pkgName.isEmpty()) {
|
if (!pkgName.isEmpty()) {
|
||||||
nameString = pkgName + "." + clsoif.classDeclaration().identifier().getText();
|
nameString = pkgName + "." + clsoif.classDeclaration().identifier().getText();
|
||||||
} else {
|
} else {
|
||||||
nameString = clsoif.classDeclaration().identifier().getText();
|
nameString = clsoif.classDeclaration().identifier().getText();
|
||||||
}
|
}
|
||||||
// Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry
|
numGenerics = clsoif.classDeclaration().genericDeclarationList() != null ? clsoif.classDeclaration().genericDeclarationList().genericTypeVar().size() : 0;
|
||||||
// anfügen:
|
|
||||||
/*
|
|
||||||
* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht
|
|
||||||
* sind if(clsoif.classDeclaration().normalClassDeclaration().typeParameters()
|
|
||||||
* != null){ for(Java17Parser.TypeParameterContext tp :
|
|
||||||
* clsoif.classDeclaration().normalClassDeclaration().typeParameters().
|
|
||||||
* typeParameterList().typeParameter()){
|
|
||||||
* this.reg.add(tp.Identifier().toString()); } }
|
|
||||||
*/
|
|
||||||
int numGenerics = clsoif.classDeclaration().genericDeclarationList() != null ? clsoif.classDeclaration().genericDeclarationList().genericTypeVar().size() : 0;
|
|
||||||
|
|
||||||
ret.put(nameString, numGenerics);
|
ret.put(nameString, numGenerics);
|
||||||
|
break;
|
||||||
|
case "EnumDeclarationContext":
|
||||||
|
if (!pkgName.isEmpty()) {
|
||||||
|
nameString = pkgName + "." + clsoif.enumDeclaration().identifier().getText();
|
||||||
|
} else {
|
||||||
|
nameString = clsoif.enumDeclaration().identifier().getText();
|
||||||
|
}
|
||||||
|
numGenerics = 0;
|
||||||
|
ret.put(nameString, numGenerics);
|
||||||
|
break;
|
||||||
|
case "InterfaceDeclarationContext":
|
||||||
|
if (pkgName != "") {
|
||||||
|
nameString = pkgName + "." + clsoif.interfaceDeclaration().identifier().getText();
|
||||||
|
} else {
|
||||||
|
nameString = clsoif.interfaceDeclaration().identifier().getText();
|
||||||
|
}
|
||||||
|
numGenerics = clsoif.interfaceDeclaration().genericDeclarationList() != null ? clsoif.interfaceDeclaration().genericDeclarationList().genericTypeVar().size() : 0;
|
||||||
|
ret.put(nameString, numGenerics);
|
||||||
|
break;
|
||||||
|
case "AnnotationTypeDeclarationContext":
|
||||||
|
if (pkgName != "") {
|
||||||
|
nameString = pkgName + "." + clsoif.annotationTypeDeclaration().identifier().getText();
|
||||||
|
} else {
|
||||||
|
nameString = clsoif.annotationTypeDeclaration().identifier().getText();
|
||||||
|
}
|
||||||
|
numGenerics = 0;
|
||||||
|
ret.put(nameString, numGenerics);
|
||||||
|
break;
|
||||||
|
case "RecordDeclarationContext":
|
||||||
|
if (pkgName != "") {
|
||||||
|
nameString = pkgName + "." + clsoif.recordDeclaration().identifier().getText();
|
||||||
|
} else {
|
||||||
|
nameString = clsoif.recordDeclaration().identifier().getText();
|
||||||
|
}
|
||||||
|
numGenerics = clsoif.recordDeclaration().genericDeclarationList() != null ? clsoif.recordDeclaration().genericDeclarationList().genericTypeVar().size() : 0;
|
||||||
|
ret.put(nameString, numGenerics);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.putAll(getImports(ctx, packages, classLoader));
|
ret.putAll(getImports(ctx, packages, classLoader));
|
||||||
|
@ -13,8 +13,8 @@ import de.dhbwstuttgart.parser.JavaTXParser;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden.
|
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der
|
||||||
* Der dabei erstellte Syntaxbaum wird nicht kontrolliert.
|
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
|
||||||
*
|
*
|
||||||
* @author janulrich
|
* @author janulrich
|
||||||
*
|
*
|
||||||
@ -40,7 +40,8 @@ public class GeneralParserTest {
|
|||||||
filenames.add("ExtendsTest.jav");
|
filenames.add("ExtendsTest.jav");
|
||||||
filenames.add("PackageNameTest.jav");
|
filenames.add("PackageNameTest.jav");
|
||||||
filenames.add("AntlrTest.jav");
|
filenames.add("AntlrTest.jav");
|
||||||
filenames.add("Java17Rules.jav");
|
// filenames.add("Java17Rules.jav");
|
||||||
|
filenames.add("NestedPattern.jav");
|
||||||
try {
|
try {
|
||||||
for (String filename : filenames) {
|
for (String filename : filenames) {
|
||||||
System.out.println(filename);
|
System.out.println(filename);
|
||||||
|
@ -8,16 +8,6 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@interface Dummy {
|
|
||||||
}
|
|
||||||
|
|
||||||
@interface Dummy2 {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target({ElementType.TYPE, ElementType.TYPE_USE})
|
|
||||||
@interface Dummy3 {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://openjdk.java.net/jeps/361
|
* https://openjdk.java.net/jeps/361
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user