mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] clean up ControlFlowBuilder
GitOrigin-RevId: 4f9375e75d77a11144c7575e6d2863cd191a6909
This commit is contained in:
committed by
intellij-monorepo-bot
parent
62b5216e7a
commit
7de2f4a1ec
+2
-2
@@ -387,7 +387,7 @@ public class GrFinalVariableAccessInspection extends BaseInspection {
|
||||
|
||||
@NotNull
|
||||
private static Instruction[] buildFlowForField(@NotNull GrOpenBlock block) {
|
||||
return new ControlFlowBuilder(block.getProject(), GrFieldControlFlowPolicy.getInstance()).buildControlFlow(block);
|
||||
return new ControlFlowBuilder(GrFieldControlFlowPolicy.getInstance()).buildControlFlow(block);
|
||||
}
|
||||
|
||||
|
||||
@@ -416,7 +416,7 @@ public class GrFinalVariableAccessInspection extends BaseInspection {
|
||||
private static Instruction[] getFlow(@NotNull PsiElement element) {
|
||||
return element instanceof GrControlFlowOwner
|
||||
? ((GrControlFlowOwner)element).getControlFlow()
|
||||
: new ControlFlowBuilder(element.getProject()).buildControlFlow((GroovyPsiElement)element);
|
||||
: new ControlFlowBuilder().buildControlFlow((GroovyPsiElement)element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -435,7 +435,7 @@ public class ControlFlowUtils {
|
||||
flow = ((GrControlFlowOwner)element).getControlFlow();
|
||||
}
|
||||
else {
|
||||
flow = new ControlFlowBuilder(element.getProject()).buildControlFlow((GroovyPsiElement)element);
|
||||
flow = new ControlFlowBuilder().buildControlFlow((GroovyPsiElement)element);
|
||||
}
|
||||
return collectReturns(flow, allExitPoints);
|
||||
}
|
||||
|
||||
+7
-19
@@ -4,7 +4,6 @@ package org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl;
|
||||
import com.intellij.openapi.diagnostic.Attachment;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
@@ -84,11 +83,11 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
private int myInstructionNumber;
|
||||
private final GrControlFlowPolicy myPolicy;
|
||||
|
||||
public ControlFlowBuilder(Project project) {
|
||||
this(project, GrResolverPolicy.getInstance());
|
||||
public ControlFlowBuilder() {
|
||||
this(GrResolverPolicy.getInstance());
|
||||
}
|
||||
|
||||
public ControlFlowBuilder(Project project, GrControlFlowPolicy policy) {
|
||||
public ControlFlowBuilder(GrControlFlowPolicy policy) {
|
||||
myPolicy = policy;
|
||||
}
|
||||
|
||||
@@ -98,7 +97,6 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
final PsiElement lbrace = block.getLBrace();
|
||||
if (lbrace != null && parent instanceof GrMethod) {
|
||||
for (GrParameter parameter : ((GrMethod)parent).getParameters()) {
|
||||
String parameterName = parameter.getName();
|
||||
if (myPolicy.isVariableInitialized(parameter)) {
|
||||
addNode(new ReadWriteVariableInstruction(createDescriptor(parameter), parameter, ReadWriteVariableInstruction.WRITE));
|
||||
}
|
||||
@@ -167,17 +165,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
checkPending(end); //collect return edges
|
||||
|
||||
|
||||
return assertValidPsi(myInstructions.toArray(Instruction.EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
public static Instruction[] assertValidPsi(Instruction[] instructions) {
|
||||
/*for (Instruction instruction : instructions) {
|
||||
PsiElement element = instruction.getElement();
|
||||
if (element != null && !element.isValid()) {
|
||||
throw new AssertionError("invalid element in dfa: " + element);
|
||||
}
|
||||
}*/
|
||||
return instructions;
|
||||
return myInstructions.toArray(Instruction.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private void addControlFlowInstructions(final GrStatementOwner owner) {
|
||||
@@ -197,7 +185,6 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
|
||||
private void addFunctionalExpressionParameters(GrFunctionalExpression expression) {
|
||||
for (GrParameter parameter : expression.getAllParameters()) {
|
||||
String parameterName = parameter.getName();
|
||||
if (myPolicy.isVariableInitialized(parameter)) {
|
||||
addNode(new ReadWriteVariableInstruction(createDescriptor(parameter), parameter, ReadWriteVariableInstruction.WRITE));
|
||||
}
|
||||
@@ -1027,6 +1014,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
|
||||
//infer 'may be return' position
|
||||
int i;
|
||||
//noinspection StatementWithEmptyBody
|
||||
for (i = statements.length - 1; i >= 0 && statements[i] instanceof GrBreakStatement; i--) {
|
||||
}
|
||||
|
||||
@@ -1164,7 +1152,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
|
||||
String path = virtualFile == null ? null : virtualFile.getPresentableUrl();
|
||||
|
||||
LOG.error(descr+ myScope.getText(), new Attachment(path+"", fileText+""));
|
||||
LOG.error(descr + myScope.getText(), new Attachment(String.valueOf(path), String.valueOf(fileText)));
|
||||
}
|
||||
|
||||
private AfterCallInstruction addCallNode(InstructionImpl finallyInstruction, GroovyPsiElement scopeWhenAdded, InstructionImpl src) {
|
||||
@@ -1241,7 +1229,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
|
||||
public void visitField(@NotNull GrField field) {
|
||||
GrExpression initializer = field.getInitializerGroovy();
|
||||
if (initializer != null) {
|
||||
Instruction[] flow = new ControlFlowBuilder(field.getProject()).buildControlFlow(initializer);
|
||||
Instruction[] flow = new ControlFlowBuilder().buildControlFlow(initializer);
|
||||
collectVars(flow);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ class GrExpressionLambdaBodyImpl(node: ASTNode) : GroovyPsiElementImpl(node), Gr
|
||||
|
||||
override fun toString(): String = "Lambda body"
|
||||
|
||||
override fun getControlFlow(): Array<Instruction> = ControlFlowBuilder(project).buildControlFlow(this)
|
||||
override fun getControlFlow(): Array<Instruction> = ControlFlowBuilder().buildControlFlow(this)
|
||||
|
||||
override fun isTopControlFlowOwner(): Boolean = true
|
||||
}
|
||||
|
||||
+2
-2
@@ -200,10 +200,10 @@ public abstract class GroovyFileBaseImpl extends PsiFileBase implements GroovyFi
|
||||
assert isValid();
|
||||
Instruction[] result = SoftReference.dereference(myControlFlow);
|
||||
if (result == null) {
|
||||
result = new ControlFlowBuilder(getProject()).buildControlFlow(this);
|
||||
result = new ControlFlowBuilder().buildControlFlow(this);
|
||||
myControlFlow = new SoftReference<>(result);
|
||||
}
|
||||
return ControlFlowBuilder.assertValidPsi(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// 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.
|
||||
// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.lang.psi.impl.statements.blocks;
|
||||
|
||||
@@ -101,7 +101,7 @@ public abstract class GrBlockImpl extends LazyParseablePsiElement implements GrC
|
||||
controlFlow = CachedValuesManager.getManager(getProject()).createCachedValue(() -> {
|
||||
try {
|
||||
ResolveProfiler.start();
|
||||
final Instruction[] flow = new ControlFlowBuilder(getProject()).buildControlFlow(this);
|
||||
final Instruction[] flow = new ControlFlowBuilder().buildControlFlow(this);
|
||||
return CachedValueProvider.Result.create(flow, getContainingFile(), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
|
||||
}
|
||||
finally {
|
||||
@@ -111,7 +111,7 @@ public abstract class GrBlockImpl extends LazyParseablePsiElement implements GrC
|
||||
}, false);
|
||||
controlFlow = putUserDataIfAbsent(CONTROL_FLOW, controlFlow);
|
||||
}
|
||||
return ControlFlowBuilder.assertValidPsi(controlFlow.getValue());
|
||||
return controlFlow.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.
|
||||
*/
|
||||
// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.refactoring.extract;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -154,7 +140,7 @@ public class GroovyExtractChooser {
|
||||
Set<GrStatement> allReturnStatements = new HashSet<>();
|
||||
GrControlFlowOwner controlFlowOwner = ControlFlowUtils.findControlFlowOwner(statement0);
|
||||
LOG.assertTrue(controlFlowOwner != null);
|
||||
final Instruction[] flow = new ControlFlowBuilder(project, GrAllVarsInitializedPolicy.getInstance()).buildControlFlow(controlFlowOwner);
|
||||
final Instruction[] flow = new ControlFlowBuilder(GrAllVarsInitializedPolicy.getInstance()).buildControlFlow(controlFlowOwner);
|
||||
allReturnStatements.addAll(ControlFlowUtils.collectReturns(flow, true));
|
||||
|
||||
ArrayList<GrStatement> returnStatements = new ArrayList<>();
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.refactoring.inline;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -165,7 +151,7 @@ public class GroovyInlineLocalProcessor extends BaseRefactoringProcessor {
|
||||
public void visitField(@NotNull GrField field) {
|
||||
GrExpression initializer = field.getInitializerGroovy();
|
||||
if (initializer != null) {
|
||||
Instruction[] flow = new ControlFlowBuilder(field.getProject()).buildControlFlow(initializer);
|
||||
Instruction[] flow = new ControlFlowBuilder().buildControlFlow(initializer);
|
||||
collectRefs(variable, flow, ControlFlowUtils.inferWriteAccessMap(flow, variable), -1, toInline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2019 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 org.jetbrains.plugins.groovy
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -84,7 +70,7 @@ class ReachingDefsTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
GrStatement lastStatement = getStatement(end, owner)
|
||||
|
||||
final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(firstStatement)
|
||||
final ControlFlowBuilder flowBuilder = new ControlFlowBuilder(firstStatement.getProject(), GrAllVarsInitializedPolicy.getInstance())
|
||||
final ControlFlowBuilder flowBuilder = new ControlFlowBuilder(GrAllVarsInitializedPolicy.getInstance())
|
||||
final Instruction[] flow = flowBuilder.buildControlFlow(flowOwner)
|
||||
final FragmentVariableInfos fragmentVariableInfos = ReachingDefinitionsCollector.obtainVariableFlowInformation(firstStatement, lastStatement, flowOwner, flow)
|
||||
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ class ControlFlowTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
final PsiElement start = file.findElementAt(model.hasSelection() ? model.selectionStart : 0)
|
||||
final PsiElement end = file.findElementAt(model.hasSelection() ? model.selectionEnd - 1 : file.textLength - 1)
|
||||
final GrControlFlowOwner owner = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(start, end), GrControlFlowOwner, false)
|
||||
final Instruction[] instructions = new ControlFlowBuilder(project).buildControlFlow(owner)
|
||||
final Instruction[] instructions = new ControlFlowBuilder().buildControlFlow(owner)
|
||||
final String cf = ControlFlowUtils.dumpControlFlow(instructions)
|
||||
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, code + "\n-----\n" + cf.trim())
|
||||
myFixture.checkResultByFile(path)
|
||||
|
||||
Reference in New Issue
Block a user