Package it.unive.lisa.program
Class InterfaceUnit
- java.lang.Object
-
- it.unive.lisa.program.Unit
-
- it.unive.lisa.program.ProgramUnit
-
- it.unive.lisa.program.CompilationUnit
-
- it.unive.lisa.program.InterfaceUnit
-
- All Implemented Interfaces:
CodeElement
public class InterfaceUnit extends CompilationUnit
A interface unit of the program to analyze. A interface unit is aUnit
that only defines instance members, from which other units (bothClassUnit
andInterfaceUnit
) can inherit from
-
-
Field Summary
-
Fields inherited from class it.unive.lisa.program.CompilationUnit
instances
-
-
Constructor Summary
Constructors Constructor Description InterfaceUnit(CodeLocation location, Program program, java.lang.String name, boolean sealed)
Builds an interface unit, defined at the given location.
-
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
addSuperinterface(InterfaceUnit unit)
Adds the givenInterfaceUnit
to the list of direct ancestors of this interface.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.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
-
InterfaceUnit
public InterfaceUnit(CodeLocation location, Program program, java.lang.String name, boolean sealed)
Builds an interface unit, defined at the given location.- 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 can be inherited from
-
-
Method Detail
-
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
-
addSuperinterface
public boolean addSuperinterface(InterfaceUnit unit)
Adds the givenInterfaceUnit
to the list of direct ancestors of this interface.- Parameters:
unit
- the unit to add- Returns:
true
only if the list has changed
-
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
-
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
-
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
-
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
-
-