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.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
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
*/
public class MetaInfServices {
public static List<JetFile> loadServicesFiles(String metaInfServicesFile, Project project) {
public final class MetaInfServices {
private MetaInfServices() {
}
public static List<JetFile> loadServicesFiles(@NotNull String metaInfServicesFile, @NotNull Project project) {
List<JetFile> libFiles = new ArrayList<JetFile>();
Set<URL> urlsLoaded = new HashSet<URL>();
try {
@@ -40,49 +44,48 @@ public class MetaInfServices {
loadLibFiles(resources, urlsLoaded, libFiles, project);
resources = Thread.currentThread().getContextClassLoader().getResources(metaInfServicesFile);
loadLibFiles(resources, urlsLoaded, libFiles, project);
} catch (IOException e) {
}
catch (IOException e) {
throw new IllegalStateException(e);
}
return libFiles;
}
protected static void loadLibFiles(Enumeration<URL> resources, Set<URL> urlsLoaded, List<JetFile> libFiles, Project project) throws IOException {
while (resources != null && resources.hasMoreElements()) {
private static void loadLibFiles(@NotNull Enumeration<URL> resources,
@NotNull Set<URL> urlsLoaded,
@NotNull List<JetFile> libFiles,
@NotNull Project project)
throws IOException {
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
if (url != null) {
if (urlsLoaded.add(url)) {
System.out.println("Loading Kotlin JS library file: " + url);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
try {
while (true) {
String line = reader.readLine();
if (line == null) {
break;
} else {
}
else {
line = line.trim();
if (line.length() == 0 || line.startsWith("#")) continue;
// lets try to discover the file
InputStream stream = loadClasspathResource(line);
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);
if (stream != null) {
String text = FileUtil.loadTextAndClose(stream);
JetFile file = JetFileUtils.createPsiFile(line, text, project);
if (file != null) {
//System.out.println("Parsing file: " + text);
libFiles.add(file);
}
libFiles.add(file);
}
}
}
} finally {
}
finally {
reader.close();
}
}
}
}
}
/**
@@ -48,7 +48,6 @@ public class ZippedLibrarySourcesConfig extends Config {
@NotNull
@Override
public List<JetFile> generateLibFiles() {
System.out.println("Parsing JS library source zip: " + pathToLibZip);
if (pathToLibZip == null) {
return Collections.emptyList();
}
@@ -63,8 +62,6 @@ public class ZippedLibrarySourcesConfig extends Config {
}
}
catch (IOException e) {
System.out.println("Failed to process " + pathToLibZip + ". Reason: " + e);
e.printStackTrace();
return Collections.emptyList();
}
}
@@ -79,7 +76,6 @@ public class ZippedLibrarySourcesConfig extends Config {
InputStream stream = file.getInputStream(entry);
String text = FileUtil.loadTextAndClose(stream);
JetFile jetFile = JetFileUtils.createPsiFile(entry.getName(), text, getProject());
System.out.println("Parsing file: " + entry.getName());
result.add(jetFile);
}
}
@@ -16,7 +16,6 @@
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.JsName;
import org.jetbrains.annotations.NotNull;
@@ -58,7 +57,7 @@ public final class ReferenceTranslator {
public static JsExpression translateAsLocalNameReference(@NotNull DeclarationDescriptor referencedDescriptor,
@NotNull TranslationContext 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();
}
@@ -70,11 +69,11 @@ public final class ReferenceTranslator {
DeclarationDescriptor effectiveDescriptor;
if (context.isEcma5() && referencedDescriptor instanceof PropertyAccessorDescriptor) {
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 {
effectiveDescriptor = referencedDescriptor;
Preconditions.checkNotNull(effectiveDescriptor, "No referencedDescriptor available");
// Preconditions.checkNotNull(effectiveDescriptor, "No referencedDescriptor available");
}
return effectiveDescriptor;
}
@@ -16,7 +16,6 @@
package org.jetbrains.k2js.translate.utils;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -189,12 +188,11 @@ public final class BindingUtils {
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
@NotNull JetReferenceExpression reference) {
DeclarationDescriptor referencedDescriptor = getNullableDescriptorForReferenceExpression(context, reference);
Preconditions.checkNotNull(referencedDescriptor, "Reference expression must reference a descriptor for reference %s at %s", reference.getText(),
DiagnosticUtils.atLocation(reference));
assert referencedDescriptor != null : "Reference expression must reference a descriptor for reference " + reference.getText() +
" at " + DiagnosticUtils.atLocation(reference);
return referencedDescriptor;
}
//TODO: remove?
@Nullable
public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context,
@NotNull JetReferenceExpression reference) {