import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
-
/**
* Java default folding preferences.
- *
+ *
* @since 3.0
*/
public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreferenceBlock {
private IPreferenceStore fStore;
+
private OverlayPreferenceStore fOverlayStore;
+
private OverlayKey[] fKeys;
- private Map fCheckBoxes= new HashMap();
- private SelectionListener fCheckBoxListener= new SelectionListener() {
+
+ private Map fCheckBoxes = new HashMap();
+
+ private SelectionListener fCheckBoxListener = new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
+
public void widgetSelected(SelectionEvent e) {
- Button button= (Button) e.widget;
+ Button button = (Button) e.widget;
fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
}
};
-
public DefaultJavaFoldingPreferenceBlock() {
- fStore= PHPeclipsePlugin.getDefault().getPreferenceStore();
- fKeys= createKeys();
- fOverlayStore= new OverlayPreferenceStore(fStore, fKeys);
+ fStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ fKeys = createKeys();
+ fOverlayStore = new OverlayPreferenceStore(fStore, fKeys);
}
-
+
private OverlayKey[] createKeys() {
- ArrayList overlayKeys= new ArrayList();
+ ArrayList overlayKeys = new ArrayList();
+
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_FOLDING_JAVADOC));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_FOLDING_HEADERS));
+ // overlayKeys.add(new
+ // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ // PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_FOLDING_METHODS));
+ // overlayKeys.add(new
+ // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ // PreferenceConstants.EDITOR_FOLDING_IMPORTS));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_JAVADOC));
-// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS));
-// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_IMPORTS));
-
return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys.size()]);
}
public Control createControl(Composite composite) {
fOverlayStore.load();
fOverlayStore.start();
-
- Composite inner= new Composite(composite, SWT.NONE);
- GridLayout layout= new GridLayout(1, true);
- layout.verticalSpacing= 3;
- layout.marginWidth= 0;
+
+ Composite inner = new Composite(composite, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ layout.verticalSpacing = 3;
+ layout.marginWidth = 0;
inner.setLayout(layout);
-
- Label label= new Label(inner, SWT.LEFT);
+
+ Label label = new Label(inner, SWT.LEFT);
label.setText(FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$
-
-// addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
-// addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.innerTypes"), PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
- addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
-// addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"), PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
-
+
+ addCheckBox(inner,
+ FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
+ addCheckBox(inner,
+ FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.headers"), PreferenceConstants.EDITOR_FOLDING_HEADERS, 0);//$NON-NLS-1$
+ // addCheckBox(inner,
+ // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.innerTypes"),
+ // PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
+ addCheckBox(inner,
+ FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
+ // addCheckBox(inner,
+ // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"),
+ // PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
+
return inner;
}
-
- private Button addCheckBox(Composite parent, String label, String key, int indentation) {
- Button checkBox= new Button(parent, SWT.CHECK);
+
+ private Button addCheckBox(Composite parent, String label, String key, int indentation) {
+ Button checkBox = new Button(parent, SWT.CHECK);
checkBox.setText(label);
-
- GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- gd.horizontalIndent= indentation;
- gd.horizontalSpan= 1;
- gd.grabExcessVerticalSpace= false;
+
+ GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ gd.horizontalIndent = indentation;
+ gd.horizontalSpan = 1;
+ gd.grabExcessVerticalSpace = false;
checkBox.setLayoutData(gd);
checkBox.addSelectionListener(fCheckBoxListener);
-
+
fCheckBoxes.put(checkBox, key);
-
+
return checkBox;
}
-
+
private void initializeFields() {
- Iterator it= fCheckBoxes.keySet().iterator();
+ Iterator it = fCheckBoxes.keySet().iterator();
while (it.hasNext()) {
- Button b= (Button) it.next();
- String key= (String) fCheckBoxes.get(b);
+ Button b = (Button) it.next();
+ String key = (String) fCheckBoxes.get(b);
b.setSelection(fOverlayStore.getBoolean(key));
}
}
-
+
/*
* @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performOk()
*/
public void performOk() {
fOverlayStore.propagate();
}
-
-
+
/*
* @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#initialize()
*/
public void initialize() {
initializeFields();
}
-
+
/*
* @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performDefaults()
*/
fOverlayStore.loadDefaults();
initializeFields();
}
-
+
/*
* @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#dispose()
*/
import net.sourceforge.phpdt.core.compiler.IScanner;
import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
import net.sourceforge.phpdt.core.compiler.InvalidInputException;
+import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
import net.sourceforge.phpdt.internal.ui.text.DocumentCharacterIterator;
import net.sourceforge.phpdt.ui.IWorkingCopyManager;
import net.sourceforge.phpdt.ui.PreferenceConstants;
private boolean fCollapseJavadoc = false;
-// private boolean fCollapseImportContainer = true;
+ // private boolean fCollapseImportContainer = true;
private boolean fCollapseInnerTypes = true;
ICompilationUnit unit = (ICompilationUnit) fInput;
synchronized (unit) {
try {
-// unit.reconcile(ICompilationUnit.NO_AST, false, null, null);
+ // unit.reconcile(ICompilationUnit.NO_AST, false, null, null);
unit.reconcile();
} catch (JavaModelException x) {
}
private void initializePreferences() {
IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
fCollapseInnerTypes = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_INNERTYPES);
-// fCollapseImportContainer = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_IMPORTS);
+ // fCollapseImportContainer =
+ // store.getBoolean(PreferenceConstants.EDITOR_FOLDING_IMPORTS);
fCollapseJavadoc = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_JAVADOC);
fCollapseMethods = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_METHODS);
fCollapseHeaderComments = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_HEADERS);
private Map computeAdditions(IParent parent) {
Map map = new LinkedHashMap(); // use a linked map to maintain ordering of
- // comments
+ // comments
try {
computeAdditions(parent.getChildren(), map);
} catch (JavaModelException x) {
boolean collapse = false;
switch (element.getElementType()) {
-// case IJavaElement.IMPORT_CONTAINER:
-// collapse = fAllowCollapsing && fCollapseImportContainer;
-// createProjection = true;
-// break;
+ // case IJavaElement.IMPORT_CONTAINER:
+ // collapse = fAllowCollapsing && fCollapseImportContainer;
+ // createProjection = true;
+ // break;
case IJavaElement.TYPE:
collapse = fAllowCollapsing && fCollapseInnerTypes && isInnerType((IType) element);
createProjection = true;
}
}
- IScanner scanner = ToolFactory.createScanner(true, false, false, false);
- scanner.setSource(contents.toCharArray());
final int shift = range.getOffset();
int start = shift;
- while (true) {
+ if (element instanceof IType) {
+ Scanner scanner = ToolFactory.createScanner(true, false, false, false);
+ scanner.setSource(contents.toCharArray());
+ scanner.setPHPMode(true);
int token = scanner.getNextToken();
- start = shift + scanner.getCurrentTokenStartPosition();
+ while (token != ITerminalSymbols.TokenNameEOF) {
- switch (token) {
- case ITerminalSymbols.TokenNameCOMMENT_PHPDOC:
- case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
- int end = shift + scanner.getCurrentTokenEndPosition() + 1;
- regions.add(new Region(start, end - start));
- }
- case ITerminalSymbols.TokenNameCOMMENT_LINE:
- continue;
- }
+ token = scanner.getNextToken();
+ start = shift + scanner.getCurrentTokenStartPosition();
- break;
+ switch (token) {
+ case ITerminalSymbols.TokenNameCOMMENT_PHPDOC:
+ case ITerminalSymbols.TokenNameCOMMENT_BLOCK: {
+ int end = shift + scanner.getCurrentTokenEndPosition() + 1;
+ regions.add(new Region(start, end - start));
+ }
+ case ITerminalSymbols.TokenNameCOMMENT_LINE:
+ continue;
+ }
+ }
}
-
regions.add(new Region(start, shift + range.getLength() - start));
if (regions.size() > 0) {
regions.toArray(result);
return result;
}
+
}
} catch (JavaModelException e) {
} catch (InvalidInputException e) {