use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.
the class CeylonVersionTool method run.
@Override
public void run() throws IOException, RecognitionException {
// TODO if version is empty? Prompt? Or should --set have an optional argument?
TypeCheckerBuilder tcb = new TypeCheckerBuilder();
for (File path : this.sourceFolders) {
tcb.addSrcDirectory(applyCwd(path));
}
TypeChecker tc = tcb.getTypeChecker();
PhasedUnits pus = tc.getPhasedUnits();
pus.visitModules();
ArrayList<Module> moduleList = new ArrayList<Module>(pus.getModuleSourceMapper().getCompiledModules());
Collections.sort(moduleList, new Comparator<Module>() {
@Override
public int compare(Module m1, Module m2) {
if (match(m1) && !match(m2)) {
return -1;
} else if (!match(m1) && match(m2)) {
return +1;
}
int cmp = m1.getNameAsString().compareToIgnoreCase(m2.getNameAsString());
if (cmp == 0) {
cmp = m1.getVersion().compareTo(m2.getVersion());
}
return cmp;
}
});
// first update all module versions and remember which version we assigned to which module
// because the user can update every individual version
Map<String, String> updatedModuleVersions = new HashMap<String, String>();
for (Module module : moduleList) {
boolean isMatch = match(module);
if (newVersion == null) {
output(module, isMatch);
} else if (isMatch) {
if (!updateModuleVersion(module, updatedModuleVersions)) {
return;
}
}
}
if (updateDistribution) {
updatedModuleVersions.put("ceylon.bootstrap", newVersion);
updatedModuleVersions.put("ceylon.language", newVersion);
updatedModuleVersions.put("ceylon.runtime", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.compiler.java", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.compiler.js", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.typechecker", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.common", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.cli", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.model", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-loader", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-aether", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-webdav", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-javascript", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.langtools.classfile", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.tool.provider", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.tools", newVersion);
}
// now do dependencies because we know which modules we did update
if (newVersion != null && !noUpdateDependencies) {
for (Module module : moduleList) {
if (!updateModuleImports(module, updatedModuleVersions)) {
return;
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.
the class MainForTest method main.
/**
* Files that are not under a proper module structure are
* placed under a <nomodule> module.
*/
public static void main(String[] args) throws Exception {
long start = System.nanoTime();
RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test/modules").logger(new LeakingLogger()).buildManager();
TypeChecker typeChecker = new TypeCheckerBuilder().statistics(true).verbose(false).addSrcDirectory(new File("test/main")).setRepositoryManager(repositoryManager).getTypeChecker();
typeChecker.process();
int errors = typeChecker.getErrors();
Tree.CompilationUnit compilationUnit = typeChecker.getPhasedUnitFromRelativePath("ceylon/language/Object.ceylon").getCompilationUnit();
if (compilationUnit == null) {
throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in .src");
}
compilationUnit = typeChecker.getPhasedUnitFromRelativePath("capture/Capture.ceylon").getCompilationUnit();
if (compilationUnit == null) {
throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in real src dir");
}
compilationUnit = typeChecker.getPhasedUnitFromRelativePath("org/eclipse/sample/multisource/Boo.ceylon").getCompilationUnit();
Module module = compilationUnit.getUnit().getPackage().getModule();
if (!"org.eclipse.sample.multisource".equals(module.getNameAsString())) {
throw new RuntimeException("Unable to extract module name");
}
if (!"0.2".equals(module.getVersion())) {
throw new RuntimeException("Unable to extract module version");
}
typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/main/capture")).setRepositoryManager(repositoryManager).getTypeChecker();
typeChecker.process();
errors += typeChecker.getErrors();
compilationUnit = typeChecker.getPhasedUnitFromRelativePath("Capture.ceylon").getCompilationUnit();
if (compilationUnit == null) {
throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for top level files (no package) in real src dir");
}
typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/moduledep1")).addSrcDirectory(new File("test/moduledep2")).addSrcDirectory(new File("test/moduletest")).addSrcDirectory(new File("test/restricted")).setRepositoryManager(repositoryManager).getTypeChecker();
typeChecker.process();
errors += typeChecker.getErrors();
ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
typeChecker.process();
errors += typeChecker.getErrors();
latestZippedLanguageSourceFile.close();
System.out.println("Tests took " + ((System.nanoTime() - start) / 1000000) + " ms");
if (errors > 0) {
System.exit(1);
}
}
use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.
the class ModelLoaderTests method compareNativeRuntimeWithJavaRuntime.
@Test
public void compareNativeRuntimeWithJavaRuntime() {
// parse the ceylon sources from the language module and
// build a map of all the native declarations
final Map<String, Declaration> nativeFromSource = new HashMap<String, Declaration>();
ClosableVirtualFile latestZippedLanguageSourceFile = getLatestZippedLanguageSourceFile();
try {
TypeCheckerBuilder typeCheckerBuilder = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile);
TypeChecker typeChecker = typeCheckerBuilder.getTypeChecker();
typeChecker.process();
for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
for (Declaration d : pu.getDeclarations()) {
if (d.isNativeHeader() && d.isToplevel()) {
String qualifiedNameString = d.getQualifiedNameString();
String key = d.getDeclarationKind() + ":" + qualifiedNameString;
Declaration prev = nativeFromSource.put(key, d);
if (prev != null) {
Assert.fail("Two declarations with the same key " + key + ": " + d + " and: " + prev);
}
}
}
}
} finally {
latestZippedLanguageSourceFile.close();
}
System.out.println(nativeFromSource);
// now compile something (it doesn't matter what, we just need
// to get our hands on from-binary models for the language module)
RunnableTest tester = new RunnableTest() {
@Override
public void test(ModelLoader loader) {
OtherModelCompare comparer = new OtherModelCompare();
Module binaryLangMod = loader.getLoadedModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER);
for (Map.Entry<String, Declaration> entry : nativeFromSource.entrySet()) {
System.out.println(entry.getKey());
Declaration source = entry.getValue();
ModelLoader.DeclarationType dt = null;
switch(source.getDeclarationKind()) {
case TYPE:
case TYPE_PARAMETER:
dt = DeclarationType.TYPE;
break;
case MEMBER:
case SETTER:
dt = DeclarationType.VALUE;
break;
}
// Ensure the package is loaded
binaryLangMod.getDirectPackage(source.getQualifiedNameString().replaceAll("::.*", ""));
Declaration binary = loader.getDeclaration(binaryLangMod, source.getQualifiedNameString().replace("::", "."), dt);
comparer.compareDeclarations(source.getQualifiedNameString(), source, binary);
}
}
};
verifyCompilerClassLoading("Any.ceylon", tester, defaultOptions);
verifyRuntimeClassLoading(tester);
}
use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.
the class CompileSomething method main.
public static void main(String[] x) throws IOException {
final Options opts = new Options().outRepo("/tmp/modules").addRepo("compiler-js/build/runtime").addRepo("../ceylon.ast/modules").addRepo("../ceylon-sdk/modules").addRepo("compiler-js/build/test/proto").addRepo("npm:").optimize(true).verbose("all").generateSourceArchive(false).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedImport"))).addSrcDir("/tmp/source");
final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(false).encoding("UTF-8");
for (File sd : opts.getSrcDirs()) {
tcb.addSrcDirectory(sd);
}
final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
tcb.setRepositoryManager(repoman);
JsModuleManagerFactory.setVerbose(true);
tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
final TypeChecker tc = tcb.getTypeChecker();
TypeCache.setEnabled(false);
tc.process(true);
TypeCache.setEnabled(true);
final JsCompiler jsc = new JsCompiler(tc, opts);
ArrayList<File> individualSources = new ArrayList<>();
for (File srcdir : opts.getSrcDirs()) {
for (File sd : srcdir.listFiles()) {
if (sd.isFile() && sd.getName().endsWith(".js") || !individualSources.isEmpty()) {
System.out.println("Especificando archivos para incluir fuentes js");
individualSources.addAll(Arrays.asList(srcdir.listFiles()));
break;
}
}
}
if (!individualSources.isEmpty()) {
jsc.setSourceFiles(individualSources);
}
jsc.stopOnErrors(true);
boolean ok = jsc.generate();
jsc.printErrors(new java.io.PrintWriter(System.out));
if (ok) {
System.out.println("OK");
} else {
System.out.println("EXIT CODE: " + jsc.getExitCode());
}
}
use of org.eclipse.ceylon.compiler.typechecker.TypeChecker in project ceylon by eclipse.
the class TestJavaDeps method testJavaDependencies.
@Test
public void testJavaDependencies() throws IOException {
final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
final TypeCheckerBuilder builder = new TypeCheckerBuilder().setRepositoryManager(repoman).addSrcDirectory(new File("src/test/resources/javadeps"));
final TypeChecker tc = builder.getTypeChecker();
tc.process();
final Options opts = new Options().addSrcDir("src/test/resources/javadeps").outRepo("./build").comment(false).generateSourceArchive(false).encoding("UTF-8");
final JsCompiler comp = new JsCompiler(tc, opts);
comp.generate();
}
Aggregations