use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class RuntimeModelLoader method loadStandardModules.
@Override
public void loadStandardModules() {
// set up the type factory and that's it: do not try to load the language module package before it's set up
// by Metamodel.loadModule
jdkProvider = new JdkProvider();
Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
addModuleToClassPath(languageModule, (ArtifactResult) null);
Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
typeFactory.setPackage(languagePackage);
// make sure the jdk modules are loaded because those are not initialised by jboss modules nor the IDE Launcher
for (String jdkModule : JDKUtils.getJDKModuleNames()) findOrCreateModule(jdkModule, JDKUtils.jdk.version);
for (String jdkOracleModule : JDKUtils.getOracleJDKModuleNames()) findOrCreateModule(jdkOracleModule, JDKUtils.jdk.version);
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class LazyModule method getPackage.
@Override
public Package getPackage(String name) {
// try here first
Package pkg = null;
// unless we're the default module, in which case we have to check this at the end,
// since every package can be part of the default module
boolean defaultModule = isDefaultModule();
if (!defaultModule) {
pkg = findPackageInModule(this, name);
if (pkg != null)
return loadPackage(pkg);
}
// then try in dependencies
Set<Module> visited = new HashSet<Module>();
for (ModuleImport dependency : getImports()) {
// we don't have to worry about the default module here since we can't depend on it
pkg = findPackageInImport(name, dependency, visited);
if (pkg != null)
return loadPackage(pkg);
}
AbstractModelLoader modelLoader = getModelLoader();
JdkProvider jdkProvider = modelLoader.getJdkProvider();
// so we pretend the JDK imports the language module
if (jdkProvider != null && jdkProvider.isJDKModule(getNameAsString())) {
Module languageModule = getModelLoader().getLanguageModule();
if (languageModule instanceof LazyModule) {
pkg = findPackageInModule((LazyModule) languageModule, name);
if (pkg != null)
return loadPackage(pkg);
}
}
// work and appear to come from there
if (jdkProvider.isJDKPackage(name)) {
return null;
}
// do the lookup of the default module last
if (defaultModule)
pkg = modelLoader.findExistingPackage(this, name);
return pkg;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.PackageLiteral that) {
super.visit(that);
Tree.ImportPath path = that.getImportPath();
if (path == null) {
path = new Tree.ImportPath(null);
that.setImportPath(path);
}
Package pack = path.getIdentifiers().isEmpty() ? unit.getPackage() : importedPackage(path, unit);
path.setModel(pack);
that.setTypeModel(unit.getPackageDeclarationType());
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AnnotationVisitor method visit.
@Override
public void visit(Tree.DocLink that) {
super.visit(that);
String text = that.getText();
int pipeIndex = text.indexOf("|");
if (pipeIndex != -1) {
text = text.substring(pipeIndex + 1);
}
String kind = null;
if (text.startsWith(DOC_LINK_MODULE)) {
kind = DOC_LINK_MODULE;
text = text.substring(DOC_LINK_MODULE.length());
} else if (text.startsWith(DOC_LINK_PACKAGE)) {
kind = DOC_LINK_PACKAGE;
text = text.substring(DOC_LINK_PACKAGE.length());
} else if (text.startsWith(DOC_LINK_CLASS)) {
kind = DOC_LINK_CLASS;
text = text.substring(DOC_LINK_CLASS.length());
} else if (text.startsWith(DOC_LINK_INTERFACE)) {
kind = DOC_LINK_INTERFACE;
text = text.substring(DOC_LINK_INTERFACE.length());
} else if (text.startsWith(DOC_LINK_FUNCTION)) {
kind = DOC_LINK_FUNCTION;
text = text.substring(DOC_LINK_FUNCTION.length());
} else if (text.startsWith(DOC_LINK_VALUE)) {
kind = DOC_LINK_VALUE;
text = text.substring(DOC_LINK_VALUE.length());
} else if (text.startsWith(DOC_LINK_ALIAS)) {
kind = DOC_LINK_ALIAS;
text = text.substring(DOC_LINK_ALIAS.length());
}
boolean parentheses = false;
if (text.endsWith("()")) {
parentheses = true;
text = text.substring(0, text.length() - 2);
}
int scopeIndex = text.indexOf("::");
String packageName;
if (DOC_LINK_MODULE.equals(kind) || DOC_LINK_PACKAGE.equals(kind)) {
packageName = text;
} else {
packageName = scopeIndex < 0 ? null : text.substring(0, scopeIndex);
}
String path = scopeIndex < 0 ? text : text.substring(scopeIndex + 2);
String[] names = path.isEmpty() ? new String[0] : path.split("\\.");
Declaration base = null;
if (packageName == null) {
if (names.length > 0) {
base = that.getScope().getMemberOrParameter(that.getUnit(), names[0], null, false);
}
} else {
Package pack = that.getUnit().getPackage().getModule().getPackage(packageName);
if (pack == null) {
if (DOC_LINK_MODULE.equals(kind)) {
that.addUsageWarning(Warning.doclink, "module is missing: '" + packageName + "'");
} else {
that.addUsageWarning(Warning.doclink, "package is missing: '" + packageName + "'");
}
} else {
that.setPkg(pack);
if (DOC_LINK_MODULE.equals(kind)) {
Package rootPack = pack.getModule().getRootPackage();
if (pack.equals(rootPack)) {
that.setModule(pack.getModule());
} else {
that.addUsageWarning(Warning.doclink, "module is missing: '" + packageName + "'");
}
}
if (names.length > 0) {
base = pack.getDirectMember(names[0], null, false);
}
}
if (DOC_LINK_MODULE.equals(kind) || DOC_LINK_PACKAGE.equals(kind)) {
return;
}
}
if (base == null) {
that.addUsageWarning(Warning.doclink, "declaration is missing: '" + (names.length > 0 ? names[0] : text) + "'");
} else {
that.setBase(base);
if (names.length > 1) {
that.setQualified(new ArrayList<Declaration>(names.length - 1));
}
for (int i = 1; i < names.length; i++) {
if (base instanceof Value) {
Value value = (Value) base;
if (!value.isParameter() && !value.isTransient() && value.getTypeDeclaration() != null && value.getTypeDeclaration().isAnonymous()) {
base = value.getTypeDeclaration();
}
}
if (base instanceof TypeDeclaration || base instanceof Functional) {
Declaration qualified = base.getMember(names[i], null, false);
if (qualified == null) {
that.addUsageWarning(Warning.doclink, "member declaration or parameter is missing: '" + names[i] + "'");
break;
} else {
that.getQualified().add(qualified);
base = qualified;
}
} else {
that.addUsageWarning(Warning.doclink, "not a type or functional declaration: '" + base.getName() + "'");
break;
}
}
}
if (base != null) {
if (kind != null && (names.length == 1 || names.length == that.getQualified().size() + 1)) {
if (DOC_LINK_CLASS.equals(kind) && !(base instanceof Class)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not a class: '" + base.getName() + "'");
} else if (DOC_LINK_INTERFACE.equals(kind) && !(base instanceof Interface)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not an interface: '" + base.getName() + "'");
} else if (DOC_LINK_ALIAS.equals(kind) && !(base instanceof TypeAlias)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not a type alias: '" + base.getName() + "'");
} else if (DOC_LINK_FUNCTION.equals(kind) && !(base instanceof Function)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not a function: '" + base.getName() + "'");
} else if (DOC_LINK_VALUE.equals(kind) && !(base instanceof Value)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not a value: '" + base.getName() + "'");
}
}
if (parentheses && !(base instanceof Functional)) {
that.addUsageWarning(Warning.doclink, "linked declaration is not a function: '" + base.getName() + "'");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class ExpressionVisitor method resolveQualifiedMemberExpression.
private TypedDeclaration resolveQualifiedMemberExpression(Tree.QualifiedMemberExpression that, boolean error) {
Tree.Identifier id = that.getIdentifier();
boolean nameNonempty = id != null && !id.getText().equals("");
if (nameNonempty && checkMember(that)) {
Tree.Primary primary = that.getPrimary();
String name = name(id);
List<Type> signature = that.getSignature();
boolean spread = that.getEllipsis();
String container;
boolean ambiguous;
TypedDeclaration member;
Type pt;
if (primary instanceof Tree.Package) {
Package pack = unit.getPackage();
container = "package '" + pack.getNameAsString() + "'";
member = getPackageTypedDeclaration(name, signature, spread, unit);
ambiguous = false;
pt = null;
} else {
pt = primary.getTypeModel().resolveAliases();
TypeDeclaration d = getDeclaration(that, pt);
if (d instanceof Constructor) {
d = d.getExtendedType().getDeclaration();
}
container = "type '" + d.getName(unit) + "'";
Scope scope = that.getScope();
member = getTypedMember(d, name, signature, spread, unit, scope);
ambiguous = member == null && d.isMemberAmbiguous(name, unit, signature, spread);
if (member == null) {
container += memberCorrectionMessage(name, d, scope, unit, cancellable);
}
}
if (member == null) {
if (error) {
if (ambiguous) {
that.addError("method or attribute is ambiguous: '" + name + "' for " + container);
} else {
that.addError("method or attribute is not defined: '" + name + "' in " + container, 100);
unit.setUnresolvedReferences();
}
}
} else {
member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
if (error) {
checkStaticPrimary(that, primary, member, pt);
}
that.setDeclaration(member);
resetSuperReference(that);
boolean selfReference = isSelfReference(primary);
if (!selfReference && !member.isShared()) {
member.setOtherInstanceAccess(true);
}
if (error) {
if (checkConcreteConstructor(member, that)) {
checkQualifiedVisibility(that, member, name, container, selfReference);
}
checkSuperMember(that, signature, spread);
}
}
return member;
} else {
return null;
}
}
Aggregations