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
ACompilationUnit
representing 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 boolean
addAncestor(CompilationUnit unit)
Adds a newCompilationUnit
as direct inheritance ancestor (i.e., superclass, interface, or superinterface) of this unit.void
addInstance(Unit unit)
Adds the given unit as an instance of this one, thus marking the former as a type that inherits from the latter.boolean
addInterface(InterfaceUnit unit)
Adds a newInterfaceUnit
as interface of this unit.boolean
addSuperclass(ClassUnit unit)
Adds a newClassUnit
as superclass of this unit.boolean
canBeInstantiated()
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).java.util.Collection<CompilationUnit>
getImmediateAncestors()
Yields the collection ofCompilationUnit
s that are this unit directly inherits from, regardless of their type.java.util.List<InterfaceUnit>
getInterfaces()
Yields the list ofInterfaceUnit
s implemented by this class.java.util.List<ClassUnit>
getSuperclasses()
Yields the list ofClassUnit
s that this class inherits from.boolean
isInstanceOf(CompilationUnit unit)
Yieldstrue
if 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:CompilationUnit
Yields the collection ofCompilationUnit
s that are this unit directly inherits from, regardless of their type.- Specified by:
getImmediateAncestors
in classCompilationUnit
- Returns:
- the collection of units that are direct ancestors of this one
-
getSuperclasses
public java.util.List<ClassUnit> getSuperclasses()
Yields the list ofClassUnit
s that this class inherits from.- Returns:
- the superclasses
-
getInterfaces
public java.util.List<InterfaceUnit> getInterfaces()
Yields the list ofInterfaceUnit
s implemented by this class.- Returns:
- the interfaces
-
addSuperclass
public final boolean addSuperclass(ClassUnit unit)
Adds a newClassUnit
as superclass of this unit.- Parameters:
unit
- the unit to add- Returns:
true
if the collection of superclasses changed as a result of the call
-
addInterface
public final boolean addInterface(InterfaceUnit unit)
Adds a newInterfaceUnit
as interface of this unit.- Parameters:
unit
- the unit to add- Returns:
true
if the collection of interfaces changed as a result of the call
-
isInstanceOf
public boolean isInstanceOf(CompilationUnit unit)
Description copied from class:CompilationUnit
Yieldstrue
if 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:
isInstanceOf
in classCompilationUnit
- Parameters:
unit
- the other unit- Returns:
true
only if that condition holds
-
addInstance
public void addInstance(Unit unit) throws ProgramValidationException
Description copied from class:CompilationUnit
Adds the given unit as an instance of this one, thus marking the former as a type that inherits from the latter.- Specified by:
addInstance
in 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:Unit
Yieldstrue
if this unit can be instantiated,false
otherwise (e.g., interfaces, abstract classes).- Specified by:
canBeInstantiated
in classUnit
- Returns:
true
if this unit can be instantiated,false
otherwise
-
addAncestor
public boolean addAncestor(CompilationUnit unit)
Description copied from class:CompilationUnit
Adds a newCompilationUnit
as direct inheritance ancestor (i.e., superclass, interface, or superinterface) of this unit.- Specified by:
addAncestor
in classCompilationUnit
- Parameters:
unit
- the unit to add- Returns:
true
if the collection of ancestors changed as a result of the call
-
-