|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
package com.github.javaparser.ast; |
|
|
|
import com.github.javaparser.*; |
|
import com.github.javaparser.ast.body.AnnotationDeclaration; |
|
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; |
|
import com.github.javaparser.ast.body.EnumDeclaration; |
|
import com.github.javaparser.ast.body.TypeDeclaration; |
|
import com.github.javaparser.ast.comments.Comment; |
|
import com.github.javaparser.ast.comments.JavadocComment; |
|
import com.github.javaparser.ast.expr.Name; |
|
import com.github.javaparser.ast.modules.ModuleDeclaration; |
|
import com.github.javaparser.ast.nodeTypes.NodeWithName; |
|
import com.github.javaparser.ast.observer.ObservableProperty; |
|
import com.github.javaparser.ast.visitor.CloneVisitor; |
|
import com.github.javaparser.ast.visitor.GenericVisitor; |
|
import com.github.javaparser.ast.visitor.VoidVisitor; |
|
import com.github.javaparser.metamodel.CompilationUnitMetaModel; |
|
import com.github.javaparser.metamodel.InternalProperty; |
|
import com.github.javaparser.metamodel.JavaParserMetaModel; |
|
import com.github.javaparser.metamodel.OptionalProperty; |
|
import com.github.javaparser.printer.Printer; |
|
import com.github.javaparser.printer.configuration.PrinterConfiguration; |
|
import com.github.javaparser.utils.ClassUtils; |
|
import com.github.javaparser.utils.CodeGenerationUtils; |
|
import com.github.javaparser.utils.Utils; |
|
import java.io.IOException; |
|
import java.nio.charset.Charset; |
|
import java.nio.file.Files; |
|
import java.nio.file.Path; |
|
import java.nio.file.Paths; |
|
import java.util.List; |
|
import java.util.Objects; |
|
import java.util.Optional; |
|
import java.util.function.Function; |
|
import java.util.stream.Collectors; |
|
import static com.github.javaparser.JavaToken.Kind.EOF; |
|
import static com.github.javaparser.Providers.UTF8; |
|
import static com.github.javaparser.Providers.provider; |
|
import static com.github.javaparser.Range.range; |
|
import static com.github.javaparser.StaticJavaParser.parseImport; |
|
import static com.github.javaparser.StaticJavaParser.parseName; |
|
import static com.github.javaparser.ast.Modifier.createModifierList; |
|
import static com.github.javaparser.utils.CodeGenerationUtils.subtractPaths; |
|
import static com.github.javaparser.utils.Utils.assertNotNull; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class CompilationUnit extends Node { |
|
|
|
private static final String JAVA_LANG = "java.lang"; |
|
|
|
@OptionalProperty |
|
private PackageDeclaration packageDeclaration; |
|
|
|
private NodeList<ImportDeclaration> imports; |
|
|
|
private NodeList<TypeDeclaration<?>> types; |
|
|
|
@OptionalProperty |
|
private ModuleDeclaration module; |
|
|
|
@InternalProperty |
|
private Storage storage; |
|
|
|
public CompilationUnit() { |
|
this(null, null, new NodeList<>(), new NodeList<>(), null); |
|
} |
|
|
|
public CompilationUnit(String packageDeclaration) { |
|
this(null, new PackageDeclaration(new Name(packageDeclaration)), new NodeList<>(), new NodeList<>(), null); |
|
} |
|
|
|
@AllFieldsConstructor |
|
public CompilationUnit(PackageDeclaration packageDeclaration, NodeList<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> types, ModuleDeclaration module) { |
|
this(null, packageDeclaration, imports, types, module); |
|
} |
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
|
public CompilationUnit(TokenRange tokenRange, PackageDeclaration packageDeclaration, NodeList<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> types, ModuleDeclaration module) { |
|
super(tokenRange); |
|
setPackageDeclaration(packageDeclaration); |
|
setImports(imports); |
|
setTypes(types); |
|
setModule(module); |
|
customInitialization(); |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
|
public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
|
return v.visit(this, arg); |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
|
public <A> void accept(final VoidVisitor<A> v, final A arg) { |
|
v.visit(this, arg); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit printer(Printer printer) { |
|
setData(PRINTER_KEY, printer); |
|
return this; |
|
} |
|
|
|
|
|
|
|
*/ |
|
@Override |
|
protected Printer getPrinter() { |
|
if (!containsData(PRINTER_KEY)) { |
|
|
|
Printer printer = createDefaultPrinter(); |
|
printer(printer); |
|
} |
|
return getData(PRINTER_KEY); |
|
} |
|
|
|
|
|
|
|
*/ |
|
@Override |
|
protected Printer getPrinter(PrinterConfiguration config) { |
|
Printer printer = getPrinter().setConfiguration(config); |
|
printer(printer); |
|
return printer; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Deprecated |
|
public List<Comment> getComments() { |
|
List<Comment> comments = this.getAllContainedComments(); |
|
this.getComment().ifPresent(comments::add); |
|
return comments; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public List<Comment> getAllComments() { |
|
List<Comment> comments = this.getAllContainedComments(); |
|
this.getComment().ifPresent(comments::add); |
|
return comments; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public NodeList<ImportDeclaration> getImports() { |
|
return imports; |
|
} |
|
|
|
public ImportDeclaration getImport(int i) { |
|
return getImports().get(i); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public Optional<PackageDeclaration> getPackageDeclaration() { |
|
return Optional.ofNullable(packageDeclaration); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public NodeList<TypeDeclaration<?>> getTypes() { |
|
return types; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public TypeDeclaration<?> getType(int i) { |
|
return getTypes().get(i); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public CompilationUnit setImports(final NodeList<ImportDeclaration> imports) { |
|
assertNotNull(imports); |
|
if (imports == this.imports) { |
|
return this; |
|
} |
|
notifyPropertyChange(ObservableProperty.IMPORTS, this.imports, imports); |
|
if (this.imports != null) |
|
this.imports.setParentNode(null); |
|
this.imports = imports; |
|
setAsParentNodeOf(imports); |
|
return this; |
|
} |
|
|
|
public CompilationUnit setImport(int i, ImportDeclaration imports) { |
|
getImports().set(i, imports); |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit addImport(ImportDeclaration importDeclaration) { |
|
if (importDeclaration.isAsterisk()) { |
|
getImports().removeIf(im -> Objects.equals(getImportPackageName(im).get(), getImportPackageName(importDeclaration).orElse(null))); |
|
} |
|
if (!isImplicitImport(importDeclaration) && getImports().stream().noneMatch(im -> im.equals(importDeclaration) || (im.isAsterisk() && Objects.equals(getImportPackageName(im).get(), getImportPackageName(importDeclaration).orElse(null))))) { |
|
getImports().add(importDeclaration); |
|
} |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private boolean isImplicitImport(ImportDeclaration importDeclaration) { |
|
Optional<Name> importPackageName = getImportPackageName(importDeclaration); |
|
if (importPackageName.isPresent()) { |
|
if (parseName(JAVA_LANG).equals(importPackageName.get())) { |
|
|
|
return true; |
|
} |
|
if (packageDeclaration != null) { |
|
|
|
Name currentPackageName = packageDeclaration.getName(); |
|
return currentPackageName.equals(importPackageName.get()); |
|
} |
|
return false; |
|
} else { |
|
|
|
return true; |
|
} |
|
} |
|
|
|
private static Optional<Name> getImportPackageName(ImportDeclaration importDeclaration) { |
|
return (importDeclaration.isAsterisk() ? new Name(importDeclaration.getName(), "*") : importDeclaration.getName()).getQualifier(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public CompilationUnit setPackageDeclaration(final PackageDeclaration packageDeclaration) { |
|
if (packageDeclaration == this.packageDeclaration) { |
|
return this; |
|
} |
|
notifyPropertyChange(ObservableProperty.PACKAGE_DECLARATION, this.packageDeclaration, packageDeclaration); |
|
if (this.packageDeclaration != null) |
|
this.packageDeclaration.setParentNode(null); |
|
this.packageDeclaration = packageDeclaration; |
|
setAsParentNodeOf(packageDeclaration); |
|
return this; |
|
} |
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public CompilationUnit setTypes(final NodeList<TypeDeclaration<?>> types) { |
|
assertNotNull(types); |
|
if (types == this.types) { |
|
return this; |
|
} |
|
notifyPropertyChange(ObservableProperty.TYPES, this.types, types); |
|
if (this.types != null) |
|
this.types.setParentNode(null); |
|
this.types = types; |
|
setAsParentNodeOf(types); |
|
return this; |
|
} |
|
|
|
public CompilationUnit setType(int i, TypeDeclaration<?> type) { |
|
NodeList<TypeDeclaration<?>> copy = new NodeList<>(); |
|
copy.addAll(getTypes()); |
|
getTypes().set(i, type); |
|
notifyPropertyChange(ObservableProperty.TYPES, copy, types); |
|
return this; |
|
} |
|
|
|
public CompilationUnit addType(TypeDeclaration<?> type) { |
|
NodeList<TypeDeclaration<?>> copy = new NodeList<>(); |
|
copy.addAll(getTypes()); |
|
getTypes().add(type); |
|
notifyPropertyChange(ObservableProperty.TYPES, copy, types); |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit setPackageDeclaration(String name) { |
|
setPackageDeclaration(new PackageDeclaration(parseName(name))); |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit addImport(String name) { |
|
return addImport(name, false, false); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit addImport(Class<?> clazz) { |
|
if (clazz.isArray()) { |
|
return addImport(clazz.getComponentType()); |
|
} |
|
if (ClassUtils.isPrimitiveOrWrapper(clazz) || JAVA_LANG.equals(clazz.getPackage().getName())) |
|
return this; |
|
else if (clazz.isAnonymousClass() || clazz.isLocalClass()) |
|
throw new IllegalArgumentException(clazz.getName() + " is an anonymous or local class therefore it can't be added with addImport"); |
|
return addImport(clazz.getCanonicalName()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit addImport(String name, boolean isStatic, boolean isAsterisk) { |
|
if (name == null) { |
|
return this; |
|
} |
|
final StringBuilder i = new StringBuilder("import "); |
|
if (isStatic) { |
|
i.append("static "); |
|
} |
|
i.append(name); |
|
if (isAsterisk) { |
|
i.append(".*"); |
|
} |
|
i.append(";"); |
|
return addImport(parseImport(i.toString())); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ClassOrInterfaceDeclaration addClass(String name) { |
|
return addClass(name, Modifier.Keyword.PUBLIC); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ClassOrInterfaceDeclaration addClass(String name, Modifier.Keyword... modifiers) { |
|
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration(createModifierList(modifiers), false, name); |
|
getTypes().add(classOrInterfaceDeclaration); |
|
return classOrInterfaceDeclaration; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ClassOrInterfaceDeclaration addInterface(String name) { |
|
return addInterface(name, Modifier.Keyword.PUBLIC); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ClassOrInterfaceDeclaration addInterface(String name, Modifier.Keyword... modifiers) { |
|
ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration(createModifierList(modifiers), true, name); |
|
getTypes().add(classOrInterfaceDeclaration); |
|
return classOrInterfaceDeclaration; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public EnumDeclaration addEnum(String name) { |
|
return addEnum(name, Modifier.Keyword.PUBLIC); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public EnumDeclaration addEnum(String name, Modifier.Keyword... modifiers) { |
|
EnumDeclaration enumDeclaration = new EnumDeclaration(createModifierList(modifiers), name); |
|
getTypes().add(enumDeclaration); |
|
return enumDeclaration; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AnnotationDeclaration addAnnotationDeclaration(String name) { |
|
return addAnnotationDeclaration(name, Modifier.Keyword.PUBLIC); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AnnotationDeclaration addAnnotationDeclaration(String name, Modifier.Keyword... modifiers) { |
|
AnnotationDeclaration annotationDeclaration = new AnnotationDeclaration(createModifierList(modifiers), name); |
|
getTypes().add(annotationDeclaration); |
|
return annotationDeclaration; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<ClassOrInterfaceDeclaration> getClassByName(String className) { |
|
return getTypes().stream().filter(type -> type.getNameAsString().equals(className) && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public List<ClassOrInterfaceDeclaration> getLocalDeclarationFromClassname(String className) { |
|
return findAll(ClassOrInterfaceDeclaration.class).stream().filter(cid -> cid.getFullyQualifiedName().get().endsWith(className)).collect(Collectors.toList()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<ClassOrInterfaceDeclaration> getInterfaceByName(String interfaceName) { |
|
return getTypes().stream().filter(type -> type.getNameAsString().equals(interfaceName) && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<EnumDeclaration> getEnumByName(String enumName) { |
|
return getTypes().stream().filter(type -> type.getNameAsString().equals(enumName) && type instanceof EnumDeclaration).findFirst().map(t -> (EnumDeclaration) t); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<String> getPrimaryTypeName() { |
|
return getStorage().map(Storage::getFileName).map(Utils::removeFileExtension); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<TypeDeclaration<?>> getPrimaryType() { |
|
return getPrimaryTypeName().flatMap(name -> getTypes().stream().filter(t -> t.getNameAsString().equals(name)).findFirst()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Optional<AnnotationDeclaration> getAnnotationDeclarationByName(String annotationName) { |
|
return getTypes().stream().filter(type -> type.getNameAsString().equals(annotationName) && type instanceof AnnotationDeclaration).findFirst().map(t -> (AnnotationDeclaration) t); |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
|
public boolean remove(Node node) { |
|
if (node == null) |
|
return false; |
|
for (int i = 0; i < imports.size(); i++) { |
|
if (imports.get(i) == node) { |
|
imports.remove(i); |
|
return true; |
|
} |
|
} |
|
if (module != null) { |
|
if (node == module) { |
|
removeModule(); |
|
return true; |
|
} |
|
} |
|
if (packageDeclaration != null) { |
|
if (node == packageDeclaration) { |
|
removePackageDeclaration(); |
|
return true; |
|
} |
|
} |
|
for (int i = 0; i < types.size(); i++) { |
|
if (types.get(i) == node) { |
|
types.remove(i); |
|
return true; |
|
} |
|
} |
|
return super.remove(node); |
|
} |
|
|
|
@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
|
public CompilationUnit removePackageDeclaration() { |
|
return setPackageDeclaration((PackageDeclaration) null); |
|
} |
|
|
|
|
|
|
|
*/ |
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public Optional<ModuleDeclaration> getModule() { |
|
return Optional.ofNullable(module); |
|
} |
|
|
|
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
|
public CompilationUnit setModule(final ModuleDeclaration module) { |
|
if (module == this.module) { |
|
return this; |
|
} |
|
notifyPropertyChange(ObservableProperty.MODULE, this.module, module); |
|
if (this.module != null) |
|
this.module.setParentNode(null); |
|
this.module = module; |
|
setAsParentNodeOf(module); |
|
return this; |
|
} |
|
|
|
@Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
|
public CompilationUnit removeModule() { |
|
return setModule((ModuleDeclaration) null); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Optional<Storage> getStorage() { |
|
return Optional.ofNullable(storage); |
|
} |
|
|
|
public CompilationUnit setStorage(Path path) { |
|
this.storage = new Storage(this, path); |
|
return this; |
|
} |
|
|
|
public CompilationUnit setStorage(Path path, Charset charset) { |
|
this.storage = new Storage(this, path, charset); |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public ModuleDeclaration setModule(String name) { |
|
final ModuleDeclaration module = new ModuleDeclaration(parseName(name), false); |
|
setModule(module); |
|
return module; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public void recalculatePositions() { |
|
if (!getTokenRange().isPresent()) { |
|
throw new IllegalStateException("Can't recalculate positions without tokens."); |
|
} |
|
Position cursor = Position.HOME; |
|
for (JavaToken t : getTokenRange().get()) { |
|
int tokenLength = t.getKind() == EOF.getKind() ? 0 : t.getText().length() - 1; |
|
t.setRange(range(cursor, cursor.right(tokenLength))); |
|
if (t.getCategory().isEndOfLine()) { |
|
cursor = cursor.nextLine(); |
|
} else { |
|
cursor = cursor.right(tokenLength + 1); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static class Storage { |
|
|
|
private final CompilationUnit compilationUnit; |
|
|
|
private final Path path; |
|
|
|
private final Charset encoding; |
|
|
|
private Storage(CompilationUnit compilationUnit, Path path) { |
|
this(compilationUnit, path, UTF8); |
|
} |
|
|
|
private Storage(CompilationUnit compilationUnit, Path path, Charset encoding) { |
|
this.compilationUnit = compilationUnit; |
|
this.path = path.toAbsolutePath(); |
|
this.encoding = encoding; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Path getPath() { |
|
return path; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public CompilationUnit getCompilationUnit() { |
|
return compilationUnit; |
|
} |
|
|
|
|
|
|
|
*/ |
|
public Charset getEncoding() { |
|
return encoding; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Path getSourceRoot() { |
|
final Optional<String> pkgAsString = compilationUnit.getPackageDeclaration().map(NodeWithName::getNameAsString); |
|
return pkgAsString.map(p -> Paths.get(CodeGenerationUtils.packageToPath(p))).map(pkg -> subtractPaths(getDirectory(), pkg)).orElse(getDirectory()); |
|
} |
|
|
|
public String getFileName() { |
|
return path.getFileName().toString(); |
|
} |
|
|
|
public Path getDirectory() { |
|
return path.getParent(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
public void save() { |
|
save(cu -> compilationUnit.getPrinter().print(cu)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void save(Function<CompilationUnit, String> makeOutput) { |
|
save(makeOutput, encoding); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void save(Function<CompilationUnit, String> makeOutput, Charset encoding) { |
|
try { |
|
Files.createDirectories(path.getParent()); |
|
final String code = makeOutput.apply(getCompilationUnit()); |
|
Files.write(path, code.getBytes(encoding)); |
|
} catch (IOException e) { |
|
throw new RuntimeException(e); |
|
} |
|
} |
|
|
|
public ParseResult<CompilationUnit> reparse(JavaParser javaParser) { |
|
try { |
|
return javaParser.parse(ParseStart.COMPILATION_UNIT, provider(getPath())); |
|
} catch (IOException e) { |
|
throw new RuntimeException(e); |
|
} |
|
} |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
|
public CompilationUnit clone() { |
|
return (CompilationUnit) accept(new CloneVisitor(), null); |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
|
public CompilationUnitMetaModel getMetaModel() { |
|
return JavaParserMetaModel.compilationUnitMetaModel; |
|
} |
|
|
|
@Override |
|
@Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
|
public boolean replace(Node node, Node replacementNode) { |
|
if (node == null) |
|
return false; |
|
for (int i = 0; i < imports.size(); i++) { |
|
if (imports.get(i) == node) { |
|
imports.set(i, (ImportDeclaration) replacementNode); |
|
return true; |
|
} |
|
} |
|
if (module != null) { |
|
if (node == module) { |
|
setModule((ModuleDeclaration) replacementNode); |
|
return true; |
|
} |
|
} |
|
if (packageDeclaration != null) { |
|
if (node == packageDeclaration) { |
|
setPackageDeclaration((PackageDeclaration) replacementNode); |
|
return true; |
|
} |
|
} |
|
for (int i = 0; i < types.size(); i++) { |
|
if (types.get(i) == node) { |
|
types.set(i, (TypeDeclaration) replacementNode); |
|
return true; |
|
} |
|
} |
|
return super.replace(node, replacementNode); |
|
} |
|
} |