use of org.autorefactor.refactoring.RefactoringRule in project AutoRefactor by JnRouvignac.
the class WorkspacePreferencePage method createControls.
private Group createControls(final Composite parent, final List<RefactoringRule> allRefactoringRules) {
fieldEditorParent = new Composite(parent, SWT.FILL);
fields = new ArrayList<FieldEditor>(1 + allRefactoringRules.size());
fields.add(new BooleanFieldEditor(DEBUG_MODE_ON.getName(), DEBUG_MODE_ON.getDescription(), fieldEditorParent));
final Group ruleGroup = new Group(fieldEditorParent, SWT.FILL);
ruleGroup.setText("Rules by default");
// All rule checkbox
toggleAllRules = new Button(ruleGroup, SWT.CHECK | SWT.LEFT);
toggleAllRules.setFont(ruleGroup.getFont());
toggleAllRules.setText("Toggle all the rules");
toggleAllRules.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean isSelected = WorkspacePreferencePage.this.toggleAllRules.getSelection();
for (BooleanFieldEditor rule : WorkspacePreferencePage.this.rules) {
((Button) rule.getDescriptionControl(ruleGroup)).setSelection(isSelected);
}
}
});
// Add a space
Composite spacer = new Composite(ruleGroup, SWT.NULL);
spacer.setLayoutData(new GridData(0, 5));
rules = new ArrayList<BooleanFieldEditor>(allRefactoringRules.size());
for (final RefactoringRule refactoringRule : allRefactoringRules) {
final BooleanFieldEditor booleanFieldEditor = new BooleanFieldEditor(refactoringRule.getClass().getCanonicalName(), refactoringRule.getName(), SWT.WRAP, ruleGroup);
booleanFieldEditor.getDescriptionControl(ruleGroup).setToolTipText(refactoringRule.getDescription());
((Button) booleanFieldEditor.getDescriptionControl(ruleGroup)).addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
invalidateToggleRules(ruleGroup);
}
});
rules.add(booleanFieldEditor);
}
fields.addAll(rules);
return ruleGroup;
}
use of org.autorefactor.refactoring.RefactoringRule in project AutoRefactor by JnRouvignac.
the class PreferenceInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
// TODO initialize preferences from the JDT preferences like:
// code style/cleanup/formatting
final IPreferenceStore store = AutoRefactorPlugin.getDefault().getPreferenceStore();
for (PreferenceConstants preference : PreferenceConstants.values()) {
final String name = preference.getName();
final Object defaultValue = preference.getDefaultValue();
if (defaultValue instanceof Boolean) {
store.setDefault(name, (Boolean) defaultValue);
} else if (defaultValue instanceof Integer) {
store.setDefault(name, (Integer) defaultValue);
} else if (defaultValue instanceof Long) {
store.setDefault(name, (Long) defaultValue);
} else if (defaultValue instanceof Double) {
store.setDefault(name, (Double) defaultValue);
} else if (defaultValue instanceof Float) {
store.setDefault(name, (Float) defaultValue);
} else if (defaultValue instanceof String) {
store.setDefault(name, (String) defaultValue);
} else {
throw new NotImplementedException(null, defaultValue);
}
}
for (RefactoringRule refactoringRule : AllRefactoringRules.getAllRefactoringRules()) {
store.setDefault(refactoringRule.getClass().getCanonicalName(), refactoringRule.isByDefault());
}
}
use of org.autorefactor.refactoring.RefactoringRule in project AutoRefactor by JnRouvignac.
the class ChooseRefactoringWizardPage method createRefactoringsTable.
private void createRefactoringsTable(Composite parent) {
tableViewer = newCheckList(parent, BORDER | H_SCROLL | CHECK | NO_FOCUS | HIDE_SELECTION);
createColumns(tableViewer);
tableViewer.setContentProvider(new ArrayContentProvider());
final List<RefactoringRule> refactorings = AllRefactoringRules.getAllRefactoringRules();
tableViewer.setInput(refactorings);
tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
}
});
tableViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
final String filter = filterText.getText().toLowerCase();
final RefactoringRule rule = (RefactoringRule) refactoring;
final String description = rule.getDescription().toLowerCase();
final String name = rule.getName().toLowerCase();
return description.contains(filter) || name.contains(filter);
}
});
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
tableViewer.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
final String filter = filterText.getText().toLowerCase();
final String name = ((RefactoringRule) cell.getElement()).getName();
cell.setText(name);
cell.setStyleRanges(getStyleRanges(name, filter));
}
private StyleRange[] getStyleRanges(String text, String filter) {
final int matchIndex = text.toLowerCase().indexOf(filter);
final int matchLength = filter.length();
if (matchIndex != -1 && matchLength != 0) {
final StyledString styledString = new StyledString(text, defaultStyler);
styledString.setStyle(matchIndex, matchLength, underlineStyler);
return styledString.getStyleRanges();
}
return null;
}
@Override
public String getToolTipText(Object refactoring) {
return ((RefactoringRule) refactoring).getDescription();
}
@Override
public Point getToolTipShift(Object object) {
return new Point(10, 20);
}
});
final Table table = tableViewer.getTable();
table.setLinesVisible(true);
tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
packColumns(table);
table.setFocus();
}
use of org.autorefactor.refactoring.RefactoringRule in project AutoRefactor by JnRouvignac.
the class WorkspacePreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
final List<RefactoringRule> allRefactoringRules = AllRefactoringRules.getAllRefactoringRules();
Collections.sort(allRefactoringRules, new Comparator<RefactoringRule>() {
@Override
public int compare(final RefactoringRule o1, final RefactoringRule o2) {
return o1.getName().compareTo(o2.getName());
}
});
final Group ruleGroup = createControls(parent, allRefactoringRules);
initialize();
invalidateToggleRules(ruleGroup);
checkState();
return fieldEditorParent;
}
use of org.autorefactor.refactoring.RefactoringRule in project AutoRefactor by JnRouvignac.
the class RefactoringRulesTest method testRefactoring0.
private void testRefactoring0() throws Exception {
final String sampleName = testName + "Sample.java";
final File sampleIn = new File(SAMPLES_BASE_DIR, "samples_in/" + sampleName);
assertTrue(testName + ": sample in file " + sampleIn + " should exist", sampleIn.exists());
final File sampleOut = new File(SAMPLES_BASE_DIR, "samples_out/" + sampleName);
assertTrue(testName + ": sample out file " + sampleOut + " should exist", sampleOut.exists());
final String refactoringClassname = testName + "Refactoring";
final RefactoringRule refactoring = getRefactoringClass(refactoringClassname);
assertNotNull(testName + ": refactoring class " + refactoringClassname + " should exist.\n" + "Make sure you added it to the method getAllRefactoringRules() " + "of the " + AllRefactoringRules.class + ".", refactoring);
final String sampleInSource = readAll(sampleIn);
final String sampleOutSource = readAll(sampleOut);
final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment(PACKAGE_NAME);
final ICompilationUnit cu = packageFragment.createCompilationUnit(sampleName, sampleInSource, true, null);
cu.getBuffer().setContents(sampleInSource);
cu.save(null, true);
final IDocument doc = new Document(sampleInSource);
new ApplyRefactoringsJob(null, null, TEST_ENVIRONMENT).applyRefactoring(doc, cu, new AggregateASTVisitor(Arrays.asList(refactoring)), newJavaProjectOptions(Release.javaSE("1.7.0"), 4), new NullProgressMonitor());
final String actual = normalizeJavaSourceCode(doc.get().replaceAll("samples_in", "samples_out"));
final String expected = normalizeJavaSourceCode(sampleOutSource);
assertEquals(testName + ": wrong output;", expected, actual);
}
Aggregations