use of org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext in project che by eclipse.
the class CallInliner method flowAnalysis.
private void flowAnalysis() {
fInvocationScope = fRootScope.findScope(fTargetNode.getStartPosition(), fTargetNode.getLength());
fInvocationScope.setCursor(fTargetNode.getStartPosition());
fFlowContext = new FlowContext(0, fNumberOfLocals + 1);
fFlowContext.setConsiderAccessMode(true);
fFlowContext.setComputeMode(FlowContext.ARGUMENTS);
Selection selection = Selection.createFromStartLength(fInvocation.getStartPosition(), fInvocation.getLength());
switch(fBodyDeclaration.getNodeType()) {
case ASTNode.INITIALIZER:
case ASTNode.FIELD_DECLARATION:
case ASTNode.METHOD_DECLARATION:
case ASTNode.ENUM_CONSTANT_DECLARATION:
fFlowInfo = new InputFlowAnalyzer(fFlowContext, selection, true).perform(fBodyDeclaration);
break;
default:
//$NON-NLS-1$
Assert.isTrue(false, "Should not happen");
}
}
use of org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext in project che by eclipse.
the class ExtractMethodAnalyzer method analyzeSelection.
private RefactoringStatus analyzeSelection(RefactoringStatus status) {
fInputFlowContext = new FlowContext(0, fMaxVariableId + 1);
fInputFlowContext.setConsiderAccessMode(true);
fInputFlowContext.setComputeMode(FlowContext.ARGUMENTS);
InOutFlowAnalyzer flowAnalyzer = new InOutFlowAnalyzer(fInputFlowContext);
fInputFlowInfo = flowAnalyzer.perform(getSelectedNodes());
if (fInputFlowInfo.branches()) {
String canHandleBranchesProblem = canHandleBranches();
if (canHandleBranchesProblem != null) {
status.addFatalError(canHandleBranchesProblem, JavaStatusContext.create(fCUnit, getSelection()));
fReturnKind = ERROR;
return status;
}
}
if (fInputFlowInfo.isValueReturn()) {
fReturnKind = RETURN_STATEMENT_VALUE;
} else if (fInputFlowInfo.isVoidReturn() || (fInputFlowInfo.isPartialReturn() && isVoidMethod() && isLastStatementSelected())) {
fReturnKind = RETURN_STATEMENT_VOID;
} else if (fInputFlowInfo.isNoReturn() || fInputFlowInfo.isThrow() || fInputFlowInfo.isUndefined()) {
fReturnKind = NO;
}
if (fReturnKind == UNDEFINED) {
status.addError(RefactoringCoreMessages.FlowAnalyzer_execution_flow, JavaStatusContext.create(fCUnit, getSelection()));
fReturnKind = NO;
}
computeInput();
computeExceptions();
computeOutput(status);
if (status.hasFatalError())
return status;
adjustArgumentsAndMethodLocals();
compressArrays();
return status;
}
use of org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext in project che by eclipse.
the class ExtractMethodAnalyzer method computeOutput.
private void computeOutput(RefactoringStatus status) {
// First find all writes inside the selection.
FlowContext flowContext = new FlowContext(0, fMaxVariableId + 1);
flowContext.setConsiderAccessMode(true);
flowContext.setComputeMode(FlowContext.RETURN_VALUES);
FlowInfo returnInfo = new InOutFlowAnalyzer(flowContext).perform(getSelectedNodes());
IVariableBinding[] returnValues = returnInfo.get(flowContext, FlowInfo.WRITE | FlowInfo.WRITE_POTENTIAL | FlowInfo.UNKNOWN);
// Compute a selection that exactly covers the selected nodes
IRegion region = getSelectedNodeRange();
Selection selection = Selection.createFromStartLength(region.getOffset(), region.getLength());
List<IVariableBinding> localReads = new ArrayList<IVariableBinding>();
flowContext.setComputeMode(FlowContext.ARGUMENTS);
FlowInfo argInfo = new InputFlowAnalyzer(flowContext, selection, true).perform(fEnclosingBodyDeclaration);
IVariableBinding[] reads = argInfo.get(flowContext, FlowInfo.READ | FlowInfo.READ_POTENTIAL | FlowInfo.UNKNOWN);
outer: for (int i = 0; i < returnValues.length && localReads.size() < returnValues.length; i++) {
IVariableBinding binding = returnValues[i];
for (int x = 0; x < reads.length; x++) {
if (reads[x] == binding) {
localReads.add(binding);
fReturnValue = binding;
continue outer;
}
}
}
switch(localReads.size()) {
case 0:
fReturnValue = null;
break;
case 1:
break;
default:
fReturnValue = null;
StringBuffer affectedLocals = new StringBuffer();
for (int i = 0; i < localReads.size(); i++) {
IVariableBinding binding = localReads.get(i);
String bindingName = BindingLabelProvider.getBindingLabel(binding, BindingLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.F_PRE_TYPE_SIGNATURE);
affectedLocals.append(bindingName);
if (i != localReads.size() - 1) {
affectedLocals.append('\n');
}
}
String message = MessageFormat.format(RefactoringCoreMessages.ExtractMethodAnalyzer_assignments_to_local, new Object[] { affectedLocals.toString() });
status.addFatalError(message, JavaStatusContext.create(fCUnit, getSelection()));
return;
}
List<IVariableBinding> callerLocals = new ArrayList<IVariableBinding>(5);
FlowInfo localInfo = new InputFlowAnalyzer(flowContext, selection, false).perform(fEnclosingBodyDeclaration);
IVariableBinding[] writes = localInfo.get(flowContext, FlowInfo.WRITE | FlowInfo.WRITE_POTENTIAL | FlowInfo.UNKNOWN);
for (int i = 0; i < writes.length; i++) {
IVariableBinding write = writes[i];
if (getSelection().covers(ASTNodes.findDeclaration(write, fEnclosingBodyDeclaration)))
callerLocals.add(write);
}
fCallerLocals = callerLocals.toArray(new IVariableBinding[callerLocals.size()]);
if (fReturnValue != null && getSelection().covers(ASTNodes.findDeclaration(fReturnValue, fEnclosingBodyDeclaration)))
fReturnLocal = fReturnValue;
}
use of org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext in project che by eclipse.
the class SourceAnalyzer method initialize.
public void initialize() {
Block body = fDeclaration.getBody();
// first collect the static imports. This is necessary to not mark
// static imported fields and methods as implicit visible.
fTypesToImport = new ArrayList<SimpleName>();
fStaticsToImport = new ArrayList<SimpleName>();
ImportReferencesCollector.collect(body, fTypeRoot.getJavaProject(), null, fTypesToImport, fStaticsToImport);
// Now collect implicit references and name references
body.accept(new UpdateCollector());
int numberOfLocals = LocalVariableIndex.perform(fDeclaration);
FlowContext context = new FlowContext(0, numberOfLocals + 1);
context.setConsiderAccessMode(true);
context.setComputeMode(FlowContext.MERGE);
InOutFlowAnalyzer flowAnalyzer = new InOutFlowAnalyzer(context);
FlowInfo info = flowAnalyzer.perform(getStatements());
for (Iterator<SingleVariableDeclaration> iter = fDeclaration.parameters().iterator(); iter.hasNext(); ) {
SingleVariableDeclaration element = iter.next();
IVariableBinding binding = element.resolveBinding();
ParameterData data = (ParameterData) element.getProperty(ParameterData.PROPERTY);
data.setAccessMode(info.getAccessMode(context, binding));
}
}
Aggregations