From 5d2e1af380e48002d8e15729e29380164a7d2d42 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 2 Jul 2010 14:08:53 +0400 Subject: [PATCH] cleanup --- .../reference/RefJavaManagerImpl.java | 22 ++++---- .../reference/RefMethodImpl.java | 55 +++++++++---------- .../reference/RefElementImpl.java | 4 +- .../impl/CompositeProjectRoot.java | 3 + .../projectRoots/impl/ProjectJdkImpl.java | 2 +- .../impl/CodeInsightTestFixtureImpl.java | 3 +- .../impl/ModuleFixtureBuilderImpl.java | 4 +- .../openapi/util/text/StringUtil.java | 2 +- 8 files changed, 48 insertions(+), 47 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index a87eda3415e0..e043ac150d5f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -209,19 +209,19 @@ public class RefJavaManagerImpl extends RefJavaManager { @Nullable public String getType(final RefEntity ref) { if (ref instanceof RefMethod) { - return RefJavaManager.METHOD; + return METHOD; } else if (ref instanceof RefClass) { - return RefJavaManager.CLASS; + return CLASS; } else if (ref instanceof RefField) { - return RefJavaManager.FIELD; + return FIELD; } else if (ref instanceof RefParameter) { - return RefJavaManager.PARAMETER; + return PARAMETER; } else if (ref instanceof RefPackage) { - return RefJavaManager.PACKAGE; + return PACKAGE; } return null; } @@ -247,8 +247,7 @@ public class RefJavaManagerImpl extends RefJavaManager { } public boolean belongsToScope(final PsiElement psiElement) { - if (psiElement instanceof PsiTypeParameter) return false; - return true; + return !(psiElement instanceof PsiTypeParameter); } public void export(final RefEntity refEntity, final Element element) { @@ -265,8 +264,7 @@ public class RefJavaManagerImpl extends RefJavaManager { private static void appendPackageElement(final Element element, final String packageName) { final Element packageElement = new Element("package"); - packageElement - .addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default")); + packageElement.addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default")); element.addContent(packageElement); } @@ -320,7 +318,7 @@ public class RefJavaManagerImpl extends RefJavaManager { public void visitMethod(final PsiMethod method) { super.visitMethod(method); final RefElement refElement = myRefManager.getReference(method); - if (refElement instanceof RefMethod) { + if (refElement instanceof RefMethodImpl) { ((RefMethodImpl)refElement).buildReferences(); } } @@ -328,7 +326,7 @@ public class RefJavaManagerImpl extends RefJavaManager { public void visitField(final PsiField field) { super.visitField(field); final RefElement refElement = myRefManager.getReference(field); - if (refElement instanceof RefField) { + if (refElement instanceof RefFieldImpl) { ((RefFieldImpl)refElement).buildReferences(); } } @@ -409,4 +407,4 @@ public class RefJavaManagerImpl extends RefJavaManager { } } } -} \ No newline at end of file +} diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java index d50ad25c5690..188c0ef7e06a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java @@ -250,43 +250,42 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { public void buildReferences() { // Work on code block to find what we're referencing... PsiMethod method = (PsiMethod) getElement(); - if (method != null) { - PsiCodeBlock body = method.getBody(); - final RefJavaUtil refUtil = RefJavaUtil.getInstance(); - refUtil.addReferences(method, this, body); - refUtil.addReferences(method, this, method.getModifierList()); - checkForSuperCall(method); - setOnlyCallsSuper(refUtil.isMethodOnlyCallsSuper(method)); + if (method == null) return; + PsiCodeBlock body = method.getBody(); + final RefJavaUtil refUtil = RefJavaUtil.getInstance(); + refUtil.addReferences(method, this, body); + refUtil.addReferences(method, this, method.getModifierList()); + checkForSuperCall(method); + setOnlyCallsSuper(refUtil.isMethodOnlyCallsSuper(method)); - setBodyEmpty(isOnlyCallsSuper() || !isExternalOverride() && (body == null || body.getStatements().length == 0)); + setBodyEmpty(isOnlyCallsSuper() || !isExternalOverride() && (body == null || body.getStatements().length == 0)); - PsiType retType = method.getReturnType(); - if (retType != null) { - PsiType psiType = retType; - RefClass ownerClass = refUtil.getOwnerClass(getRefManager(), method); + PsiType retType = method.getReturnType(); + if (retType != null) { + PsiType psiType = retType; + RefClass ownerClass = refUtil.getOwnerClass(getRefManager(), method); - if (ownerClass != null) { - psiType = psiType.getDeepComponentType(); + if (ownerClass != null) { + psiType = psiType.getDeepComponentType(); - if (psiType instanceof PsiClassType) { - PsiClass psiClass = PsiUtil.resolveClassInType(psiType); - if (psiClass != null && getRefManager().belongsToScope(psiClass)) { - RefClassImpl refClass = (RefClassImpl) getRefManager().getReference(psiClass); - if (refClass != null) { - refClass.addTypeReference(ownerClass); - refClass.addClassExporter(this); - } + if (psiType instanceof PsiClassType) { + PsiClass psiClass = PsiUtil.resolveClassInType(psiType); + if (psiClass != null && getRefManager().belongsToScope(psiClass)) { + RefClassImpl refClass = (RefClassImpl) getRefManager().getReference(psiClass); + if (refClass != null) { + refClass.addTypeReference(ownerClass); + refClass.addClassExporter(this); } } } } - - for (RefParameter parameter : getParameters()) { - refUtil.setIsFinal(parameter, parameter.getElement().hasModifierProperty(PsiModifier.FINAL)); - } - - getRefManager().fireBuildReferences(this); } + + for (RefParameter parameter : getParameters()) { + refUtil.setIsFinal(parameter, parameter.getElement().hasModifierProperty(PsiModifier.FINAL)); + } + + getRefManager().fireBuildReferences(this); } private void collectUncaughtExceptions(PsiMethod method) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java index 343ea8fe2736..c90fdfcf13a6 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefElementImpl.java @@ -139,7 +139,7 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement } public boolean isReferenced() { - return getInReferences().size() > 0; + return !getInReferences().isEmpty(); } public boolean hasSuspiciousCallers() { @@ -257,6 +257,6 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement } } final RefEntity entity = getOwner(); - return entity instanceof RefElement && ((RefElementImpl)entity).isSuppressed(toolId); + return entity instanceof RefElementImpl && ((RefElementImpl)entity).isSuppressed(toolId); } } diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java index 0d08f0701195..65ebc7db7e56 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/CompositeProjectRoot.java @@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -35,6 +36,7 @@ import java.util.List; class CompositeProjectRoot implements ProjectRoot { private final List myRoots = new ArrayList(); + @NotNull ProjectRoot[] getProjectRoots() { return myRoots.toArray(new ProjectRoot[myRoots.size()]); } @@ -68,6 +70,7 @@ class CompositeProjectRoot implements ProjectRoot { myRoots.remove(root); } + @NotNull ProjectRoot add(VirtualFile virtualFile) { final SimpleProjectRoot root = new SimpleProjectRoot(virtualFile); myRoots.add(root); diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java index 93bb832970ba..b58d7672ca56 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/ProjectJdkImpl.java @@ -83,7 +83,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements JDOMExternaliz } public final void setVersionString(String versionString) { - myVersionString = (versionString == null || "".equals(versionString)) ? null : versionString; + myVersionString = versionString == null || "".equals(versionString) ? null : versionString; myVersionDefined = true; } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index f017ac8a85a3..6bf2e3d1052f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -838,6 +838,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig configureInspections(myInspections == null ? new LocalInspectionTool[0] : myInspections); DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); DaemonCodeAnalyzer.getInstance(getProject()).setUpdateByTimerEnabled(false); + ensureIndexesUpToDate(getProject()); } private void enableInspectionTool(InspectionProfileEntry tool){ @@ -1188,7 +1189,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } } - private static void ensureIndexesUpToDate(Project project) { + public static void ensureIndexesUpToDate(Project project) { FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); assertTrue(!DumbServiceImpl.getInstance(project).isDumb()); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java index 9bcc3827b482..b9822cc970e4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java @@ -62,7 +62,7 @@ public abstract class ModuleFixtureBuilderImpl implemen } public ModuleFixtureBuilder addSourceRoot(final String sourceRootPath) { - assert myContentRoots.size() > 0 : "content root should be added first"; + assert !myContentRoots.isEmpty() : "content root should be added first"; mySourceRoots.add(sourceRootPath); return this; } @@ -101,7 +101,7 @@ public abstract class ModuleFixtureBuilderImpl implemen protected abstract T instantiateFixture(); Module buildModule() { - final Module[] module = new Module[]{null}; + final Module[] module = {null}; ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 68c6ff4e95f9..538ec7bc0d67 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -890,7 +890,7 @@ public class StringUtil { if (separator.length() == 0) { return Collections.singletonList(s); } - ArrayList result = new ArrayList(); + List result = new ArrayList(); int pos = 0; while (true) { int index = s.indexOf(separator, pos);