/*
Компилятор языка программирования
Объектно-ориентированный продвинутый векторный транслятор
Copyright © 2021, 2024 Малик Разработчик
Это свободная программа: вы можете перераспространять ее и/или изменять
ее на условиях Стандартной общественной лицензии GNU в том виде,
в каком она была опубликована Фондом свободного программного обеспечения;
либо версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.
Эта программа распространяется в надежде, что она будет полезной,
но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
общественной лицензии GNU.
Вы должны были получить копию Стандартной общественной лицензии GNU
вместе с этой программой. Если это не так, см.
<https://www.gnu.org/licenses/>.
*/
package ru.malik.elaborarer.avtoo.lang;
import avt.lang.array.*;
public class Package(RequiredReflectItem, Cloneable, Measureable, ObjectArray, AVTOOConstants)
{
public (Library parentLibrary, int visibility, String specialCanonicalName, Source source, int declarationPosition, int documentationPosition):
super(parentLibrary, visibility & MASK_VISIBILITY, specialCanonicalName, specialCanonicalName, source, declarationPosition, documentationPosition) {
}
public boolean isVisibleFrom(ClassType type) {
if(type == null)
{
throw new NullPointerException(String.format(avt.lang.package.getResourceString("null-pointer.argument"), new Object[] { "type" }));
}
if(type.parentProgramme != parentProgramme)
{
throw new IllegalArgumentException(package.getResourceString("type.not-same-programme.package"));
}
switch(visibility)
{
default:
/* Недостижимый код. Нужен только для того, чтобы избежать сообщений об ошибках от компилятора. */
throw new IllegalCompilerObjectStateException(/*этот пакет имеет неизвестную видимость*/);
case PUBLIC:
case PUBLISHED:
return true;
case PROTECTED:
case PACKAGE:
case RESERVED_PACKAGE:
Library library = type.parentLibrary;
return parentLibrary == library || library != null && !library.application;
case PRIVATE:
case SOURCE:
case RESERVED_SOURCE:
return parentLibrary == type.parentLibrary;
}
}
public ClassType createClassType(int attributes, String specialSimpleName, Source source, int declarationPosition, int documentationPosition, String outputPath) {
if(specialSimpleName == null)
{
throw new NullPointerException(String.format(avt.lang.package.getResourceString("null-pointer.argument"), new Object[] { "specialSimpleName" }));
}
if(specialSimpleName.isEmpty())
{
throw new IllegalArgumentException(package.getResourceString("illegal-argument.empty.type-name"));
}
if(specialSimpleName.endsWith("[]"))
{
throw new IllegalArgumentException(package.getResourceString("illegal-argument.ends-with-brackets.type-name"));
}
Library library = parentLibrary;
if(library != null && source != null && library.sources.indexOf(source) < 0)
{
throw new IllegalArgumentException(package.getResourceString("source.not-same-programme"));
}
attributes &= ~ATTR_PRIMITIVE;
Programme programme = parentProgramme;
ClassType result = programme == null ? null : programme.newClassType(this, attributes, specialSimpleName, source, declarationPosition, documentationPosition, outputPath);
if(result == null) result = new ClassType(this, attributes, specialSimpleName, source, declarationPosition, documentationPosition, outputPath);
appendChildItem(result);
if(programme != null) programme.appendType(result);
if(library != null) library.appendClass(result);
if(source != null) source.appendDeclared(result);
return result;
}
public final Type getChildItem(String specialCanonicalName) { return (Type) super.getChildItem(specialCanonicalName); }
public final Type getChildItem(String specialCanonicalName, boolean ignoreCase) { return (Type) super.getChildItem(specialCanonicalName, ignoreCase); }
public final Type getChildType(String specialCanonicalName) { return (Type) super.getChildItem(specialCanonicalName); }
public final Type getChildType(String specialCanonicalName, boolean ignoreCase) { return (Type) super.getChildItem(specialCanonicalName, ignoreCase); }
public final Type operator [](int index) { return (Type) super.operator [](index); }
protected void insertChildItem(ProgrammeItem item, int position) {
if(item != null && !(item instanceof Type))
{
throw new IllegalArgumentException(package.getResourceString("adding-item.not-a-type"));
}
super.insertChildItem(item, position);
}
protected String composeRecompilableName() { return specialCanonicalName; }
protected String composeFasmSimpleName() {
String name = specialCanonicalName;
return !name.isEmpty() ? name : FASMNAME_SYSTEM_PACKAGE;
}
protected String composeFasmFullName() { return fasmSimpleName; }
protected String composeFasmFileName() { return fasmSimpleName; }
}