use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ModuleVisitor method visit.
@Override
public void visit(Tree.ImportModule that) {
super.visit(that);
String version = getVersionString(that.getVersion(), that.getConstantVersion(), that);
if (that.getVersion() == null && version != null) {
that.setVersion(new Tree.QuotedLiteral(new CommonToken(STRING_LITERAL, "\"" + version + "\"")));
}
List<String> name;
Node node;
Tree.ImportPath importPath = that.getImportPath();
Tree.QuotedLiteral quotedLiteral = that.getQuotedLiteral();
if (importPath != null) {
name = getNameAsList(importPath);
node = importPath;
} else if (quotedLiteral != null) {
String nameString = getNameString(quotedLiteral);
name = asList(nameString.split("\\."));
node = quotedLiteral;
} else {
name = Collections.emptyList();
node = null;
}
if (node != null) {
Tree.QuotedLiteral artifact = that.getArtifact();
if (artifact != null) {
name = new ArrayList<String>(name);
String nameString = getNameString(artifact);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
Tree.QuotedLiteral classifier = that.getClassifier();
if (classifier != null) {
String nameString = getNameString(classifier);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
}
if (phase == Phase.SRC_MODULE) {
String path = formatPath(name);
that.setName(path);
} else if (phase == Phase.REMAINING) {
// set in previous phase
String path = that.getName();
Tree.Identifier ns = that.getNamespace();
String namespace = ns != null ? ns.getText() : null;
boolean hasMavenName = isMavenModule(path);
boolean forCeylon = (importPath != null && namespace == null) || (importPath == null && namespace == null && !hasMavenName) || DefaultRepository.NAMESPACE.equals(namespace);
if (name.isEmpty()) {
that.addError("missing module name");
} else if (name.get(0).equals(DEFAULT_MODULE_NAME)) {
if (forCeylon) {
node.addError("reserved module name: 'default'");
}
} else if (name.size() == 1 && name.get(0).equals("ceylon")) {
if (forCeylon) {
node.addError("reserved module name: 'ceylon'");
}
} else if (name.size() > 1 && name.get(0).equals("ceylon") && name.get(1).equals("language")) {
if (forCeylon) {
node.addError("the language module is imported implicitly");
}
} else {
if (namespace == null && hasMavenName) {
namespace = MavenRepository.NAMESPACE;
node.addUsageWarning(Warning.missingImportPrefix, "use of old style Maven imports is deprecated, prefix with 'maven:'");
}
Tree.AnnotationList al = that.getAnnotationList();
Unit u = unit.getUnit();
Backends bs = getNativeBackend(al, u);
if (!bs.none()) {
for (Backend b : bs) {
if (!b.isRegistered()) {
node.addError("illegal native backend name: '\"" + b.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
}
}
if (!moduleBackends.none() && !moduleBackends.supports(bs)) {
node.addError("native backend name on import conflicts with module descriptor: '\"" + bs.names() + "\"' is not in '\"" + moduleBackends.names() + "\"'");
}
}
Module importedModule = moduleManager.getOrCreateModule(name, version);
if (importPath != null) {
importPath.setModel(importedModule);
}
if (!completeOnlyAST && mainModule != null) {
if (importedModule.getVersion() == null) {
importedModule.setVersion(version);
}
ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
if (moduleImport == null) {
boolean optional = hasAnnotation(al, "optional", u);
boolean export = hasAnnotation(al, "shared", u);
moduleImport = new ModuleImport(namespace, importedModule, optional, export, bs);
moduleImport.getAnnotations().clear();
buildAnnotations(al, moduleImport.getAnnotations());
mainModule.addImport(moduleImport);
}
moduleManagerUtil.addModuleDependencyDefinition(moduleImport, that);
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class RefinementVisitor method checkRefinedTypeAndParameterTypes.
/*private boolean refinesOverloaded(Declaration dec,
Declaration refined, Type st) {
Functional fun1 = (Functional) dec;
Functional fun2 = (Functional) refined;
if (fun1.getParameterLists().size()!=1 ||
fun2.getParameterLists().size()!=1) {
return false;
}
List<Parameter> pl1 = fun1.getParameterLists()
.get(0).getParameters();
List<Parameter> pl2 = fun2.getParameterLists()
.get(0).getParameters();
if (pl1.size()!=pl2.size()) {
return false;
}
for (int i=0; i<pl1.size(); i++) {
Parameter p1 = pl1.get(i);
Parameter p2 = pl2.get(i);
if (p1==null || p2==null ||
p1.getType()==null ||
p2.getType()==null) {
return false;
}
else {
Type p2st = p2.getType()
.substitute(st.getTypeArguments());
if (!matches(p1.getType(), p2st, dec.getUnit())) {
return false;
}
}
}
return true;
}*/
private void checkRefinedTypeAndParameterTypes(Tree.Declaration that, Declaration refining, ClassOrInterface ci, Declaration refined) {
List<TypeParameter> refinedTypeParams = refined.getTypeParameters();
List<TypeParameter> refiningTypeParams = refining.getTypeParameters();
checkRefiningMemberTypeParameters(that, refining, refined, refinedTypeParams, refiningTypeParams);
List<Type> typeArgs = checkRefiningMemberUpperBounds(that, ci, refined, refinedTypeParams, refiningTypeParams);
Type cit = ci.getType();
Reference refinedMember = cit.getTypedReference(refined, typeArgs);
Reference refiningMember = cit.getTypedReference(refining, typeArgs);
Declaration refinedMemberDec = refinedMember.getDeclaration();
Declaration refiningMemberDec = refiningMember.getDeclaration();
Node typeNode = getTypeErrorNode(that);
if (refinedMemberIsDynamicallyTyped(refinedMemberDec, refiningMemberDec)) {
checkRefiningMemberDynamicallyTyped(refined, refiningMemberDec, typeNode);
} else if (refiningMemberIsDynamicallyTyped(refinedMemberDec, refiningMemberDec)) {
checkRefinedMemberDynamicallyTyped(refined, refinedMemberDec, typeNode);
} else if (refinedMemberIsVariable(refinedMemberDec)) {
checkRefinedMemberTypeExactly(refiningMember, refinedMember, typeNode, refined, refining);
} else {
// note: this version checks return type and parameter types in one shot, but the
// resulting error messages aren't as friendly, so do it the hard way instead!
// checkAssignable(refiningMember.getFullType(), refinedMember.getFullType(), that,
checkRefinedMemberTypeAssignable(refiningMember, refinedMember, typeNode, refined, refining);
}
if (refining instanceof Functional && refined instanceof Functional) {
checkRefiningMemberParameters(that, refining, refined, refinedMember, refiningMember, false);
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.ClassBody that) {
if (that.getScope() == declaration.getContainer()) {
Tree.Statement les = getLastExecutableStatement(that);
Tree.Declaration lc = getLastConstructor(that);
declarationSection = les == null;
lastExecutableStatement = les;
lastConstructor = lc;
new Visitor() {
boolean declarationSection = false;
@Override
public void visit(Tree.ExecutableStatement that) {
super.visit(that);
if (that == lastExecutableStatement) {
declarationSection = true;
}
}
@Override
public void visit(Tree.Declaration that) {
super.visit(that);
if (declarationSection && isSameDeclaration(that)) {
definedInDeclarationSection = true;
}
if (that == lastExecutableStatement) {
declarationSection = true;
}
}
@Override
public void visit(Tree.StaticMemberOrTypeExpression that) {
super.visit(that);
if (declarationSection && declaration instanceof FunctionOrValue && that.getDeclaration() == declaration) {
usedInDeclarationSection = true;
}
}
}.visit(that);
super.visit(that);
declarationSection = false;
lastExecutableStatement = null;
lastConstructor = null;
if (!declaration.isAnonymous()) {
if (isSharedDeclarationUninitialized()) {
Node d = getDeclaration(that);
if (d == null)
d = that;
d.addError("must be definitely specified by class initializer: " + message(declaration) + explanation(), 1401);
}
}
} else {
super.visit(that);
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Body that) {
addGuardedVariables(that, that instanceof Tree.ClassBody);
int oid = id;
id = 0;
super.visit(that);
id = oid;
Tree.ImportList importList = that.getImportList();
if (importList != null) {
Node firstNonImportNode = null;
for (Node d : that.getStatements()) {
firstNonImportNode = d;
break;
}
if (firstNonImportNode != null) {
for (Tree.Import im : importList.getImports()) {
if (im.getEndIndex() > firstNonImportNode.getStartIndex()) {
im.addError("import statement must occur before any other statement in block");
}
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class AnnotationVisitor method checkAnnotationParameter.
private void checkAnnotationParameter(Functional a, Tree.Parameter pn) {
Parameter p = pn.getParameterModel();
if (!(p.getModel() instanceof Value)) {
pn.addError("annotations may not have callable parameters");
} else {
Type pt = p.getType();
if (pt != null && isIllegalAnnotationParameterType(pt)) {
Node errorNode;
if (pn instanceof Tree.ValueParameterDeclaration) {
Tree.ValueParameterDeclaration vpd = (Tree.ValueParameterDeclaration) pn;
errorNode = vpd.getTypedDeclaration().getType();
} else {
errorNode = pn;
}
errorNode.addError("illegal annotation parameter type: '" + pt.asString() + "'");
}
Tree.SpecifierOrInitializerExpression se = null;
if (pn instanceof Tree.InitializerParameter) {
Tree.InitializerParameter ip = (Tree.InitializerParameter) pn;
se = ip.getSpecifierExpression();
} else if (pn instanceof Tree.ParameterDeclaration) {
Tree.ParameterDeclaration pd = (Tree.ParameterDeclaration) pn;
Tree.TypedDeclaration td = pd.getTypedDeclaration();
if (td instanceof Tree.MethodDeclaration) {
Tree.MethodDeclaration md = (Tree.MethodDeclaration) td;
se = md.getSpecifierExpression();
} else if (td instanceof Tree.AttributeDeclaration) {
Tree.AttributeDeclaration ad = (Tree.AttributeDeclaration) td;
se = ad.getSpecifierOrInitializerExpression();
}
}
if (se != null) {
checkAnnotationArgument(a, se.getExpression());
}
}
}
Aggregations