Cleanup (mostly unused class deprecated, remaining usages rewritten)

This commit is contained in:
Roman Shevchenko
2014-06-27 17:00:27 +02:00
parent 7f307dfe8e
commit 68c351b5cf
5 changed files with 45 additions and 99 deletions

View File

@@ -30,7 +30,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.*;
import com.intellij.util.SmartList;
import com.intellij.util.cls.ClsUtil;
import com.intellij.util.concurrency.SequentialTaskExecutor;
import io.netty.channel.Channel;
import org.jetbrains.annotations.NotNull;
@@ -38,6 +37,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.ide.PooledThreadExecutor;
import org.jetbrains.jps.api.CmdlineProtoUtil;
import org.jetbrains.jps.api.CmdlineRemoteProto;
import org.jetbrains.org.objectweb.asm.Opcodes;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -177,7 +177,7 @@ public abstract class DefaultMessageHandler implements BuilderMessageHandler {
}
else {
for (final PsiField changedField : changedFields) {
if (!accessChanged && ClsUtil.isPrivate(accessFlags)) {
if (!accessChanged && isPrivate(accessFlags)) {
// optimization: don't need to search, cause may be used only in this class
continue;
}
@@ -291,7 +291,7 @@ public abstract class DefaultMessageHandler implements BuilderMessageHandler {
private SearchScope getSearchScope(PsiClass aClass, int fieldAccessFlags) {
SearchScope searchScope = GlobalSearchScope.projectScope(myProject);
if (aClass != null && ClsUtil.isPackageLocal(fieldAccessFlags)) {
if (aClass != null && isPackageLocal(fieldAccessFlags)) {
final PsiFile containingFile = aClass.getContainingFile();
if (containingFile instanceof PsiJavaFile) {
final String packageName = ((PsiJavaFile)containingFile).getPackageName();
@@ -386,4 +386,11 @@ public abstract class DefaultMessageHandler implements BuilderMessageHandler {
return null;
}
private static boolean isPackageLocal(int flags) {
return (Opcodes.ACC_PUBLIC & flags) == 0 && (Opcodes.ACC_PROTECTED & flags) == 0 && (Opcodes.ACC_PRIVATE & flags) == 0;
}
private static boolean isPrivate(int flags) {
return (Opcodes.ACC_PRIVATE & flags) != 0;
}
}

View File

@@ -15,6 +15,7 @@
*/
package com.intellij.util.cls;
/** @deprecated to be removed in IDEA 15 */
public class BytePointer {
public final byte[] bytes;
public int offset;

View File

@@ -16,9 +16,9 @@
package com.intellij.util.cls;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NonNls;
/** @deprecated to be removed in IDEA 15 */
@SuppressWarnings("ALL")
public class ClsUtil {
public static final int MAGIC = 0xCAFEBABE;
@@ -375,56 +375,6 @@ public class ClsUtil {
}
public static String literalToString(CharSequence value, char quote) {
int length = value.length();
@NonNls StringBuilder buffer = new StringBuilder(length + 3);
buffer.append(quote);
for (int i = 0; i < length; i++) {
char c = value.charAt(i);
if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9') {
buffer.append(c);
continue;
}
switch (c) {
case '\b':
buffer.append("\\b");
break;
case '\t':
buffer.append("\\t");
break;
case '\n':
buffer.append("\\n");
break;
case '\f':
buffer.append("\\f");
break;
case '\r':
buffer.append("\\r");
break;
case '\\':
buffer.append("\\\\");
break;
default:
if (c == quote) {
buffer.append("\\").append(quote);
}
else if (Character.isISOControl(c)) {
String hexCode = StringUtil.toUpperCase(Integer.toHexString(c));
buffer.append("\\u");
int paddingCount = 4 - hexCode.length();
while (paddingCount-- > 0) {
buffer.append(0);
}
buffer.append(hexCode);
}
else {
buffer.append(c);
}
}
}
buffer.append(quote);
return buffer.toString();
return quote + StringUtil.escapeStringCharacters(value.toString()) + quote;
}
}

View File

@@ -1,20 +0,0 @@
<!--
~ Copyright 2000-2007 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><body bgcolor="white">
Provides the utilities for parsing compiled Java class files.
</body></html>

View File

@@ -27,14 +27,12 @@ import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.ZipFileCache;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.ArrayUtil;
import com.intellij.util.cls.BytePointer;
import com.intellij.util.cls.ClsFormatException;
import com.intellij.util.cls.ClsUtil;
import icons.DevkitIcons;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -43,16 +41,19 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.DevKitBundle;
import javax.swing.*;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
* User: anna
* Date: Nov 22, 2004
* @author anna
* @since Nov 22, 2004
*/
public class IdeaJdk extends JavaDependentSdkType implements JavaSdkType {
private static final Icon ADD_SDK = DevkitIcons.Add_sdk;
@@ -262,26 +263,33 @@ public class IdeaJdk extends JavaDependentSdkType implements JavaSdkType {
return false;
}
private static int getIdeaClassFileVersion(final Sdk ideaSdk) {
int result = -1;
File apiJar = getOpenApiJar(ideaSdk.getHomePath());
if (apiJar == null) return -1;
final VirtualFile mainClassFile = JarFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(apiJar.getPath()) +
"!/com/intellij/psi/PsiManager.class");
if (mainClassFile != null) {
final BytePointer ptr;
try {
ptr = new BytePointer(mainClassFile.contentsToByteArray(), 6);
result = ClsUtil.readU2(ptr);
}
catch (IOException e) {
// ignore
}
catch (ClsFormatException e) {
// ignore
private static int getIdeaClassFileVersion(Sdk ideaSdk) {
try {
File apiJar = getOpenApiJar(ideaSdk.getHomePath());
if (apiJar != null) {
ZipFile zipFile = ZipFileCache.acquire(apiJar.getPath());
try {
ZipEntry entry = zipFile.getEntry("com/intellij/psi/PsiManager.class");
if (entry != null) {
DataInputStream stream = new DataInputStream(zipFile.getInputStream(entry));
try {
if (stream.skip(6) == 6) {
return stream.readUnsignedShort();
}
}
finally {
stream.close();
}
}
}
finally {
ZipFileCache.release(zipFile);
}
}
}
return result;
catch (IOException ignored) { }
return -1;
}
@Nullable