mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -21,6 +21,8 @@ import com.intellij.debugger.engine.JVMNameUtil;
|
||||
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
|
||||
import com.intellij.debugger.engine.events.SuspendContextCommandImpl;
|
||||
import com.intellij.debugger.impl.DebuggerContextImpl;
|
||||
import com.intellij.debugger.impl.DebuggerUtilsEx;
|
||||
import com.intellij.debugger.jdi.MethodBytecodeUtil;
|
||||
import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
|
||||
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
|
||||
import com.intellij.debugger.ui.tree.ValueDescriptor;
|
||||
@@ -32,6 +34,11 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.sun.jdi.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class JumpToObjectAction extends DebuggerAction{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.JumpToObjectAction");
|
||||
@@ -96,7 +103,35 @@ public class JumpToObjectAction extends DebuggerAction{
|
||||
}
|
||||
if(type instanceof ClassType) {
|
||||
final ClassType clsType = (ClassType)type;
|
||||
final Location location = ContainerUtil.getFirstItem(clsType.allLineLocations());
|
||||
Location lambdaLocation = null;
|
||||
if (DebuggerUtilsEx.isLambdaClassName(clsType.name())) {
|
||||
List<Method> notConstructorMethods = ContainerUtil.filter(clsType.methods(), m -> !m.isConstructor());
|
||||
if (notConstructorMethods.size() == 1) {
|
||||
AtomicReference<Location> locationRef = new AtomicReference<>();
|
||||
MethodBytecodeUtil.visit(clsType, notConstructorMethods.get(0), new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
ReferenceType cls = ContainerUtil.getFirstItem(clsType.virtualMachine().classesByName(owner));
|
||||
if (cls != null) {
|
||||
Method method = ContainerUtil.getFirstItem(cls.methodsByName(name));
|
||||
if (method != null) {
|
||||
try {
|
||||
Location loc = ContainerUtil.getFirstItem(method.allLineLocations());
|
||||
if (loc != null) {
|
||||
locationRef.set(loc);
|
||||
}
|
||||
}
|
||||
catch (AbsentInformationException e) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lambdaLocation = locationRef.get();
|
||||
}
|
||||
}
|
||||
final Location location = lambdaLocation != null ? lambdaLocation : ContainerUtil.getFirstItem(clsType.allLineLocations());
|
||||
if (location != null) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {
|
||||
@Override
|
||||
@@ -118,10 +153,7 @@ public class JumpToObjectAction extends DebuggerAction{
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClassNotPreparedException e) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
catch (AbsentInformationException e) {
|
||||
catch (ClassNotPreparedException | AbsentInformationException e) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
package com.intellij.debugger.jdi;
|
||||
|
||||
import com.sun.jdi.ClassType;
|
||||
import com.sun.jdi.Method;
|
||||
import com.sun.jdi.ReferenceType;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author egor
|
||||
*/
|
||||
public class MethodBytecodeUtil {
|
||||
private MethodBytecodeUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to use ASM MethodVisitor with jdi method bytecode
|
||||
*/
|
||||
public static void visit(ClassType classType, Method method, MethodVisitor methodVisitor) {
|
||||
try {
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos)) {
|
||||
dos.writeInt(0xCAFEBABE); // magic
|
||||
dos.writeInt(Opcodes.V1_8); // version
|
||||
dos.writeShort(classType.constantPoolCount()); // constant_pool_count
|
||||
dos.write(classType.constantPool()); // constant_pool
|
||||
|
||||
// we generate and put code attribute right after the constant pool
|
||||
byte[] bytecodes = method.bytecodes();
|
||||
int codeSize = dos.size();
|
||||
dos.writeShort(0); // max_stack
|
||||
dos.writeShort(0); // max_locals
|
||||
dos.writeInt(bytecodes.length); // code_length
|
||||
dos.write(bytecodes); // code
|
||||
dos.writeShort(0); // exception_table_length
|
||||
dos.writeShort(0); // attributes_count
|
||||
codeSize = dos.size() - codeSize;
|
||||
|
||||
ClassReader clsReader = new ClassReader(bos.toByteArray());
|
||||
ClassWriter clsWriter = new ClassWriter(clsReader, 0);
|
||||
clsWriter.visit(Opcodes.V1_8,
|
||||
Opcodes.ACC_PUBLIC,
|
||||
classType.name(),
|
||||
classType.signature(),
|
||||
classType.superclass().name(),
|
||||
classType.interfaces().stream().map(ReferenceType::name).toArray(String[]::new));
|
||||
MethodVisitor mv = clsWriter.visitMethod(Opcodes.ACC_PUBLIC, method.name(), method.signature(), method.signature(), null);
|
||||
mv.visitAttribute(createCode(clsReader, codeSize));
|
||||
|
||||
new ClassReader(clsWriter.toByteArray()).accept(new ClassVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
return methodVisitor;
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static Attribute createCode(ClassReader cr, int len) {
|
||||
return new Attribute("Code") {
|
||||
@Override
|
||||
public Attribute read(ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) {
|
||||
return super.read(cr, off, len, buf, codeOff, labels);
|
||||
}
|
||||
}.read(cr, cr.header, len, null, 0, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -357,8 +357,10 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
return createToolbar(group);
|
||||
}
|
||||
|
||||
private static JComponent createToolbar(final DefaultActionGroup specialGroup) {
|
||||
return ActionManager.getInstance().createActionToolbar(ActionPlaces.CODE_INSPECTION, specialGroup, false).getComponent();
|
||||
private JComponent createToolbar(final DefaultActionGroup specialGroup) {
|
||||
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CODE_INSPECTION, specialGroup, false);
|
||||
toolbar.setTargetComponent(this);
|
||||
return toolbar.getComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RefElementNode extends SuppressableInspectionTreeNode {
|
||||
|
||||
@Override
|
||||
public int getProblemCount() {
|
||||
return isLeaf() ? 1 : super.getProblemCount();
|
||||
return isLeaf() ? myPresentation.getIgnoredRefElements().contains(getElement()) ? 0 : 1 : super.getProblemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -356,7 +356,7 @@ public final class HttpRequests {
|
||||
}
|
||||
|
||||
private static <T> T process(RequestBuilderImpl builder, RequestProcessor<T> processor) throws IOException {
|
||||
LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed(),
|
||||
LOG.assertTrue(ApplicationManager.getApplication() == null || !ApplicationManager.getApplication().isReadAccessAllowed(),
|
||||
"Network shouldn't be accessed in EDT or inside read action");
|
||||
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
+3
-1
@@ -137,8 +137,10 @@ public final class EditorHistoryManager implements PersistentStateComponent<Elem
|
||||
for (int i = states.length - 1; i >= 0; i--) {
|
||||
final FileEditorProvider provider = oldProviders [i];
|
||||
LOG.assertTrue(provider != null);
|
||||
FileEditor editor = editors[i];
|
||||
if (!editor.isValid()) continue;
|
||||
providers[i] = provider;
|
||||
states[i] = editors[i].getState(FileEditorStateLevel.FULL);
|
||||
states[i] = editor.getState(FileEditorStateLevel.FULL);
|
||||
}
|
||||
addEntry(HistoryEntry.createHeavy(myProject, file, providers, states, providers[selectedProviderIndex]));
|
||||
trimToSize();
|
||||
|
||||
@@ -105,7 +105,11 @@ final class HistoryEntry {
|
||||
|
||||
HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, disposable);
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
entry.putState(providers[i], states[i]);
|
||||
FileEditorProvider provider = providers[i];
|
||||
FileEditorState state = states[i];
|
||||
if (provider != null && state != null) {
|
||||
entry.putState(provider, state);
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -782,9 +782,6 @@ dumb.aware.run.configurations.description=Enable executing run configurations in
|
||||
focus.follows.mouse.workarounds=false
|
||||
focus.follows.mouse.workarounds.description=Enables some workarounds for Focus-follows-mouse issues, like IDEA-112015
|
||||
|
||||
angular.js.ui.router.diagram=false
|
||||
angular.js.ui.router.diagram.description=Enables AngularJS ui-router states&views diagram action
|
||||
|
||||
cidr.xcode.derived.data.override=true
|
||||
cidr.xcode.derived.data.override.description=Ignore Xcode DerivedData location settings
|
||||
|
||||
|
||||
@@ -196,9 +196,6 @@
|
||||
key="non.final.field.compareto.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.CompareToUsesNonFinalVariableInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="CovariantCompareTo" bundle="com.siyeh.InspectionGadgetsBundle" key="covariant.compareto.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.CovariantCompareToInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="CovariantEquals" bundle="com.siyeh.InspectionGadgetsBundle" key="covariant.equals.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.bugs.CovariantEqualsInspection"/>
|
||||
|
||||
-2
@@ -62,8 +62,6 @@ collection.added.to.self.display.name=Collection added to self
|
||||
collection.added.to.self.problem.descriptor=''{0}()'' called on collection <code>#ref</code> with itself as argument #loc
|
||||
non.final.field.compareto.display.name=Non-final field referenced in 'compareTo()'
|
||||
non.final.field.compareto.problem.descriptor=Non-final field <code>#ref</code> accessed in 'compareTo()' #loc
|
||||
covariant.compareto.display.name=Covariant 'compareTo()'
|
||||
covariant.compareto.problem.descriptor=<code>#ref()</code> should take 'Object' as its argument #loc
|
||||
covariant.equals.display.name=Covariant 'equals()'
|
||||
covariant.equals.problem.descriptor=<code>#ref()</code> should take 'Object' as its argument #loc
|
||||
empty.class.initializer.display.name=Empty class initializer
|
||||
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CovariantCompareToInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("covariant.compareto.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message("covariant.compareto.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new CovariantCompareToVisitor();
|
||||
}
|
||||
|
||||
private static class CovariantCompareToVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitMethod(@NotNull PsiMethod method) {
|
||||
final String name = method.getName();
|
||||
if (!HardcodedMethodConstants.COMPARE_TO.equals(name)) {
|
||||
return;
|
||||
}
|
||||
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 1) {
|
||||
return;
|
||||
}
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
final PsiType paramType = parameters[0].getType();
|
||||
if (TypeUtils.isJavaLangObject(paramType)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod[] methods = aClass.findMethodsByName(HardcodedMethodConstants.COMPARE_TO, false);
|
||||
final Project project = method.getProject();
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
|
||||
final GlobalSearchScope scope = method.getResolveScope();
|
||||
final PsiClass comparableClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_COMPARABLE, scope);
|
||||
PsiType substitutedTypeParam = null;
|
||||
if (comparableClass != null && comparableClass.getTypeParameters().length == 1) {
|
||||
final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(comparableClass, aClass, PsiSubstitutor.EMPTY);
|
||||
//null iff aClass is not inheritor of comparableClass
|
||||
if (superSubstitutor != null) {
|
||||
substitutedTypeParam = superSubstitutor.substitute(comparableClass.getTypeParameters()[0]);
|
||||
}
|
||||
}
|
||||
for (PsiMethod compareToMethod : methods) {
|
||||
if (isNonVariantCompareTo(compareToMethod, substitutedTypeParam)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
registerMethodError(method);
|
||||
}
|
||||
|
||||
private static boolean isNonVariantCompareTo(PsiMethod method, PsiType substitutedTypeParam) {
|
||||
final PsiClassType objectType = TypeUtils.getObjectType(method);
|
||||
if (MethodUtils.methodMatches(method, null, PsiType.INT, HardcodedMethodConstants.COMPARE_TO, objectType)) {
|
||||
return true;
|
||||
}
|
||||
if (substitutedTypeParam == null) {
|
||||
return false;
|
||||
}
|
||||
return MethodUtils.methodMatches(method, null, PsiType.INT, HardcodedMethodConstants.COMPARE_TO, substitutedTypeParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports a class having a <b>compareTo()</b>
|
||||
method taking an argument other than <b>java.lang.Object</b>, if the class does not have a <b>compareTo()</b> method
|
||||
which does take <b>java.lang.Object</b> as its argument. Normally, this is a mistake.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
import java.lang.Comparable;
|
||||
|
||||
class Foo implements Comparable<Foo> {
|
||||
public int compareTo(Foo o) {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public int compareTo(String o) {
|
||||
return 0; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class CovariantCompareToInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest("com/siyeh/igtest/bugs/covariantCompareTo/" + getTestName(true), new CovariantCompareToInspection());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user