本文整理汇总了Java中com.intellij.refactoring.util.VariableData类的典型用法代码示例。如果您正苦于以下问题:Java VariableData类的具体用法?Java VariableData怎么用?Java VariableData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariableData类属于com.intellij.refactoring.util包,在下文中一共展示了VariableData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findUsedVariables
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
private static Set<PsiVariable> findUsedVariables(VariableData data, final List<? extends PsiVariable> inputVariables,
PsiExpression expression) {
final Set<PsiVariable> found = new HashSet<PsiVariable>();
expression.accept(new JavaRecursiveElementVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression referenceExpression) {
super.visitReferenceExpression(referenceExpression);
PsiElement resolved = referenceExpression.resolve();
if (resolved instanceof PsiVariable && inputVariables.contains(resolved)) {
found.add((PsiVariable)resolved);
}
}
});
found.remove(data.variable);
return found;
}
示例2: removeParametersUsedInExitsOnly
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
public void removeParametersUsedInExitsOnly(PsiElement codeFragment,
Collection<PsiStatement> exitStatements,
ControlFlow controlFlow,
int startOffset,
int endOffset) {
final LocalSearchScope scope = new LocalSearchScope(codeFragment);
Variables:
for (Iterator<VariableData> iterator = myInputVariables.iterator(); iterator.hasNext();) {
final VariableData data = iterator.next();
for (PsiReference ref : ReferencesSearch.search(data.variable, scope)) {
PsiElement element = ref.getElement();
int elementOffset = controlFlow.getStartOffset(element);
if (elementOffset >= startOffset && elementOffset <= endOffset) {
if (!isInExitStatements(element, exitStatements)) continue Variables;
}
}
iterator.remove();
}
}
示例3: getVariableInfos
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
public VariableInfo[] getVariableInfos() {
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
VariableInfo[] infos = new VariableInfo[myVariableData.length];
for (int idx = 0; idx < myVariableData.length; idx++) {
VariableData data = myVariableData[idx];
VariableInfo info = myVariableToInfoMap.get(data.variable);
info.passAsParameter = data.passAsParameter;
info.parameterName = data.name;
info.parameterName = data.name;
String propertyName = codeStyleManager.variableNameToPropertyName(data.name, VariableKind.PARAMETER);
info.fieldName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.FIELD);
infos[idx] = info;
}
return infos;
}
示例4: doOKAction
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
protected void doOKAction() {
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
if (myCreateInnerClassRb.isSelected()) {
final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
if (innerClass != null) {
conflicts.putValue(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
}
}
if (conflicts.size() > 0) {
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
return;
}
}
final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
if (makeVarargsCb != null && makeVarargsCb.isSelected()) {
final VariableData data = myInputVariables[myInputVariables.length - 1];
if (data.type instanceof PsiArrayType) {
data.type = new PsiEllipsisType(((PsiArrayType)data.type).getComponentType());
}
}
super.doOKAction();
}
示例5: getDuplicates
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
public List<Match> getDuplicates(final PsiMethod method, final PsiMethodCallExpression methodCall, ParametersFolder folder) {
final List<Match> duplicates = findDuplicatesSignature(method, folder);
if (duplicates != null && !duplicates.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode() ||
new PreviewDialog(method, myExtractedMethod, methodCall, myMethodCall, duplicates.size()).showAndGet()) {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
@Override
public void run() {
myMethodCall = (PsiMethodCallExpression)methodCall.replace(myMethodCall);
myExtractedMethod = (PsiMethod)method.replace(myExtractedMethod);
}
});
final DuplicatesFinder finder = MethodDuplicatesHandler.createDuplicatesFinder(myExtractedMethod);
if (finder != null) {
final List<VariableData> datas = finder.getParameters().getInputVariables();
myVariableData = datas.toArray(new VariableData[datas.size()]);
return finder.findDuplicates(myExtractedMethod.getContainingClass());
}
}
}
return null;
}
示例6: collectParamValues
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
private static boolean collectParamValues(List<Match> duplicates, VariableData variableData, THashSet<PsiExpression> map) {
for (Match duplicate : duplicates) {
final List<PsiElement> values = duplicate.getParameterValues(variableData.variable);
if (values == null || values.isEmpty()) {
return false;
}
boolean found = false;
for (PsiElement value : values) {
if (value instanceof PsiExpression) {
map.add((PsiExpression)value);
found = true;
break;
}
}
if (!found) return false;
}
return true;
}
示例7: checkMethodConflicts
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
protected void checkMethodConflicts(MultiMap<PsiElement, String> conflicts) {
PsiMethod prototype;
try {
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
prototype = factory.createMethod(myNameField.getEnteredName().trim(), myReturnType);
if (myTypeParameterList != null) prototype.getTypeParameterList().replace(myTypeParameterList);
for (VariableData data : myInputVariables) {
if (data.passAsParameter) {
prototype.getParameterList().add(factory.createParameter(data.name, data.type));
}
}
// set the modifiers with which the method is supposed to be created
PsiUtil.setModifierProperty(prototype, PsiModifier.PRIVATE, true);
} catch (IncorrectOperationException e) {
return;
}
ConflictsUtil.checkMethodConflicts(myTargetClass, null, prototype, conflicts);
}
示例8: Settings
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
public Settings(boolean replaceUsages,
@Nullable String classParameterName,
@Nullable VariableData[] variableDatum,
boolean delegate) {
myReplaceUsages = replaceUsages;
myDelegate = delegate;
myMakeClassParameter = classParameterName != null;
myClassParameterName = classParameterName;
myMakeFieldParameters = variableDatum != null;
myFieldToNameList = new ArrayList<FieldParameter>();
if(myMakeFieldParameters) {
myFieldToNameMapping = new HashMap<PsiField, String>();
for (VariableData data : variableDatum) {
if (data.passAsParameter) {
myFieldToNameMapping.put((PsiField)data.variable, data.name);
myFieldToNameList.add(new FieldParameter((PsiField)data.variable, data.name, data.type));
}
}
}
else {
myFieldToNameMapping = null;
}
}
示例9: performWithFields
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
private void performWithFields() throws Exception {
configureByFile(TEST_ROOT + getTestName(false) + ".java");
PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue(element instanceof PsiClass);
PsiClass aClass = (PsiClass)element;
final ArrayList<VariableData> parametersForFields = new ArrayList<>();
final boolean addClassParameter = MakeStaticUtil.buildVariableData(aClass, parametersForFields);
new MakeClassStaticProcessor(
getProject(),
aClass,
new Settings(true, addClassParameter ? "anObject" : null,
parametersForFields.toArray(
new VariableData[parametersForFields.size()]))).run();
checkResultByFile(TEST_ROOT + getTestName(false) + "_after.java");
}
示例10: doTest
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
private void doTest(final boolean delegate,
final boolean createInner,
final Function<PsiMethod, VariableData[]> function) throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(getProject()));
assertNotNull("Class Test not found", aClass);
final PsiMethod method = aClass.findMethodsByName("foo", false)[0];
final VariableData[] datas = function.fun(method);
IntroduceParameterObjectProcessor processor = new IntroduceParameterObjectProcessor("Param", "", null, method, datas, delegate, false,
createInner, null, false);
processor.run();
});
}
示例11: doOKAction
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
protected void doOKAction() {
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
if (myCreateInnerClassRb.isSelected()) {
final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
if (innerClass != null) {
conflicts.putValue(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
}
}
if (conflicts.size() > 0) {
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
conflictsDialog.show();
if (!conflictsDialog.isOK()){
if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
return;
}
}
final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
if (makeVarargsCb != null && makeVarargsCb.isSelected()) {
final VariableData data = myInputVariables[myInputVariables.length - 1];
if (data.type instanceof PsiArrayType) {
data.type = new PsiEllipsisType(((PsiArrayType)data.type).getComponentType());
}
}
super.doOKAction();
}
示例12: doOKAction
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
protected void doOKAction() {
MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
checkMethodConflicts(conflicts);
if (!conflicts.isEmpty()) {
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
conflictsDialog.show();
if (!conflictsDialog.isOK()){
if (conflictsDialog.isShowConflicts()) close(CANCEL_EXIT_CODE);
return;
}
}
if (myMakeVarargs != null && myMakeVarargs.isSelected()) {
final VariableData data = myInputVariables[myInputVariables.length - 1];
if (data.type instanceof PsiArrayType) {
data.type = new PsiEllipsisType(((PsiArrayType)data.type).getComponentType());
}
}
super.doOKAction();
}
示例13: checkMethodConflicts
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
protected void checkMethodConflicts(MultiMap<PsiElement, String> conflicts) {
PsiMethod prototype;
try {
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
prototype = factory.createMethod(myNameField.getText().trim(), myReturnType);
if (myTypeParameterList != null) prototype.getTypeParameterList().replace(myTypeParameterList);
for (VariableData data : myInputVariables) {
if (data.passAsParameter) {
prototype.getParameterList().add(factory.createParameter(data.name, data.type));
}
}
// set the modifiers with which the method is supposed to be created
PsiUtil.setModifierProperty(prototype, PsiModifier.PRIVATE, true);
} catch (IncorrectOperationException e) {
return;
}
ConflictsUtil.checkMethodConflicts(myTargetClass, null, prototype, conflicts);
}
示例14: Settings
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
public Settings(boolean replaceUsages, String classParameterName,
VariableData[] variableDatum) {
myReplaceUsages = replaceUsages;
myMakeClassParameter = classParameterName != null;
myClassParameterName = classParameterName;
myMakeFieldParameters = variableDatum != null;
myFieldToNameList = new ArrayList<FieldParameter>();
if(myMakeFieldParameters) {
myFieldToNameMapping = new com.intellij.util.containers.HashMap<PsiField, String>();
for (VariableData data : variableDatum) {
if (data.passAsParameter) {
myFieldToNameMapping.put((PsiField)data.variable, data.name);
myFieldToNameList.add(new FieldParameter((PsiField)data.variable, data.name, data.type));
}
}
}
else {
myFieldToNameMapping = null;
}
}
示例15: performWithFields
import com.intellij.refactoring.util.VariableData; //导入依赖的package包/类
private void performWithFields() throws Exception {
configureByFile(TEST_ROOT + getTestName(false) + ".java");
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
assertTrue(element instanceof PsiClass);
PsiClass aClass = (PsiClass)element;
final ArrayList<VariableData> parametersForFields = new ArrayList<VariableData>();
final boolean addClassParameter = MakeStaticUtil.buildVariableData(aClass, parametersForFields);
new MakeClassStaticProcessor(
getProject(),
aClass,
new Settings(true, addClassParameter ? "anObject" : null,
parametersForFields.toArray(
new VariableData[parametersForFields.size()]))).run();
checkResultByFile(TEST_ROOT + getTestName(false) + "_after.java");
}