use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class JsIdentifierNames method name.
public String name(Parameter param) {
if (param == null) {
return null;
}
String name = param.getName();
FunctionOrValue decl = param.getModel();
final boolean nonLocal = decl.isShared() && decl.isMember() || decl.isToplevel() && decl instanceof Function;
if (nonLocal) {
// The identifier might be accessed from other .js files, so it must
// be reliably reproducible. In most cases simply using the original
// name is ok because otherwise it would result in a name collision in
// Ceylon too. We just have to take care of a few exceptions:
String suffix = nestingSuffix(decl, false);
if (suffix.length() > 0) {
// nested type
name += suffix;
} else if (reservedWords.contains(name)) {
// JavaScript keyword
name = "$_" + name;
}
} else {
// The identifier will not be used outside the generated .js file,
// so we can simply disambiguate it with a numeric ID.
name = uniquePrivateName(decl, false);
}
return JsUtils.escapeStringLiteral(name);
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class TestModuleManager method tmptest.
@Test
public void tmptest() {
System.out.println("-----------------------");
ClassOrInterface d0 = (ClassOrInterface) srclang.getDirectMember("Iterable", null, false);
Assert.assertNotNull("ContainerWithFirstElement from srclang", d0);
ClassOrInterface d1 = (ClassOrInterface) jslang.getDirectMember("Iterable", null, false);
Assert.assertNotNull("ContainerWithFirstElement from jslang", d1);
Type seq0 = null, seq1 = null;
for (Type pt : d0.getSatisfiedTypes()) {
System.out.println(d0 + " satisfies " + pt);
if (pt.asString().startsWith("Null[]")) {
seq0 = pt;
break;
}
}
for (Type pt : d1.getSatisfiedTypes()) {
if (pt.asString().startsWith("Null[]")) {
seq1 = pt;
break;
}
}
compareTypes(seq0, seq1, new ArrayList<String>());
System.out.println("src " + seq0 + " - js " + seq1);
compareTypeDeclarations(d0, d1);
FunctionOrValue m0 = (FunctionOrValue) d0.getDirectMember("last", null, false);
FunctionOrValue m1 = (FunctionOrValue) d1.getDirectMember("last", null, false);
System.out.println("Iterable.last " + m0 + " vs " + m1);
System.out.println("refined member " + d0.getRefinedMember("last", null, false).getContainer() + " vs " + d1.getRefinedMember("last", null, false).getContainer());
System.out.println("last is transient? " + m0.isTransient() + " vs " + m1.isTransient());
System.out.println("refined " + m0.getRefinedDeclaration().getContainer() + " vs " + m1.getRefinedDeclaration().getContainer());
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class RefinementVisitor method checkSmallRefinement.
private void checkSmallRefinement(Node that, Declaration refiningDeclaration, Declaration refinedDeclaration) {
if (refiningDeclaration instanceof FunctionOrValue && refinedDeclaration instanceof FunctionOrValue) {
FunctionOrValue refiningFunctionOrValue = (FunctionOrValue) refiningDeclaration;
FunctionOrValue refinedFunctionOrValue = (FunctionOrValue) refinedDeclaration;
boolean refiningSmall = refiningFunctionOrValue.isSmall();
boolean refinedSmall = refinedFunctionOrValue.isSmall();
if (refiningSmall && !refinedSmall) {
that.addUsageWarning(Warning.smallIgnored, "small annotation on actual member " + message(refiningDeclaration) + " will be ignored: " + message(refinedDeclaration) + " is not small");
}
refiningFunctionOrValue.setSmall(refinedSmall);
}
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class SelfReferenceVisitor method visit.
@Override
public void visit(Tree.AssignmentOp that) {
super.visit(that);
if (inBody()) {
Tree.Term lt = that.getLeftTerm();
Tree.Term rt = that.getRightTerm();
if (lt instanceof Tree.MemberOrTypeExpression && rt instanceof Tree.This) {
MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) lt;
Declaration d = mte.getDeclaration();
if (d instanceof FunctionOrValue) {
FunctionOrValue fov = (FunctionOrValue) d;
if (fov.isLate()) {
// NOTE: EARLY EXIT!!
return;
}
}
}
checkSelfReference(that, rt);
}
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class SpecificationVisitor method specification.
private void specification(Tree.SpecifierStatement that, Tree.StaticMemberOrTypeExpression bme) {
boolean constant = !isVariable() && !isLate();
Scope scope = that.getScope();
if (constant && (!declaration.isDefinedInScope(scope) || declaration instanceof FunctionOrValue && ((FunctionOrValue) declaration).isShortcutRefinement())) {
// this error is added by ExpressionVisitor
// that.addError("inherited member is not variable and may not be specified here: " +
// name());
} else if (!declared && constant) {
bme.addError(shortdesc() + " is not yet declared: " + name());
} else if (loopDepth > 0 && constant && !(endsInReturnThrow && lastContinue == null || endsInBreak && allOuterLoopsBreak && lastContinue == null)) {
if (definitely) {
bme.addError(longdesc() + " is aready definitely specified: " + name(), 803);
} else {
bme.addError(longdesc() + " is not definitely unspecified in loop: " + name(), 803);
// to eliminate dupe error
specify();
}
} else if (specificationDisabled && constant) {
if (withinDeclaration) {
bme.addError("cannot specify " + shortdesc() + " from within its own body: " + name());
} else {
bme.addError("cannot specify " + shortdesc() + " declared in outer scope: " + name(), 803);
}
} else if (possibly && constant) {
if (definitely) {
bme.addError(longdesc() + " is aready definitely specified: " + name(), 803);
} else {
bme.addError(longdesc() + " is not definitely unspecified: " + name(), 803);
// to eliminate dupe error
specify();
}
} else {
specify();
bme.visit(this);
}
}
Aggregations