use of abs.frontend.typechecker.KindedName in project abstools by abstools.
the class ClassKindTypeExtension method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
ClassDecl d = (ClassDecl) e.lookup(new KindedName(Kind.CLASS, e.getClassName()));
List<Annotation> anns = AnnotationHelper.getAnnotationsOfType(d.getAnnotations(), "ABS.StdLib.ClassKindAnnotation");
if (!anns.isEmpty()) {
String name = ((DataConstructorExp) anns.get(0).getValue()).getDecl().getName();
if (e.hasLocal()) {
if (name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_PLAIN, d.getName()));
}
} else {
if (!name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_COG, d.getName()));
}
}
}
}
use of abs.frontend.typechecker.KindedName in project abstools by abstools.
the class ABSCodeScanner method resolveTypeUse.
/**
* resolves the type use in the type checked model.
* @param tu
* @param typeCheckedModel
* @return the declaration or <b>null</b> if a {@link RuntimeException} occurs
*/
private ASTNode<?> resolveTypeUse(TypeUse tu, Model typeCheckedModel) {
try {
String tuname = tu.getName();
ModuleDecl moduleDecl = tu.getModuleDecl();
if (moduleDecl == null) {
// Looks like we're in a delta.
return tu;
}
ModuleDecl typecheckedMDecl = typeCheckedModel.lookupModule(moduleDecl.getName());
if (typecheckedMDecl == null)
return tu;
Decl declNode = typecheckedMDecl.lookup(new KindedName(Kind.TYPE_DECL, tuname));
if (declNode instanceof TypeSynDecl) {
TypeSynDecl tsd = (TypeSynDecl) declNode;
return resolveTypeUse(tsd.getValue(), typeCheckedModel);
}
return declNode;
} catch (RuntimeException e) {
// better make sure that can not happen
if (doDebug)
e.printStackTrace();
return null;
}
}
use of abs.frontend.typechecker.KindedName in project abstools by abstools.
the class ProposalFactory method addToplevelProposals.
/**
* add proposals for all visible names.
* @param node the node under the cursor
*/
private void addToplevelProposals(ASTNode<?> node) {
ProposalComparator comp = new ProposalComparator();
ArrayList<ICompletionProposal> tempNonqual = new ArrayList<ICompletionProposal>();
ArrayList<ICompletionProposal> tempQual = new ArrayList<ICompletionProposal>();
ModuleDecl moddecl = node.getModuleDecl();
if (moddecl == null) {
return;
}
try {
Map<KindedName, ResolvedName> visibleNames = moddecl.getVisibleNames();
for (Entry<KindedName, ResolvedName> kentry : visibleNames.entrySet()) {
KindedName kname = kentry.getKey();
if (qualifierIsPrefixOf(kname.getName())) {
CompletionProposal proposal = makeVisibleNameProposal(kentry.getValue(), kname);
if (kname.isQualified()) {
tempQual.add(proposal);
} else {
tempNonqual.add(proposal);
}
}
}
Collections.sort(tempNonqual, comp);
proposals.addAll(tempNonqual);
Collections.sort(tempQual, comp);
proposals.addAll(tempQual);
} catch (TypeCheckerException e) {
// ignore all type check exceptions
}
}
use of abs.frontend.typechecker.KindedName in project abstools by abstools.
the class TypingTest method testFieldUse.
@Test
public void testFieldUse() {
Model m = assertParseOkStdLib(" class C { Bool f; Bool m() { return this.f; } }");
ClassDecl d = (ClassDecl) m.lookup(new KindedName(Kind.CLASS, "UnitTest.C"));
FieldDecl f = d.getField(0);
ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
assertEquals(f.getType(), s.getRetExp().getType());
}
use of abs.frontend.typechecker.KindedName in project abstools by abstools.
the class TypingTest method testNew.
@Test
public void testNew() {
Model m = assertParseOk("interface I {} class C implements I {} { I i; i = new local C(); }");
assertEquals(m.lookup(new KindedName(Kind.TYPE_DECL, "UnitTest.I")).getType(), ((UnionType) getTypeOfFirstAssignment(m)).getType(0));
}
Aggregations