Commit 0082e804 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - final classes cannot be extended


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 38497d6e
......@@ -38,10 +38,14 @@ type class BadExtends extends MinimalClass, MinimalAbstractClass, MinimalFinalCl
// dummy
}
type class @trait BadExtends2 extends MinimalFinalClass, MinimalTraitClass {
type class @trait BadExtends2 extends MinimalClass, MinimalTraitClass {
// dummy
}
type class BadExtends3 extends MinimalFinalClass() {
}
type class SuperClass {
var integer vl_a;
template MyUnion t_union := { a := 10 }
......
......@@ -35,6 +35,7 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
public final class ClassTypeReferenceList extends ASTNode implements ILocateableNode, IIncrementallyUpdateable {
private final String ONLYONNONTRAIT = "A class can only extend one non-trait class";
private final String TRAITEXTENDSTRAIT = "A trait class can only extend trait classes";
private final String FINALCANNOTBEEXTENDED = "A final class cannot be extended";
private Class_Type parentClass;
......@@ -92,6 +93,10 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
final Type type = deftype.getType(timestamp);
if (type instanceof Class_Type) {
final Class_Type extClass = (Class_Type)type;
if (extClass.isFinal()) {
classRef.getLocation().reportSemanticError(FINALCANNOTBEEXTENDED);
parentClass.setIsErroneous(true);
}
if (! extClass.isTrait()) {
nrNonTraitExtends++;
if (parentClass.isTrait()) {
......
......@@ -227,6 +227,22 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return isTrait;
}
/**
* Checks if the class is declared using the '@abstract' modifier
* @return
*/
public boolean isAbstract() {
return isAbstract;
}
/**
* Checks if the class is declared using the '@abstract' modifier
* @return
*/
public boolean isFinal() {
return isFinal;
}
@Override
public Identifier getComponentIdentifierByName(Identifier identifier) {
// TODO Auto-generated method stub
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(22);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(24);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 9;
......@@ -53,8 +53,11 @@ public class OOP_Semantic_tests {
for (i = 0; i < 2; i++) {
markersToCheck.add(new MarkerToCheck("A class can only extend one non-trait class", lineNum, IMarker.SEVERITY_ERROR));
}
markersToCheck.add(new MarkerToCheck("A final class cannot be extended", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("A trait class can only extend trait classes", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("A final class cannot be extended", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 15;
markersToCheck.add(new MarkerToCheck("Reference to non-existent field `nonexist' in union template for type `@classesNegativeSemantic.MyUnion'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment