use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class AbstractTransformer method collectQualifyingTypeArguments.
/**
* Collects all the type parameters and arguments required for an interface that's been pulled up to the
* toplevel, including its containing type and method type parameters.
*/
private void collectQualifyingTypeArguments(java.util.List<TypeParameter> qualifyingTypeParameters, Map<TypeParameter, Type> qualifyingTypeArguments, java.util.List<Reference> qualifyingTypes) {
// make sure we only add type parameters with the same name once, as duplicates are erased from the target interface
// since they cannot be accessed
Set<String> names = new HashSet<String>();
// walk the qualifying types backwards to make sure we only add a TP with the same name once and the outer one wins
for (int i = qualifyingTypes.size() - 1; i >= 0; i--) {
Reference qualifiedType = qualifyingTypes.get(i);
Map<TypeParameter, Type> tas = qualifiedType.getTypeArguments();
java.util.List<TypeParameter> tps = qualifiedType.getDeclaration().getTypeParameters();
// add any type params for this type
if (tps != null) {
int index = 0;
for (TypeParameter tp : tps) {
// add it only once
if (names.add(tp.getName())) {
// start putting all these type parameters at 0 and then in order
// so that outer type params end up before inner type params but
// order is preserved within each type
qualifyingTypeParameters.add(index++, tp);
qualifyingTypeArguments.put(tp, tas.get(tp));
}
}
}
// add any container method TP
Declaration declaration = qualifiedType.getDeclaration();
if (Decl.isLocal(declaration)) {
Scope scope = declaration.getContainer();
// collect every container method until the next type or package
java.util.List<Function> methods = new LinkedList<Function>();
while (scope != null && scope instanceof ClassOrInterface == false && scope instanceof Package == false) {
if (scope instanceof Function) {
methods.add((Function) scope);
}
scope = scope.getContainer();
}
// methods are sorted inner to outer, which is the order we're following here for types
for (Function method : methods) {
java.util.List<TypeParameter> methodTypeParameters = method.getTypeParameters();
if (methodTypeParameters != null) {
int index = 0;
for (TypeParameter tp : methodTypeParameters) {
// add it only once
if (names.add(tp.getName())) {
// start putting all these type parameters at 0 and then in order
// so that outer type params end up before inner type params but
// order is preserved within each type
qualifyingTypeParameters.add(index++, tp);
qualifyingTypeArguments.put(tp, tp.getType());
}
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class AbstractTransformer method makeUnwrapArray.
JCExpression makeUnwrapArray(final Declaration methodOrClass) {
Scope javaArrayDecl = methodOrClass.getContainer();
String name;
if (javaArrayDecl.equals(typeFact().getJavaIntArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapIntArray";
} else if (javaArrayDecl.equals(typeFact().getJavaLongArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapLongArray";
} else if (javaArrayDecl.equals(typeFact().getJavaShortArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapShortArray";
} else if (javaArrayDecl.equals(typeFact().getJavaFloatArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapFloatArray";
} else if (javaArrayDecl.equals(typeFact().getJavaDoubleArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapDoubleArray";
} else if (javaArrayDecl.equals(typeFact().getJavaByteArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapByteArray";
} else if (javaArrayDecl.equals(typeFact().getJavaBooleanArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapBooleanArray";
} else if (javaArrayDecl.equals(typeFact().getJavaCharArrayDeclaration())) {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapCharArray";
} else {
name = "org.eclipse.ceylon.compiler.java.Util.unwrapObjectArray";
}
return naming.makeQuotedQualIdentFromString(name);
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class BoxingVisitor method hasTypeParameterWithConstraintsOutsideScopeResolved.
private boolean hasTypeParameterWithConstraintsOutsideScopeResolved(Type type, Scope scope) {
if (type == null)
return false;
if (type.isUnion()) {
java.util.List<Type> caseTypes = type.getCaseTypes();
for (Type pt : caseTypes) {
if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
return true;
}
return false;
}
if (type.isIntersection()) {
java.util.List<Type> satisfiedTypes = type.getSatisfiedTypes();
for (Type pt : satisfiedTypes) {
if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
return true;
}
return false;
}
TypeDeclaration declaration = type.getDeclaration();
if (declaration == null)
return false;
if (type.isTypeParameter()) {
// only look at it if it is defined outside our scope
Scope typeParameterScope = declaration.getContainer();
while (scope != null) {
if (Decl.equalScopes(scope, typeParameterScope))
return false;
scope = scope.getContainer();
}
TypeParameter tp = (TypeParameter) declaration;
Boolean nonErasedBounds = tp.hasNonErasedBounds();
if (nonErasedBounds == null)
visitTypeParameter(tp);
return nonErasedBounds != null ? nonErasedBounds.booleanValue() : false;
}
// now check its type parameters
for (Type pt : type.getTypeArgumentList()) {
if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
return true;
}
// no problem here
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.Scope 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.model.typechecker.model.Scope in project ceylon by eclipse.
the class LinkRenderer method isInCurrentModule.
private boolean isInCurrentModule(Object obj) {
Module objModule = null;
if (obj instanceof Module) {
objModule = (Module) obj;
} else if (obj instanceof Scope) {
objModule = getPackage((Scope) obj).getModule();
} else if (obj instanceof Element) {
objModule = getPackage(((Element) obj).getScope()).getModule();
}
Module currentModule = ceylonDocTool.getCurrentModule();
if (currentModule != null && objModule != null) {
return currentModule.equals(objModule);
}
return false;
}
Aggregations