Cleanup (internal API usages)

This commit is contained in:
Roman Shevchenko
2015-12-02 16:00:36 +01:00
parent 152b6f65e2
commit 4fae71c186
3 changed files with 43 additions and 21 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,17 +23,13 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.lang.UrlClassLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import sun.misc.CompoundEnumeration;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.ListIterator;
import java.util.*;
/**
* @author Eugene Zhuravlev
@@ -170,12 +166,12 @@ public class PluginClassLoader extends UrlClassLoader {
@Override
public Enumeration<URL> findResources(final String name) throws IOException {
final Enumeration[] resources = new Enumeration[myParents.length + 1];
@SuppressWarnings("unchecked") Enumeration<URL>[] resources = new Enumeration[myParents.length + 1];
resources[0] = super.findResources(name);
for (int idx = 0; idx < myParents.length; idx++) {
resources[idx + 1] = fetchResources(myParents[idx], name);
}
return new CompoundEnumeration<URL>(resources);
return new DeepEnumeration(resources);
}
@SuppressWarnings("UnusedDeclaration")
@@ -201,8 +197,8 @@ public class PluginClassLoader extends UrlClassLoader {
private static URL fetchResource(ClassLoader cl, String resourceName) {
try {
final Method findResourceMethod = getFindResourceMethod(cl.getClass(), "findResource");
return (URL)findResourceMethod.invoke(cl, resourceName);
Method findResource = getFindResourceMethod(cl.getClass(), "findResource");
return findResource != null ? (URL)findResource.invoke(cl, resourceName) : null;
}
catch (Exception e) {
Logger.getInstance(PluginClassLoader.class).error(e);
@@ -210,10 +206,11 @@ public class PluginClassLoader extends UrlClassLoader {
}
}
private static Enumeration fetchResources(ClassLoader cl, String resourceName) {
private static Enumeration<URL> fetchResources(ClassLoader cl, String resourceName) {
try {
final Method findResourceMethod = getFindResourceMethod(cl.getClass(), "findResources");
return findResourceMethod == null ? null : (Enumeration)findResourceMethod.invoke(cl, resourceName);
Method findResources = getFindResourceMethod(cl.getClass(), "findResources");
@SuppressWarnings("unchecked") Enumeration<URL> e = findResources == null ? null : (Enumeration)findResources.invoke(cl, resourceName);
return e;
}
catch (Exception e) {
Logger.getInstance(PluginClassLoader.class).error(e);
@@ -244,4 +241,31 @@ public class PluginClassLoader extends UrlClassLoader {
public String toString() {
return "PluginClassLoader[" + myPluginId + ", " + myPluginVersion + "]";
}
}
private static class DeepEnumeration implements Enumeration<URL> {
private final Enumeration<URL>[] myEnumerations;
private int myIndex = 0;
public DeepEnumeration(Enumeration<URL>[] enumerations) {
myEnumerations = enumerations;
}
@Override
public boolean hasMoreElements() {
while (myIndex < myEnumerations.length) {
Enumeration<URL> e = myEnumerations[myIndex];
if (e != null && e.hasMoreElements()) return true;
myIndex++;
}
return false;
}
@Override
public URL nextElement() {
if (!hasMoreElements()) {
throw new NoSuchElementException();
}
return myEnumerations[myIndex].nextElement();
}
}
}
@@ -3,10 +3,10 @@ package org.jetbrains.plugins.ipnb.editor.panels.code;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.Base64;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil;
import org.jetbrains.plugins.ipnb.format.cells.output.IpnbImageOutputCell;
import sun.misc.BASE64Decoder;
import javax.imageio.ImageIO;
import javax.swing.*;
@@ -28,7 +28,7 @@ public class IpnbImagePanel extends IpnbCodeOutputPanel<IpnbImageOutputCell> {
final JBLabel label = new JBLabel();
if (!StringUtil.isEmptyOrSpaces(png)) {
try {
byte[] btDataFile = new BASE64Decoder().decodeBuffer(png);
byte[] btDataFile = Base64.decode(png);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(btDataFile));
label.setIcon(new ImageIcon(image));
}
@@ -21,12 +21,12 @@ import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.PsiManager;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.HashSet;
import com.sun.org.apache.xerces.internal.util.XML11Char;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;
import org.intellij.plugins.relaxNG.compact.psi.RncFile;
import org.intellij.plugins.relaxNG.compact.psi.RncGrammar;
import org.jdom.Verifier;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -71,10 +71,8 @@ public class RenameUtil {
if (name == null) {
return false;
}
if (XML11Char.isXML11ValidNCName(name)) {
return true;
}
return name.length() >= 2 && name.startsWith("\\") && XML11Char.isXML11ValidNCName(name.substring(1));
return Verifier.checkXMLName(name) == null ||
name.length() >= 2 && name.charAt(0) == '\\' && Verifier.checkXMLName(name.substring(1)) == null;
}
public static boolean isKeyword(String name) {