[java] Less raw types

GitOrigin-RevId: 0bb21ea1ab22c45d79e74e8c839c6b8495a9036a
This commit is contained in:
Tagir Valeev
2024-09-17 10:55:16 +02:00
committed by intellij-monorepo-bot
parent aee119040c
commit 33a3a3d3d9
12 changed files with 57 additions and 74 deletions

View File

@@ -134,19 +134,15 @@ public final class AsmCodeGenerator {
fis.close();
}
FileOutputStream fos = new FileOutputStream(classFile);
try {
try (FileOutputStream fos = new FileOutputStream(classFile)) {
fos.write(patchedData);
}
finally {
fos.close();
}
}
catch (IOException e) {
myErrors.add(new FormErrorInfo(null, "Cannot read or write class file " + classFile.getPath() + ": " + e.toString()));
myErrors.add(new FormErrorInfo(null, "Cannot read or write class file " + classFile.getPath() + ": " + e));
}
catch(IllegalStateException e) {
myErrors.add(new FormErrorInfo(null, "Unexpected data in form file when patching class " + classFile.getPath() + ": " + e.toString()));
myErrors.add(new FormErrorInfo(null, "Unexpected data in form file when patching class " + classFile.getPath() + ": " + e));
}
}
@@ -313,7 +309,7 @@ public final class AsmCodeGenerator {
final String rootBinding = myRootContainer.getComponent(0).getBinding();
if (rootBinding != null && myFieldDescMap.containsKey(rootBinding)) {
buildGetRootComponenMethod();
buildGetRootComponentMethod();
}
if (myGetFontMethod != null) {
@@ -328,7 +324,7 @@ public final class AsmCodeGenerator {
super.visitEnd();
}
private void buildGetRootComponenMethod() {
private void buildGetRootComponentMethod() {
final Type componentType = Type.getType(JComponent.class);
final Method method = new Method(GET_ROOT_COMPONENT_METHOD_NAME, componentType, new Type[0]);
GeneratorAdapter generator = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, method, null, null, cv);
@@ -623,11 +619,10 @@ public final class AsmCodeGenerator {
final InstrumentationClassFinder.PseudoClass componentClass,
final GeneratorAdapter generator,
final int componentLocal) throws CodeGenerationException {
for (Object o : lwComponent.getDelegeeClientProperties().entrySet()) {
Map.Entry e = (Map.Entry)o;
for (Map.Entry<String, Object> e : lwComponent.getDelegeeClientProperties().entrySet()) {
generator.loadLocal(componentLocal);
generator.push((String)e.getKey());
generator.push(e.getKey());
Object value = e.getValue();
if (value instanceof StringDescriptor) {

View File

@@ -10,11 +10,10 @@ import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public final class CompiledClassPropertiesProvider implements PropertiesProvider {
private final ClassLoader myLoader;
private final HashMap<String, Map<String, LwIntrospectedProperty>> myCache;
private final HashMap<String, HashMap<String, LwIntrospectedProperty>> myCache;
public CompiledClassPropertiesProvider(final ClassLoader loader) {
if (loader == null) {
@@ -25,16 +24,16 @@ public final class CompiledClassPropertiesProvider implements PropertiesProvider
}
@Override
public HashMap getLwProperties(final String className) {
public HashMap<String, LwIntrospectedProperty> getLwProperties(final String className) {
if (myCache.containsKey(className)) {
return (HashMap)myCache.get(className);
return myCache.get(className);
}
if (Utils.validateJComponentClass(myLoader, className, false) != null) {
return null;
}
final Class aClass;
final Class<?> aClass;
try {
aClass = Class.forName(className, false, myLoader);
}
@@ -55,7 +54,7 @@ public final class CompiledClassPropertiesProvider implements PropertiesProvider
for (final PropertyDescriptor descriptor : descriptors) {
final Method readMethod = descriptor.getReadMethod();
final Method writeMethod = descriptor.getWriteMethod();
final Class propertyType = descriptor.getPropertyType();
final Class<?> propertyType = descriptor.getPropertyType();
if (writeMethod == null || readMethod == null || propertyType == null) {
continue;
}

View File

@@ -21,7 +21,6 @@ import org.jdom.Element;
import java.awt.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -31,7 +30,7 @@ public abstract class LwComponent implements IComponent{
*/
private String myId;
/**
* may be null
* could be null
*/
private String myBinding;
/**
@@ -55,13 +54,13 @@ public abstract class LwComponent implements IComponent{
*/
private final Rectangle myBounds;
private final HashMap myIntrospectedProperty2Value;
private final HashMap<LwIntrospectedProperty, Object> myIntrospectedProperty2Value;
/**
* if class is unknown (cannot be loaded), properties tag is stored as is
* if class is unknown (cannot be loaded), property tag is stored as is
*/
private Element myErrorComponentProperties;
protected final HashMap myClientProperties;
protected final HashMap myDelegeeClientProperties;
protected final HashMap<Object, Object> myClientProperties;
protected final HashMap<String, Object> myDelegeeClientProperties;
private boolean myCustomCreate = false;
private boolean myDefaultBinding = false;
@@ -71,10 +70,10 @@ public abstract class LwComponent implements IComponent{
}
myBounds = new Rectangle();
myConstraints = new GridConstraints();
myIntrospectedProperty2Value = new LinkedHashMap();
myIntrospectedProperty2Value = new LinkedHashMap<>();
myClassName = className;
myClientProperties = new LinkedHashMap();
myDelegeeClientProperties = new LinkedHashMap();
myClientProperties = new LinkedHashMap<>();
myDelegeeClientProperties = new LinkedHashMap<>();
}
@Override
@@ -121,8 +120,7 @@ public abstract class LwComponent implements IComponent{
}
/**
* @return component's constraints in XY layout. This method rever
* returns {@code null}.
* @return component's constraints in XY layout.
*/
public final Rectangle getBounds(){
return (Rectangle)myBounds.clone();
@@ -190,12 +188,7 @@ public abstract class LwComponent implements IComponent{
}
public final LwIntrospectedProperty[] getAssignedIntrospectedProperties() {
final LwIntrospectedProperty[] properties = new LwIntrospectedProperty[myIntrospectedProperty2Value.size()];
final Iterator iterator = myIntrospectedProperty2Value.keySet().iterator();
for (int i=0; iterator.hasNext(); i++) {
properties[i] = (LwIntrospectedProperty)iterator.next();
}
return properties;
return myIntrospectedProperty2Value.keySet().toArray(new LwIntrospectedProperty[0]);
}
/**
@@ -224,7 +217,7 @@ public abstract class LwComponent implements IComponent{
propertiesElement = new Element(UIFormXmlConstants.ELEMENT_PROPERTIES, element.getNamespace());
}
final HashMap name2property = provider.getLwProperties(getComponentClassName());
final HashMap<String, LwIntrospectedProperty> name2property = provider.getLwProperties(getComponentClassName());
if (name2property == null) {
myErrorComponentProperties = propertiesElement.clone();
return;
@@ -233,7 +226,7 @@ public abstract class LwComponent implements IComponent{
final List<Element> propertyElements = propertiesElement.getChildren();
for (Element t : propertyElements) {
final String name = t.getName();
final LwIntrospectedProperty property = (LwIntrospectedProperty)name2property.get(name);
final LwIntrospectedProperty property = name2property.get(name);
if (property == null){
continue;
}
@@ -268,7 +261,7 @@ public abstract class LwComponent implements IComponent{
lwProp = new LwIntroPrimitiveTypeProperty(propName, Double.class);
}
else {
Class propClass;
Class<?> propClass;
try {
propClass = Class.forName(className);
}
@@ -329,7 +322,7 @@ public abstract class LwComponent implements IComponent{
myClientProperties.put(key, value);
}
public HashMap getDelegeeClientProperties() {
public HashMap<String, Object> getDelegeeClientProperties() {
return myDelegeeClientProperties;
}
}

View File

@@ -25,5 +25,5 @@ public interface PropertiesProvider {
* @return key - property name (String), value - LwProperty. If class cannot be inspected for some reason,
* returns null
*/
HashMap getLwProperties(String className);
HashMap<String, LwIntrospectedProperty> getLwProperties(String className);
}

View File

@@ -103,7 +103,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
private JPanel createParametersPanel () {
myThisClassesMap = MoveInstanceMembersUtil.getThisClassesToMembers(myMethod);
myOldClassParameterNameFields = new HashMap<>();
if (myThisClassesMap.size() == 0) return null;
if (myThisClassesMap.isEmpty()) return null;
JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
for (PsiClass aClass : myThisClassesMap.keySet()) {
final String text = JavaRefactoringBundle.message("move.method.this.parameter.label", ObjectUtils.notNull(aClass.getName(), ""));
@@ -147,7 +147,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
}
@Override
protected void updateOnChanged(JList list) {
protected void updateOnChanged(JList<?> list) {
super.updateOnChanged(list);
final PsiVariable selectedValue = (PsiVariable)list.getSelectedValue();
if (selectedValue != null) {

View File

@@ -37,7 +37,7 @@ public abstract class MoveInstanceMethodDialogBase extends MoveDialogBase {
return myList;
}
protected JList myList;
protected JList<Object> myList;
protected JavaVisibilityPanel myVisibilityPanel;
protected final @NlsContexts.DialogTitle String myRefactoringName;
@@ -73,8 +73,8 @@ public abstract class MoveInstanceMethodDialogBase extends MoveDialogBase {
return hBox;
}
protected JList createTargetVariableChooser() {
final JList list = new JBList(new MyListModel());
protected JList<Object> createTargetVariableChooser() {
final JList<Object> list = new JBList<>(new MyListModel());
list.setCellRenderer(new MyListCellRenderer());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
@@ -88,7 +88,7 @@ public abstract class MoveInstanceMethodDialogBase extends MoveDialogBase {
return list;
}
protected void updateOnChanged(JList list) {
protected void updateOnChanged(JList<?> list) {
getOKAction().setEnabled(!list.getSelectionModel().isSelectionEmpty());
}
@@ -120,7 +120,7 @@ public abstract class MoveInstanceMethodDialogBase extends MoveDialogBase {
return true;
}
private class MyListModel extends AbstractListModel {
private class MyListModel extends AbstractListModel<Object> {
@Override
public int getSize() {
return myVariables.length;

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.rename.inplace;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -13,9 +12,7 @@ import java.util.HashMap;
import java.util.Map;
class JavaResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot {
private static final Logger LOG = Logger.getInstance(JavaResolveSnapshot.class);
private final Map<SmartPsiElementPointer, SmartPsiElementPointer> myReferencesMap = new HashMap<>();
private final Map<SmartPsiElementPointer<?>, SmartPsiElementPointer<?>> myReferencesMap = new HashMap<>();
private final Project myProject;
private final Document myDocument;
@@ -23,15 +20,15 @@ class JavaResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot {
myProject = scope.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile());
final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject);
final Map<PsiElement, SmartPsiElementPointer> pointers = new HashMap<>();
final Map<PsiElement, SmartPsiElementPointer<?>> pointers = new HashMap<>();
scope.accept(new JavaRecursiveElementWalkingVisitor() {
@Override public void visitReferenceExpression(@NotNull PsiReferenceExpression refExpr) {
if (!refExpr.isQualified()) {
JavaResolveResult resolveResult = refExpr.advancedResolve(false);
final PsiElement resolved = resolveResult.getElement();
if ((resolved instanceof PsiField || resolved instanceof PsiClass) && resolveResult.isStaticsScopeCorrect()) {
SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr);
SmartPsiElementPointer value = pointers.get(resolved);
SmartPsiElementPointer<?> key = pointerManager.createSmartPsiElementPointer(refExpr);
SmartPsiElementPointer<?> value = pointers.get(resolved);
if (value == null) {
value = pointerManager.createSmartPsiElementPointer(resolved);
pointers.put(resolved, value);
@@ -47,7 +44,7 @@ class JavaResolveSnapshot extends ResolveSnapshotProvider.ResolveSnapshot {
@Override
public void apply(String hidingLocalName) {
PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
for (Map.Entry<SmartPsiElementPointer,SmartPsiElementPointer> entry : myReferencesMap.entrySet()) {
for (Map.Entry<SmartPsiElementPointer<?>, SmartPsiElementPointer<?>> entry : myReferencesMap.entrySet()) {
qualify(entry.getKey().getElement(), entry.getValue().getElement(), hidingLocalName);
}
}

View File

@@ -12,7 +12,7 @@ import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
public abstract class ClsMemberImpl<T extends PsiMemberStub> extends ClsRepositoryPsiElement<T> implements PsiDocCommentOwner, PsiNameIdentifierOwner {
public abstract class ClsMemberImpl<T extends PsiMemberStub<?>> extends ClsRepositoryPsiElement<T> implements PsiDocCommentOwner, PsiNameIdentifierOwner {
private final NotNullLazyValue<PsiDocComment> myDocComment;
private final NotNullLazyValue<PsiIdentifier> myNameIdentifier;

View File

@@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public abstract class ClsRepositoryPsiElement<T extends StubElement> extends ClsElementImpl implements StubBasedPsiElement<T> {
public abstract class ClsRepositoryPsiElement<T extends StubElement<?>> extends ClsElementImpl implements StubBasedPsiElement<T> {
private final T myStub;
protected ClsRepositoryPsiElement(final T stub) {
@@ -50,7 +50,7 @@ public abstract class ClsRepositoryPsiElement<T extends StubElement> extends Cls
@Override
public PsiFile getContainingFile() {
StubElement p = myStub;
StubElement<?> p = myStub;
while (!(p instanceof PsiFileStub)) {
p = p.getParentStub();
}
@@ -70,8 +70,8 @@ public abstract class ClsRepositoryPsiElement<T extends StubElement> extends Cls
@Override
public PsiElement @NotNull [] getChildren() {
@SuppressWarnings("unchecked") List<StubElement> stubs = getStub().getChildrenStubs();
if (stubs.size() == 0) return EMPTY_ARRAY;
List<StubElement<?>> stubs = getStub().getChildrenStubs();
if (stubs.isEmpty()) return EMPTY_ARRAY;
PsiElement[] children = new PsiElement[stubs.size()];
for (int i = 0; i < stubs.size(); i++) {
children[i] = stubs.get(i).getPsi();
@@ -81,13 +81,13 @@ public abstract class ClsRepositoryPsiElement<T extends StubElement> extends Cls
@Override
public PsiElement getFirstChild() {
@SuppressWarnings("unchecked") List<StubElement> children = getStub().getChildrenStubs();
List<StubElement<?>> children = getStub().getChildrenStubs();
return children.isEmpty() ? null : children.get(0).getPsi();
}
@Override
public PsiElement getLastChild() {
@SuppressWarnings("unchecked") List<StubElement> children = getStub().getChildrenStubs();
List<StubElement<?>> children = getStub().getChildrenStubs();
return children.isEmpty() ? null : children.get(children.size() - 1).getPsi();
}

View File

@@ -10,7 +10,7 @@ public final class MethodInvoker {
// TODO: may leak objects here
static ThreadLocal<Object> returnValue = new ThreadLocal<>();
public static Object invoke(Class cls, Object obj, String name, Class[] parameterTypes, Object[] args)
public static Object invoke(Class<?> cls, Object obj, String name, Class<?>[] parameterTypes, Object[] args)
throws Throwable {
ArrayList<Method> methods = new ArrayList<>();
// TODO: better collect methods lazily
@@ -40,17 +40,17 @@ public final class MethodInvoker {
}
//TODO: avoid recursion
private static void addMatchingMethods(List<Method> methods, Class cls, String name, Class[] parameterTypes) {
private static void addMatchingMethods(List<Method> methods, Class<?> cls, String name, Class<?>[] parameterTypes) {
try {
methods.add(cls.getDeclaredMethod(name, parameterTypes));
}
catch (NoSuchMethodException ignored) {
}
Class superclass = cls.getSuperclass();
Class<?> superclass = cls.getSuperclass();
if (superclass != null) {
addMatchingMethods(methods, superclass, name, parameterTypes);
}
for (Class anInterface : cls.getInterfaces()) {
for (Class<?> anInterface : cls.getInterfaces()) {
addMatchingMethods(methods, anInterface, name, parameterTypes);
}
}

View File

@@ -20,7 +20,7 @@ import java.util.HashMap;
public final class PsiPropertiesProvider implements PropertiesProvider {
private final Module myModule;
private final HashMap<String, HashMap> myCache;
private final HashMap<String, HashMap<String, LwIntrospectedProperty>> myCache;
public PsiPropertiesProvider(final @NotNull Module module) {
myModule = module;
@@ -28,7 +28,7 @@ public final class PsiPropertiesProvider implements PropertiesProvider {
}
@Override
public @Nullable HashMap getLwProperties(final String className) {
public @Nullable HashMap<String, LwIntrospectedProperty> getLwProperties(final String className) {
if (myCache.containsKey(className)) {
return myCache.get(className);
}
@@ -40,11 +40,11 @@ public final class PsiPropertiesProvider implements PropertiesProvider {
return null;
}
final HashMap result = new HashMap();
final HashMap<String, LwIntrospectedProperty> result = new HashMap<>();
final PsiMethod[] methods = aClass.getAllMethods();
for (final PsiMethod method : methods) {
// it's a setter candidate.. try to find getter
// it's a setter candidate. try to find getter
if (!PropertyUtilBase.isSimplePropertySetter(method)) {
continue;

View File

@@ -977,11 +977,10 @@ public final class FormSourceCodeGenerator {
}
private void generateClientProperties(final LwComponent component, final String variable) throws CodeGenerationException {
HashMap props = component.getDelegeeClientProperties();
for (final Object o : props.entrySet()) {
Map.Entry e = (Map.Entry)o;
HashMap<String, Object> props = component.getDelegeeClientProperties();
for (final Map.Entry<String, Object> e : props.entrySet()) {
startMethodCall(variable, "putClientProperty");
push((String) e.getKey());
push(e.getKey());
Object value = e.getValue();
if (value instanceof StringDescriptor) {