use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class BugException method addError.
/**
* Add an error to the a node. A {@link CodeGenError}
* is created with the exception's message and the exception as cause,
* and is added to the assoicated node (if there is one), and otherwise
* the given node.
* @param fallbackNode
*/
public void addError(Node fallbackNode) {
if (!this.attached) {
Node bestNode = bestNode(fallbackNode);
bestNode.addError(new CodeGenError(bestNode, getMessage(), Backend.Java, this));
this.attached = true;
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class CeylonDoc method writeAnnotations.
protected final void writeAnnotations(Referenceable referenceable) throws IOException {
Tree.AnnotationList annotationList = null;
Node node = tool.getNode(referenceable);
if (node instanceof Tree.Declaration) {
annotationList = ((Tree.Declaration) node).getAnnotationList();
} else if (node instanceof Tree.ImportModule) {
annotationList = ((Tree.ImportModule) node).getAnnotationList();
} else if (node instanceof Tree.ModuleDescriptor) {
annotationList = ((Tree.ModuleDescriptor) node).getAnnotationList();
} else if (node instanceof Tree.PackageDescriptor) {
annotationList = ((Tree.PackageDescriptor) node).getAnnotationList();
}
if (annotationList != null) {
annotationList.visit(new WriteAnnotationsVisitor(referenceable));
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node in project ceylon by eclipse.
the class ClassOrPackageDoc method getParameterDefaultValue.
private String getParameterDefaultValue(Parameter param) throws IOException {
String defaultValue = null;
if (param.isDefaulted()) {
PhasedUnit pu = tool.getParameterUnit(param);
Node paramNode = tool.getParameterNode(param);
if (pu != null && paramNode instanceof Tree.Parameter) {
Tree.SpecifierOrInitializerExpression defArg = getDefaultArgument((Tree.Parameter) paramNode);
if (defArg != null) {
defaultValue = getSourceCode(pu, defArg.getExpression());
if (defaultValue != null) {
defaultValue = defaultValue.trim();
}
}
}
}
return defaultValue;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Node 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.Node 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];
}
Aggregations