use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class Naming method addNamesForWrapperClass.
private <R> void addNamesForWrapperClass(TypeDeclarationBuilder<R> builder, TypedDeclaration decl, int namingOptions) {
if ((namingOptions & NA_FQ) != 0) {
if ((namingOptions & NA_WRAPPER) == 0 && (namingOptions & NA_WRAPPER_UNQUOTED) == 0) {
throw new BugException("If you pass FQ you must pass WRAPPER or WRAPPER_UNQUOTED too, or there's no class name to qualify!");
}
List<String> outerNames = null;
Scope s = decl.getContainer();
while (s != null) {
if (s instanceof Package) {
final List<String> packageName = ((Package) s).getName();
for (int ii = 0; ii < packageName.size(); ii++) {
if (ii == 0 && packageName.get(ii).isEmpty()) {
continue;
}
builder.select(quoteIfJavaKeyword(packageName.get(ii)));
}
break;
} else if (s instanceof ClassOrInterface) {
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(getQuotedClassName((ClassOrInterface) s, 0));
} else if (s instanceof TypedDeclaration) {
if (outerNames == null) {
outerNames = new ArrayList<String>(2);
}
outerNames.add(quoteIfJavaKeyword(((TypedDeclaration) s).getName()));
}
s = s.getContainer();
}
if (outerNames != null) {
for (int ii = outerNames.size() - 1; ii >= 0; ii--) {
String outerName = outerNames.get(ii);
builder.select(outerName);
}
}
}
if ((namingOptions & NA_WRAPPER) != 0) {
builder.select(getQuotedClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
} else if ((namingOptions & NA_WRAPPER_UNQUOTED) != 0) {
builder.select(getRealName(decl, namingOptions & (NA_GETTER | NA_SETTER | NA_WRAPPER_UNQUOTED)));
} else if ((namingOptions & NA_Q_LOCAL_INSTANCE) != 0) {
if (Decl.isBoxedVariable(decl)) {
builder.select(getVariableBoxName(decl));
} else {
builder.select(getAttrClassName(decl, namingOptions & (NA_GETTER | NA_SETTER)));
}
}
if ((namingOptions & NA_WRAPPER_WITH_THIS) != 0) {
builder.select("this");
}
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
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 = com.redhat.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 com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class LinkRenderer method isLinkable.
private boolean isLinkable(Declaration decl) {
if (decl == null) {
return false;
}
if (decl.isParameter()) {
return true;
}
if (!ceylonDocTool.isIncludeNonShared()) {
if (!decl.isShared()) {
return false;
}
Scope c = decl.getContainer();
while (c != null) {
boolean isShared = true;
if (c instanceof Declaration) {
isShared = ((Declaration) c).isShared();
}
if (c instanceof Package) {
isShared = ((Package) c).isShared();
}
if (!isShared) {
return false;
}
c = c.getContainer();
}
}
return true;
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class LinkRenderer method processTypedDeclaration.
private String processTypedDeclaration(TypedDeclaration decl) {
String declName = Util.getDeclarationName(decl);
Scope declContainer = decl.getContainer();
if (isLinkable(decl)) {
String url = getUrl(declContainer, decl);
if (url != null) {
return buildLinkElement(url, getLinkText(decl), "Go to " + decl.getQualifiedNameString());
}
}
String result = declName;
if (withinText) {
result = "<code>" + result + "</code>";
}
if (customText != null) {
result = customText;
}
return result;
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class LinkRenderer method processTypeAlias.
private String processTypeAlias(TypeAlias alias) {
String aliasName = alias.getName();
Scope aliasContainer = alias.getContainer();
if (isLinkable(alias)) {
String url = getUrl(aliasContainer, alias);
if (url != null) {
return buildLinkElement(url, aliasName, "Go to " + alias.getQualifiedNameString());
}
}
return buildSpanElementWithNameAndTooltip(alias);
}
Aggregations