Package it.unive.lisa.program
Class ClassUnit
- java.lang.Object
-
- it.unive.lisa.program.Unit
-
- it.unive.lisa.program.ProgramUnit
-
- it.unive.lisa.program.CompilationUnit
-
- it.unive.lisa.program.ClassUnit
-
- All Implemented Interfaces:
CodeElement
- Direct Known Subclasses:
AbstractClassUnit
public class ClassUnit extends CompilationUnit
ACompilationUnitrepresenting a concrete class that can be instantiated.
-
-
Field Summary
-
Fields inherited from class it.unive.lisa.program.CompilationUnit
instances
-
-
Constructor Summary
Constructors Constructor Description ClassUnit(CodeLocation location, Program program, java.lang.String name, boolean sealed)Builds a compilation unit, defined at the given program point.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAncestor(CompilationUnit unit)Adds a newCompilationUnitas direct inheritance ancestor (i.e., superclass, interface, or superinterface) of this unit.voidaddInstance(Unit unit)Adds the given unit as an instance of this one, thus marking the former as a type that inherits from the latter.booleanaddInterface(InterfaceUnit unit)Adds a newInterfaceUnitas interface of this unit.booleanaddSuperclass(ClassUnit unit)Adds a newClassUnitas superclass of this unit.booleancanBeInstantiated()Yieldstrueif this unit can be instantiated,falseotherwise (e.g., interfaces, abstract classes).java.util.Collection<CompilationUnit>getImmediateAncestors()Yields the collection ofCompilationUnits that are this unit directly inherits from, regardless of their type.java.util.List<InterfaceUnit>getInterfaces()Yields the list ofInterfaceUnits implemented by this class.java.util.List<ClassUnit>getSuperclasses()Yields the list ofClassUnits that this class inherits from.booleanisInstanceOf(CompilationUnit unit)Yieldstrueif and only if this unit is an instance of the given one.-
Methods inherited from class it.unive.lisa.program.CompilationUnit
addAnnotation, addInstanceCodeMember, addInstanceGlobal, getAbstractCodeMembers, getAnnotations, getCodeMembersRecursively, getGlobalsRecursively, getInstanceCFGs, getInstanceCodeMember, getInstanceCodeMembers, getInstanceCodeMembersByName, getInstanceConstructs, getInstanceGlobal, getInstanceGlobals, getInstances, getMatchingInstanceCodeMembers, isSealed, searchCodeMembers, searchGlobals
-
Methods inherited from class it.unive.lisa.program.ProgramUnit
getLocation, getProgram
-
Methods inherited from class it.unive.lisa.program.Unit
addCodeMember, addGlobal, getCodeMember, getCodeMembers, getCodeMembersByName, getGlobal, getGlobals, getMatchingCodeMember, getName, toString
-
-
-
-
Constructor Detail
-
ClassUnit
public ClassUnit(CodeLocation location, Program program, java.lang.String name, boolean sealed)
Builds a compilation unit, defined at the given program point.- Parameters:
location- the location where the unit is define within the source fileprogram- the program where this unit is definedname- the name of the unitsealed- whether or not this unit is sealed, meaning that it cannot be used as super unit of other compilation units
-
-
Method Detail
-
getImmediateAncestors
public java.util.Collection<CompilationUnit> getImmediateAncestors()
Description copied from class:CompilationUnitYields the collection ofCompilationUnits that are this unit directly inherits from, regardless of their type.- Specified by:
getImmediateAncestorsin classCompilationUnit- Returns:
- the collection of units that are direct ancestors of this one
-
getSuperclasses
public java.util.List<ClassUnit> getSuperclasses()
Yields the list ofClassUnits that this class inherits from.- Returns:
- the superclasses
-
getInterfaces
public java.util.List<InterfaceUnit> getInterfaces()
Yields the list ofInterfaceUnits implemented by this class.- Returns:
- the interfaces
-
addSuperclass
public final boolean addSuperclass(ClassUnit unit)
Adds a newClassUnitas superclass of this unit.- Parameters:
unit- the unit to add- Returns:
trueif the collection of superclasses changed as a result of the call
-
addInterface
public final boolean addInterface(InterfaceUnit unit)
Adds a newInterfaceUnitas interface of this unit.- Parameters:
unit- the unit to add- Returns:
trueif the collection of interfaces changed as a result of the call
-
isInstanceOf
public boolean isInstanceOf(CompilationUnit unit)
Description copied from class:CompilationUnitYieldstrueif and only if this unit is an instance of the given one. This method works correctly even ifProgramValidationLogic.validateAndFinalize(Program)has not been invoked yet, and thus the if collection of instances of the given unit is not yet available.- Specified by:
isInstanceOfin classCompilationUnit- Parameters:
unit- the other unit- Returns:
trueonly if that condition holds
-
addInstance
public void addInstance(Unit unit) throws ProgramValidationException
Description copied from class:CompilationUnitAdds the given unit as an instance of this one, thus marking the former as a type that inherits from the latter.- Specified by:
addInstancein classCompilationUnit- Parameters:
unit- the unit to be added- Throws:
ProgramValidationException- if the given unit cannot be added
-
canBeInstantiated
public boolean canBeInstantiated()
Description copied from class:UnitYieldstrueif this unit can be instantiated,falseotherwise (e.g., interfaces, abstract classes).- Specified by:
canBeInstantiatedin classUnit- Returns:
trueif this unit can be instantiated,falseotherwise
-
addAncestor
public boolean addAncestor(CompilationUnit unit)
Description copied from class:CompilationUnitAdds a newCompilationUnitas direct inheritance ancestor (i.e., superclass, interface, or superinterface) of this unit.- Specified by:
addAncestorin classCompilationUnit- Parameters:
unit- the unit to add- Returns:
trueif the collection of ancestors changed as a result of the call
-
-