Clean up some code commenting out preconditions for now

This commit is contained in:
pTalanov
2012-06-01 15:42:50 +04:00
parent cbcee10618
commit 144fef96cd
4 changed files with 25 additions and 29 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.k2js.config;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.k2js.utils.JetFileUtils; import org.jetbrains.k2js.utils.JetFileUtils;
@@ -31,8 +32,11 @@ import java.util.*;
/** /**
* A helper class to discover a META-INF/services file on the classpath and load the files referenced inside it * A helper class to discover a META-INF/services file on the classpath and load the files referenced inside it
*/ */
public class MetaInfServices { public final class MetaInfServices {
public static List<JetFile> loadServicesFiles(String metaInfServicesFile, Project project) { private MetaInfServices() {
}
public static List<JetFile> loadServicesFiles(@NotNull String metaInfServicesFile, @NotNull Project project) {
List<JetFile> libFiles = new ArrayList<JetFile>(); List<JetFile> libFiles = new ArrayList<JetFile>();
Set<URL> urlsLoaded = new HashSet<URL>(); Set<URL> urlsLoaded = new HashSet<URL>();
try { try {
@@ -40,49 +44,48 @@ public class MetaInfServices {
loadLibFiles(resources, urlsLoaded, libFiles, project); loadLibFiles(resources, urlsLoaded, libFiles, project);
resources = Thread.currentThread().getContextClassLoader().getResources(metaInfServicesFile); resources = Thread.currentThread().getContextClassLoader().getResources(metaInfServicesFile);
loadLibFiles(resources, urlsLoaded, libFiles, project); loadLibFiles(resources, urlsLoaded, libFiles, project);
} catch (IOException e) { }
catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
return libFiles; return libFiles;
} }
protected static void loadLibFiles(Enumeration<URL> resources, Set<URL> urlsLoaded, List<JetFile> libFiles, Project project) throws IOException { private static void loadLibFiles(@NotNull Enumeration<URL> resources,
while (resources != null && resources.hasMoreElements()) { @NotNull Set<URL> urlsLoaded,
@NotNull List<JetFile> libFiles,
@NotNull Project project)
throws IOException {
while (resources.hasMoreElements()) {
URL url = resources.nextElement(); URL url = resources.nextElement();
if (url != null) { if (url != null) {
if (urlsLoaded.add(url)) { if (urlsLoaded.add(url)) {
System.out.println("Loading Kotlin JS library file: " + url);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
try { try {
while (true) { while (true) {
String line = reader.readLine(); String line = reader.readLine();
if (line == null) { if (line == null) {
break; break;
} else { }
else {
line = line.trim(); line = line.trim();
if (line.length() == 0 || line.startsWith("#")) continue; if (line.length() == 0 || line.startsWith("#")) continue;
// lets try to discover the file // lets try to discover the file
InputStream stream = loadClasspathResource(line); InputStream stream = loadClasspathResource(line);
if (stream == null) { if (stream != null) {
System.out.println("WARNING: failed to find JS source file: " + line + " on the classpath");
} else {
//System.out.println("Loading JS library file: " + line);
String text = FileUtil.loadTextAndClose(stream); String text = FileUtil.loadTextAndClose(stream);
JetFile file = JetFileUtils.createPsiFile(line, text, project); JetFile file = JetFileUtils.createPsiFile(line, text, project);
if (file != null) { libFiles.add(file);
//System.out.println("Parsing file: " + text);
libFiles.add(file);
}
} }
} }
} }
} finally { }
finally {
reader.close(); reader.close();
} }
} }
} }
} }
} }
/** /**
@@ -48,7 +48,6 @@ public class ZippedLibrarySourcesConfig extends Config {
@NotNull @NotNull
@Override @Override
public List<JetFile> generateLibFiles() { public List<JetFile> generateLibFiles() {
System.out.println("Parsing JS library source zip: " + pathToLibZip);
if (pathToLibZip == null) { if (pathToLibZip == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -63,8 +62,6 @@ public class ZippedLibrarySourcesConfig extends Config {
} }
} }
catch (IOException e) { catch (IOException e) {
System.out.println("Failed to process " + pathToLibZip + ". Reason: " + e);
e.printStackTrace();
return Collections.emptyList(); return Collections.emptyList();
} }
} }
@@ -79,7 +76,6 @@ public class ZippedLibrarySourcesConfig extends Config {
InputStream stream = file.getInputStream(entry); InputStream stream = file.getInputStream(entry);
String text = FileUtil.loadTextAndClose(stream); String text = FileUtil.loadTextAndClose(stream);
JetFile jetFile = JetFileUtils.createPsiFile(entry.getName(), text, getProject()); JetFile jetFile = JetFileUtils.createPsiFile(entry.getName(), text, getProject());
System.out.println("Parsing file: " + entry.getName());
result.add(jetFile); result.add(jetFile);
} }
} }
@@ -16,7 +16,6 @@
package org.jetbrains.k2js.translate.reference; package org.jetbrains.k2js.translate.reference;
import com.google.common.base.Preconditions;
import com.google.dart.compiler.backend.js.ast.JsExpression; import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsName; import com.google.dart.compiler.backend.js.ast.JsName;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -58,7 +57,7 @@ public final class ReferenceTranslator {
public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor, public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor,
@NotNull TranslationContext context) { @NotNull TranslationContext context) {
DeclarationDescriptor effectiveDescriptor = getReferencedDescriptor(referencedDescriptor, context); DeclarationDescriptor effectiveDescriptor = getReferencedDescriptor(referencedDescriptor, context);
Preconditions.checkNotNull(effectiveDescriptor, "Could not find DeclarationDescriptor for %s", referencedDescriptor); // Preconditions.checkNotNull(effectiveDescriptor, "Could not find DeclarationDescriptor for %s", referencedDescriptor);
return context.getNameForDescriptor(effectiveDescriptor).makeRef(); return context.getNameForDescriptor(effectiveDescriptor).makeRef();
} }
@@ -70,11 +69,11 @@ public final class ReferenceTranslator {
DeclarationDescriptor effectiveDescriptor; DeclarationDescriptor effectiveDescriptor;
if (context.isEcma5() && referencedDescriptor instanceof PropertyAccessorDescriptor) { if (context.isEcma5() && referencedDescriptor instanceof PropertyAccessorDescriptor) {
effectiveDescriptor = ((PropertyAccessorDescriptor) referencedDescriptor).getCorrespondingProperty(); effectiveDescriptor = ((PropertyAccessorDescriptor) referencedDescriptor).getCorrespondingProperty();
Preconditions.checkNotNull(effectiveDescriptor, "No correspondingProperty available for descriptor %s", referencedDescriptor); // Preconditions.checkNotNull(effectiveDescriptor, "No correspondingProperty available for descriptor %s", referencedDescriptor);
} }
else { else {
effectiveDescriptor = referencedDescriptor; effectiveDescriptor = referencedDescriptor;
Preconditions.checkNotNull(effectiveDescriptor, "No referencedDescriptor available"); // Preconditions.checkNotNull(effectiveDescriptor, "No referencedDescriptor available");
} }
return effectiveDescriptor; return effectiveDescriptor;
} }
@@ -16,7 +16,6 @@
package org.jetbrains.k2js.translate.utils; package org.jetbrains.k2js.translate.utils;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -189,12 +188,11 @@ public final class BindingUtils {
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context, public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
@NotNull JetReferenceExpression reference) { @NotNull JetReferenceExpression reference) {
DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference); DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference);
Preconditions.checkNotNull(referencedDescriptor, "Reference expression must reference a descriptor for reference %s at %s", reference.getText(), assert referencedDescriptor != null : "Reference expression must reference a descriptor for reference " + reference.getText() +
DiagnosticUtils.atLocation(reference)); " at " + DiagnosticUtils.atLocation(reference);
return referencedDescriptor; return referencedDescriptor;
} }
//TODO: remove?
@Nullable @Nullable
public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context, public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context,
@NotNull JetReferenceExpression reference) { @NotNull JetReferenceExpression reference) {