use of org.eclipse.ceylon.compiler.typechecker.tree.Visitor in project ceylon by eclipse.
the class ClassOrPackageDoc method getParametersAssertions.
private Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> getParametersAssertions(final Declaration decl) {
final Map<Parameter, Map<Tree.Assertion, List<Tree.Condition>>> parametersAssertions = new LinkedHashMap<Parameter, Map<Tree.Assertion, List<Tree.Condition>>>();
if (((Functional) decl).getParameterLists().isEmpty()) {
return parametersAssertions;
}
Node node = tool.getNode(decl);
PhasedUnit pu = tool.getUnit(decl);
if (node == null || pu == null) {
return parametersAssertions;
}
Tree.Body body = null;
if (node instanceof Tree.MethodDefinition) {
body = ((Tree.MethodDefinition) node).getBlock();
} else if (node instanceof Tree.ClassDefinition) {
body = ((Tree.ClassDefinition) node).getClassBody();
}
if (body == null) {
return parametersAssertions;
}
final Map<String, Parameter> parametersNames = new HashMap<String, Parameter>();
for (ParameterList parameterList : ((Functional) decl).getParameterLists()) {
for (Parameter parameter : parameterList.getParameters()) {
parametersNames.put(parameter.getName(), parameter);
}
}
body.visitChildren(new Visitor() {
private boolean stop = false;
private Tree.Assertion assertion = null;
private Set<Parameter> referencedParameters = new HashSet<Parameter>();
@Override
public void visit(Tree.Assertion that) {
assertion = that;
super.visit(that);
assertion = null;
}
@Override
public void visit(Tree.Condition that) {
referencedParameters.clear();
super.visit(that);
if (assertion != null && !referencedParameters.isEmpty()) {
for (Parameter referencedParameter : referencedParameters) {
Map<Tree.Assertion, List<Tree.Condition>> parameterAssertions = parametersAssertions.get(referencedParameter);
if (parameterAssertions == null) {
parameterAssertions = new LinkedHashMap<Tree.Assertion, List<Tree.Condition>>();
parametersAssertions.put(referencedParameter, parameterAssertions);
}
List<Tree.Condition> parameterConditions = parameterAssertions.get(assertion);
if (parameterConditions == null) {
parameterConditions = new ArrayList<Tree.Condition>();
parameterAssertions.put(assertion, parameterConditions);
}
parameterConditions.add(that);
}
}
}
@Override
public void visit(Tree.BaseMemberExpression that) {
if (assertion != null) {
Declaration d = that.getDeclaration();
Scope realScope = org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope(d.getScope());
if (parametersNames.containsKey(d.getName()) && realScope == decl) {
referencedParameters.add(parametersNames.get(d.getName()));
}
}
super.visit(that);
}
@Override
public void visit(Tree.Statement that) {
if (assertion == null) {
stop = true;
}
super.visit(that);
}
@Override
public void visitAny(Node that) {
if (!stop) {
super.visitAny(that);
}
}
});
return parametersAssertions;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Visitor in project ceylon by eclipse.
the class LinkRenderer method findDocLink.
private Tree.DocLink findDocLink(final String docLinkText, Referenceable referenceable) {
final Tree.DocLink[] docLinks = new Tree.DocLink[1];
Node scopeNode = ceylonDocTool.getNode(referenceable);
if (scopeNode != null) {
scopeNode.visit(new Visitor() {
@Override
public void visit(Tree.DocLink docLink) {
String s1 = normalizeSpaces(docLinkText);
String s2 = normalizeSpaces(docLink.getText());
if (s1.equals(s2)) {
docLinks[0] = docLink;
return;
}
}
});
}
return docLinks[0];
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Visitor in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Parameter that) {
super.visit(that);
Tree.SpecifierOrInitializerExpression sie = null;
if (that instanceof Tree.ParameterDeclaration) {
Tree.ParameterDeclaration pd = (Tree.ParameterDeclaration) that;
Tree.TypedDeclaration td = pd.getTypedDeclaration();
if (td instanceof Tree.AttributeDeclaration) {
Tree.AttributeDeclaration ad = (Tree.AttributeDeclaration) td;
sie = ad.getSpecifierOrInitializerExpression();
} else if (td instanceof Tree.MethodDeclaration) {
Tree.MethodDeclaration md = (Tree.MethodDeclaration) td;
sie = md.getSpecifierExpression();
}
} else if (that instanceof Tree.InitializerParameter) {
Tree.InitializerParameter ip = (Tree.InitializerParameter) that;
sie = ip.getSpecifierExpression();
}
if (sie != null) {
if (scope instanceof ClassAlias) {
sie.addUnsupportedError("defaulted parameters are not yet supported for class aliases");
}
new Visitor() {
public void visit(Tree.AssignmentOp that) {
that.addError("assignment may not occur in default argument expression");
}
@Override
public void visit(Tree.PostfixOperatorExpression that) {
that.addError("postfix increment or decrement may not occur in default argument expression");
}
@Override
public void visit(Tree.PrefixOperatorExpression that) {
that.addError("prefix increment or decrement may not occur in default argument expression");
}
}.visit(sie);
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Visitor in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.FunctionArgument that) {
Tree.Type type = that.getType();
final Function f = new Function();
f.setName("anonymous#" + fid++);
f.setAnonymous(true);
if (type.getToken() != null) {
f.setDeclaredVoid(type instanceof Tree.VoidModifier);
} else {
Tree.Block block = that.getBlock();
if (block != null) {
f.setDeclaredVoid(true);
new Visitor() {
@Override
public void visit(Tree.Declaration that) {
}
@Override
public void visit(Tree.TypedArgument that) {
}
@Override
public void visit(Tree.ObjectExpression that) {
}
@Override
public void visit(Tree.FunctionArgument that) {
}
@Override
public void visit(Tree.Return that) {
if (that.getExpression() != null) {
f.setDeclaredVoid(false);
}
super.visit(that);
}
}.visit(block);
}
}
that.setDeclarationModel(f);
visitArgument(that, f);
Scope o = enterScope(f);
Declaration d = beginDeclaration(f);
super.visit(that);
endDeclaration(d);
exitScope(o);
setParameterLists(f, that.getParameterLists(), that);
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Visitor in project ceylon by eclipse.
the class PhasedUnit method validateTree.
public void validateTree() {
// System.out.println("Validating tree for " + fileName);
if (!treeValidated) {
String fn = unit.getRelativePath();
for (int i = 0; i < fn.length(); i = fn.offsetByCodePoints(i, 1)) {
int cp = fn.codePointAt(i);
if (cp > 127) {
rootNode.addUsageWarning(Warning.filenameNonAscii, "source file name has non-ASCII characters: " + fn);
}
}
String ufn = unit.getFilename();
for (Unit u : unit.getPackage().getUnits()) {
if (!u.equals(unit) && u.getFilename().equalsIgnoreCase(ufn)) {
if (u.getFilename().equals(ufn)) {
String errorMessage = "identical source files: " + unit.getFullPath() + " and " + u.getFullPath();
if (u.getFilename().equals(MODULE_FILE) || u.getFilename().equals(PACKAGE_FILE)) {
errorMessage += " (a module/package descriptor should be defined only once, even in case of multiple source directories)";
}
rootNode.addError(errorMessage);
} else {
rootNode.addUsageWarning(Warning.filenameCaselessCollision, "source file names differ only by case: " + unit.getFullPath() + " and " + u.getFullPath());
}
}
}
rootNode.visit(new Validator().setExceptionHandler(this));
rootNode.visit(new Visitor() {
@Override
public void visit(ModuleDescriptor that) {
super.visit(that);
ImportPath importPath = that.getImportPath();
if (importPath != null) {
String moduleName = formatPath(importPath.getIdentifiers());
ModuleSourceMapper moduleManagerUtil = moduleSourceMapperRef.get();
if (moduleManagerUtil != null) {
for (Module otherModule : moduleManagerUtil.getCompiledModules()) {
String otherModuleName = otherModule.getNameAsString();
if (moduleName.startsWith(otherModuleName + ".") || otherModuleName.startsWith(moduleName + ".")) {
StringBuilder error = new StringBuilder().append("Found two modules within the same hierarchy: '").append(otherModule.getNameAsString()).append("' and '").append(moduleName).append("'");
that.addError(error.toString());
}
}
}
}
}
}.setExceptionHandler(this));
treeValidated = true;
}
}
Aggregations