mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor java global inspection graph: extract writable interfaces
This is needed to avoid access to package-private members in platform modules from java modules (IDEA-200277).
This commit is contained in:
@@ -97,7 +97,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
|
||||
} else {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(containingFile);
|
||||
LOG.assertTrue(module != null);
|
||||
final RefModuleImpl refModule = (RefModuleImpl)getRefManager().getRefModule(module);
|
||||
final WritableRefEntity refModule = (WritableRefEntity)getRefManager().getRefModule(module);
|
||||
LOG.assertTrue(refModule != null);
|
||||
refModule.add(this);
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
|
||||
private void setDefaultConstructor(RefMethodImpl defaultConstructor) {
|
||||
if (defaultConstructor != null) {
|
||||
for (RefClass superClass : getBaseClasses()) {
|
||||
RefMethodImpl superDefaultConstructor = (RefMethodImpl)superClass.getDefaultConstructor();
|
||||
WritableRefElement superDefaultConstructor = (WritableRefElement)superClass.getDefaultConstructor();
|
||||
|
||||
if (superDefaultConstructor != null) {
|
||||
superDefaultConstructor.addInReference(defaultConstructor);
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class RefJavaFileImpl extends RefFileImpl {
|
||||
if (!packageName.isEmpty()) {
|
||||
((RefPackageImpl)getRefManager().getExtension(RefJavaManager.MANAGER).getPackage(packageName)).add(this);
|
||||
} else if (myRefModule != null) {
|
||||
((RefModuleImpl)myRefModule).add(this);
|
||||
((WritableRefEntity)myRefModule).add(this);
|
||||
} else {
|
||||
((RefProjectImpl)manager.getRefProject()).add(this);
|
||||
}
|
||||
|
||||
+3
-3
@@ -510,7 +510,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
if (dataElements.length > 0) {
|
||||
final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psi, PsiModifierListOwner.class);
|
||||
if (listOwner != null) {
|
||||
final RefElementImpl element = (RefElementImpl)myRefManager.getReference(listOwner);
|
||||
final WritableRefElement element = (WritableRefElement)myRefManager.getReference(listOwner);
|
||||
if (element != null) {
|
||||
String suppression = StringUtil.join(dataElements, PsiElement::getText, ",");
|
||||
element.addSuppression(suppression);
|
||||
@@ -566,7 +566,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
private void retrieveSuppressions(UAnnotation annotation, UAnnotated annotated) {
|
||||
if (annotated != null) {
|
||||
PsiElement annotatedSrc = annotated.getSourcePsi();
|
||||
final RefElementImpl element = (RefElementImpl)myRefManager.getReference(annotatedSrc);
|
||||
final WritableRefElement element = (WritableRefElement)myRefManager.getReference(annotatedSrc);
|
||||
if (element != null) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
final List<UNamedExpression> nameValuePairs = annotation.getAttributeValues();
|
||||
@@ -614,7 +614,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
field = (PsiField)psiElement;
|
||||
RefElement refElement = myRefManager.getReference(field);
|
||||
if (refElement != null) {
|
||||
((RefElementImpl)refElement).addSuppression(suppressId);
|
||||
((WritableRefElement)refElement).addSuppression(suppressId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ public class RefJavaModuleImpl extends RefElementImpl implements RefJavaModule {
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
((RefModuleImpl)myRefModule).add(this);
|
||||
((WritableRefEntity)myRefModule).add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,7 +246,7 @@ public class RefJavaModuleImpl extends RefElementImpl implements RefJavaModule {
|
||||
RefElement refElement = getRefManager().getReference(element);
|
||||
if (refElement != null) {
|
||||
addOutReference(refElement);
|
||||
((RefElementImpl)refElement).addInReference(this);
|
||||
((WritableRefElement)refElement).addInReference(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -310,7 +310,7 @@ public class RefJavaUtilImpl extends RefJavaUtil {
|
||||
boolean hasConstructorsMarked = false;
|
||||
|
||||
if (defaultConstructorOnly) {
|
||||
RefMethodImpl refDefaultConstructor = (RefMethodImpl)refClass.getDefaultConstructor();
|
||||
WritableRefElement refDefaultConstructor = (WritableRefElement)refClass.getDefaultConstructor();
|
||||
if (refDefaultConstructor != null) {
|
||||
refDefaultConstructor.addInReference(refFrom);
|
||||
refFrom.addOutReference(refDefaultConstructor);
|
||||
@@ -320,7 +320,7 @@ public class RefJavaUtilImpl extends RefJavaUtil {
|
||||
else {
|
||||
for (RefMethod cons : refClass.getConstructors()) {
|
||||
if (cons instanceof RefImplicitConstructor) continue;
|
||||
((RefMethodImpl)cons).addInReference(refFrom);
|
||||
((WritableRefElement)cons).addInReference(refFrom);
|
||||
refFrom.addOutReference(cons);
|
||||
hasConstructorsMarked = true;
|
||||
}
|
||||
|
||||
+4
-4
@@ -48,7 +48,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
RefMethodImpl(@NotNull RefElement ownerClass, UMethod method, PsiElement psi, RefManager manager) {
|
||||
super(method, psi, manager);
|
||||
|
||||
((RefEntityImpl)ownerClass).add(this);
|
||||
((WritableRefEntity)ownerClass).add(this);
|
||||
}
|
||||
|
||||
// To be used only from RefImplicitConstructor.
|
||||
@@ -57,7 +57,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
((RefClassImpl)ownerClass).add(this);
|
||||
|
||||
addOutReference(ownerClass);
|
||||
((RefClassImpl)ownerClass).addInReference(this);
|
||||
((WritableRefElement)ownerClass).addInReference(this);
|
||||
|
||||
setConstructor(true);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
@Override
|
||||
public synchronized void add(@NotNull RefEntity child) {
|
||||
if (child instanceof RefParameter) {
|
||||
((RefEntityImpl)child).setOwner(this);
|
||||
((WritableRefEntity)child).setOwner(this);
|
||||
return;
|
||||
}
|
||||
super.add(child);
|
||||
@@ -183,7 +183,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
RefClass ownerClass = getOwnerClass();
|
||||
if (ownerClass != null) {
|
||||
for (RefClass superClass : ownerClass.getBaseClasses()) {
|
||||
RefMethodImpl superDefaultConstructor = (RefMethodImpl)superClass.getDefaultConstructor();
|
||||
WritableRefElement superDefaultConstructor = (WritableRefElement)superClass.getDefaultConstructor();
|
||||
if (superDefaultConstructor != null) {
|
||||
superDefaultConstructor.addInReference(this);
|
||||
addOutReference(superDefaultConstructor);
|
||||
|
||||
+8
-5
@@ -37,7 +37,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RefElementImpl extends RefEntityImpl implements RefElement {
|
||||
public abstract class RefElementImpl extends RefEntityImpl implements RefElement, WritableRefElement {
|
||||
protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.reference.RefElement");
|
||||
|
||||
private static final int IS_ENTRY_MASK = 0x80;
|
||||
@@ -169,7 +169,8 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
|
||||
return ObjectUtils.notNull(myInReferences, ContainerUtil.emptyList());
|
||||
}
|
||||
|
||||
synchronized void addInReference(RefElement refElement) {
|
||||
@Override
|
||||
public synchronized void addInReference(RefElement refElement) {
|
||||
List<RefElement> inReferences = myInReferences;
|
||||
if (inReferences == null){
|
||||
myInReferences = inReferences = new ArrayList<>(1);
|
||||
@@ -179,7 +180,8 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void addOutReference(RefElement refElement) {
|
||||
@Override
|
||||
public synchronized void addOutReference(RefElement refElement) {
|
||||
List<RefElement> outReferences = myOutReferences;
|
||||
if (outReferences == null){
|
||||
myOutReferences = outReferences = new ArrayList<>(1);
|
||||
@@ -221,7 +223,7 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
|
||||
public void referenceRemoved() {
|
||||
myIsDeleted = true;
|
||||
if (getOwner() != null) {
|
||||
((RefEntityImpl)getOwner()).removeChild(this);
|
||||
getOwner().removeChild(this);
|
||||
}
|
||||
|
||||
for (RefElement refCallee : getOutReferences()) {
|
||||
@@ -246,7 +248,8 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
|
||||
|
||||
protected abstract void initialize();
|
||||
|
||||
void addSuppression(final String text) {
|
||||
@Override
|
||||
public void addSuppression(final String text) {
|
||||
mySuppressions = text.split("[, ]");
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -29,15 +29,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
abstract class RefEntityImpl implements RefEntity {
|
||||
private volatile RefEntityImpl myOwner;
|
||||
public abstract class RefEntityImpl implements RefEntity, WritableRefEntity {
|
||||
private volatile WritableRefEntity myOwner;
|
||||
protected List<RefEntity> myChildren; // guarded by this
|
||||
private final String myName;
|
||||
private Map<Key, Object> myUserMap; // guarded by this
|
||||
protected long myFlags; // guarded by this
|
||||
protected final RefManagerImpl myManager;
|
||||
|
||||
RefEntityImpl(@NotNull String name, @NotNull RefManager manager) {
|
||||
protected RefEntityImpl(@NotNull String name, @NotNull RefManager manager) {
|
||||
myManager = (RefManagerImpl)manager;
|
||||
myName = myManager.internName(name);
|
||||
}
|
||||
@@ -61,14 +61,16 @@ abstract class RefEntityImpl implements RefEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefEntity getOwner() {
|
||||
public WritableRefEntity getOwner() {
|
||||
return myOwner;
|
||||
}
|
||||
|
||||
protected void setOwner(@Nullable final RefEntityImpl owner) {
|
||||
@Override
|
||||
public void setOwner(@Nullable final WritableRefEntity owner) {
|
||||
myOwner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(@NotNull final RefEntity child) {
|
||||
List<RefEntity> children = myChildren;
|
||||
if (children == null) {
|
||||
@@ -78,10 +80,11 @@ abstract class RefEntityImpl implements RefEntity {
|
||||
((RefEntityImpl)child).setOwner(this);
|
||||
}
|
||||
|
||||
protected synchronized void removeChild(@NotNull final RefEntity child) {
|
||||
@Override
|
||||
public synchronized void removeChild(@NotNull final RefEntity child) {
|
||||
if (myChildren != null) {
|
||||
myChildren.remove(child);
|
||||
((RefEntityImpl)child).setOwner(null);
|
||||
((WritableRefEntity)child).setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -160,22 +160,22 @@ public class RefManagerImpl extends RefManager {
|
||||
}
|
||||
}
|
||||
|
||||
void fireNodeMarkedReferenced(RefElement refWhat,
|
||||
RefElement refFrom,
|
||||
boolean referencedFromClassInitializer,
|
||||
final boolean forReading,
|
||||
final boolean forWriting) {
|
||||
public void fireNodeMarkedReferenced(RefElement refWhat,
|
||||
RefElement refFrom,
|
||||
boolean referencedFromClassInitializer,
|
||||
final boolean forReading,
|
||||
final boolean forWriting) {
|
||||
for (RefGraphAnnotator annotator : myGraphAnnotators) {
|
||||
annotator.onMarkReferenced(refWhat, refFrom, referencedFromClassInitializer, forReading, forWriting);
|
||||
}
|
||||
}
|
||||
|
||||
void fireNodeMarkedReferenced(RefElement refWhat,
|
||||
RefElement refFrom,
|
||||
boolean referencedFromClassInitializer,
|
||||
final boolean forReading,
|
||||
final boolean forWriting,
|
||||
PsiElement element) {
|
||||
public void fireNodeMarkedReferenced(RefElement refWhat,
|
||||
RefElement refFrom,
|
||||
boolean referencedFromClassInitializer,
|
||||
final boolean forReading,
|
||||
final boolean forWriting,
|
||||
PsiElement element) {
|
||||
for (RefGraphAnnotator annotator : myGraphAnnotators) {
|
||||
annotator.onMarkReferenced(refWhat, refFrom, referencedFromClassInitializer, forReading, forWriting, element);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class RefManagerImpl extends RefManager {
|
||||
}
|
||||
}
|
||||
|
||||
void fireBuildReferences(RefElement refElement) {
|
||||
public void fireBuildReferences(RefElement refElement) {
|
||||
for (RefGraphAnnotator annotator : myGraphAnnotators) {
|
||||
annotator.onReferencesBuild(refElement);
|
||||
}
|
||||
@@ -618,7 +618,7 @@ public class RefManagerImpl extends RefManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
<T extends RefElement> T getFromRefTableOrCache(final PsiElement element, @NotNull NullableFactory<? extends T> factory) {
|
||||
public <T extends RefElement> T getFromRefTableOrCache(final PsiElement element, @NotNull NullableFactory<? extends T> factory) {
|
||||
return getFromRefTableOrCache(element, factory, null);
|
||||
}
|
||||
|
||||
@@ -712,7 +712,7 @@ public class RefManagerImpl extends RefManager {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isValidPointForReference() {
|
||||
public boolean isValidPointForReference() {
|
||||
return myIsInProcess || myOfflineView || ApplicationManager.getApplication().isUnitTestMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class RefModuleImpl extends RefEntityImpl implements RefModule {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void removeChild(@NotNull final RefEntity child) {
|
||||
public synchronized void removeChild(@NotNull final RefEntity child) {
|
||||
if (myChildren != null) {
|
||||
myChildren.remove(child);
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.reference;
|
||||
|
||||
public interface WritableRefElement extends RefElement, WritableRefEntity {
|
||||
void addInReference(RefElement refElement);
|
||||
|
||||
void addOutReference(RefElement refElement);
|
||||
|
||||
void addSuppression(String text);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.reference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface WritableRefEntity extends RefEntity {
|
||||
void setOwner(@Nullable WritableRefEntity owner);
|
||||
|
||||
void add(@NotNull RefEntity child);
|
||||
|
||||
void removeChild(@NotNull RefEntity child);
|
||||
}
|
||||
Reference in New Issue
Block a user