issue_id
int64 2.03k
426k
| title
stringlengths 9
251
| body
stringlengths 1
32.8k
⌀ | status
stringclasses 6
values | after_fix_sha
stringlengths 7
7
| project_name
stringclasses 6
values | repo_url
stringclasses 6
values | repo_name
stringclasses 6
values | language
stringclasses 1
value | issue_url
null | before_fix_sha
null | pull_url
null | commit_datetime
timestamp[us, tz=UTC] | report_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 2
187
| file_content
stringlengths 0
368k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
38,892 |
Bug 38892 ASTRewrite should support copying nodes more than once.
|
M1 Try is result currently in an exception: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; Node used as more than one copy source at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.dom.ASTRewrite.createCopy (ASTRewrite.java:289)
|
resolved fixed
|
4cfc259
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-13T17:08:53Z | 2003-06-13T16:00:00Z |
extension/org/eclipse/jdt/internal/corext/dom/ASTRewrite.java
| |
38,892 |
Bug 38892 ASTRewrite should support copying nodes more than once.
|
M1 Try is result currently in an exception: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; Node used as more than one copy source at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.dom.ASTRewrite.createCopy (ASTRewrite.java:289)
|
resolved fixed
|
4cfc259
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-13T17:08:53Z | 2003-06-13T16:00:00Z |
org.eclipse.jdt.ui/core
| |
38,892 |
Bug 38892 ASTRewrite should support copying nodes more than once.
|
M1 Try is result currently in an exception: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; Node used as more than one copy source at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.dom.ASTRewrite.createCopy (ASTRewrite.java:289)
|
resolved fixed
|
4cfc259
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-13T17:08:53Z | 2003-06-13T16:00:00Z |
extension/org/eclipse/jdt/internal/corext/dom/ASTRewriteAnalyzer.java
| |
38,892 |
Bug 38892 ASTRewrite should support copying nodes more than once.
|
M1 Try is result currently in an exception: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; Node used as more than one copy source at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.dom.ASTRewrite.createCopy (ASTRewrite.java:289)
|
resolved fixed
|
4cfc259
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-13T17:08:53Z | 2003-06-13T16:00:00Z |
org.eclipse.jdt.ui/core
| |
38,892 |
Bug 38892 ASTRewrite should support copying nodes more than once.
|
M1 Try is result currently in an exception: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; Node used as more than one copy source at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.dom.ASTRewrite.createCopy (ASTRewrite.java:289)
|
resolved fixed
|
4cfc259
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-13T17:08:53Z | 2003-06-13T16:00:00Z |
extension/org/eclipse/jdt/internal/corext/dom/CopyIndentedSourceEdit.java
| |
38,512 |
Bug 38512 [call hierarchy] should open callee on double click
|
I20030604 A double click on a caller in the callers view will neither open the caller file (as context menu -> open does) nor expand the tree item. Open the file would be more intuitive IMHO, but something should happen anyway.
|
verified fixed
|
6eb3294
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-16T12:43:50Z | 2003-06-05T13:33:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyUI.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Jesper Kamstrup Linnet ([email protected]) - initial API and implementation
* (report 36180: Callers/Callees view)
******************************************************************************/
package org.eclipse.jdt.internal.ui.callhierarchy;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.OpenActionUtil;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
public class CallHierarchyUI {
private static final int DEFAULT_MAX_CALL_DEPTH= 10;
private static final String PREF_MAX_CALL_DEPTH = "PREF_MAX_CALL_DEPTH"; //$NON-NLS-1$
private static CallHierarchyUI fgInstance;
private CallHierarchyUI() { }
public static CallHierarchyUI getDefault() {
if (fgInstance == null) {
fgInstance = new CallHierarchyUI();
}
return fgInstance;
}
/**
* Returns the maximum tree level allowed
* @return int
*/
public int getMaxCallDepth() {
int maxCallDepth;
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
maxCallDepth = settings.getInt(PREF_MAX_CALL_DEPTH);
if (maxCallDepth < 1 || maxCallDepth > 99) {
maxCallDepth= DEFAULT_MAX_CALL_DEPTH;
}
return maxCallDepth;
}
public void setMaxCallDepth(int maxCallDepth) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_MAX_CALL_DEPTH, maxCallDepth);
}
public static void jumpToMember(IJavaElement element) {
if (element != null) {
try {
IEditorPart methodEditor = EditorUtility.openInEditor(element, true);
JavaUI.revealInEditor(methodEditor, (IJavaElement) element);
} catch (JavaModelException e) {
JavaPlugin.log(e);
} catch (PartInitException e) {
JavaPlugin.log(e);
}
}
}
public static void jumpToLocation(CallLocation callLocation) {
try {
IEditorPart methodEditor = EditorUtility.openInEditor(callLocation.getMember(),
false);
if (methodEditor instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) methodEditor;
editor.selectAndReveal(callLocation.getStart(),
(callLocation.getEnd() - callLocation.getStart()));
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
} catch (PartInitException e) {
JavaPlugin.log(e);
}
}
public static void openInEditor(Object element, Shell shell, String title) {
CallLocation callLocation= null;
if (element instanceof CallLocation) {
callLocation= (CallLocation) element;
} else if (element instanceof CallLocation) {
callLocation= CallHierarchy.getCallLocation(element);
}
if (callLocation == null) {
return;
}
try {
boolean activateOnOpen = OpenStrategy.activateOnOpen();
IEditorPart methodEditor = EditorUtility.openInEditor(callLocation.getMember(),
activateOnOpen);
if (methodEditor instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) methodEditor;
editor.selectAndReveal(callLocation.getStart(),
(callLocation.getEnd() - callLocation.getStart()));
}
} catch (JavaModelException e) {
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
IJavaStatusConstants.INTERNAL_ERROR,
CallHierarchyMessages.getString(
"CallHierarchyUI.open_in_editor.error.message"), e)); //$NON-NLS-1$
ErrorDialog.openError(shell, title,
CallHierarchyMessages.getString(
"CallHierarchyUI.open_in_editor.error.messageProblems"), //$NON-NLS-1$
e.getStatus());
} catch (PartInitException x) {
String name = callLocation.getCalledMember().getElementName();
MessageDialog.openError(shell,
CallHierarchyMessages.getString(
"CallHierarchyUI.open_in_editor.error.messageProblems"), //$NON-NLS-1$
CallHierarchyMessages.getFormattedString(
"CallHierarchyUI.open_in_editor.error.messageArgs", //$NON-NLS-1$
new String[] { name, x.getMessage() }));
}
}
/**
* @param elem
* @return
*/
public static IEditorPart isOpenInEditor(Object elem) {
IJavaElement javaElement= null;
if (elem instanceof MethodWrapper) {
javaElement= ((MethodWrapper) elem).getMember();
} else if (elem instanceof CallLocation) {
javaElement= ((CallLocation) elem).getCalledMember();
}
if (javaElement != null) {
return EditorUtility.isOpenInEditor(javaElement);
}
return null;
}
/**
* Converts the input to a possible input candidates
*/
public static IJavaElement[] getCandidates(Object input) {
if (!(input instanceof IJavaElement)) {
return null;
}
IJavaElement elem= (IJavaElement) input;
if (elem.getElementType() == IJavaElement.METHOD) {
return new IJavaElement[] { elem };
}
return null;
}
public static CallHierarchyViewPart open(IJavaElement[] candidates, IWorkbenchWindow window) {
Assert.isTrue(candidates != null && candidates.length != 0);
IJavaElement input= null;
if (candidates.length > 1) {
String title= CallHierarchyMessages.getString("CallHierarchyUI.selectionDialog.title"); //$NON-NLS-1$
String message= CallHierarchyMessages.getString("CallHierarchyUI.selectionDialog.message"); //$NON-NLS-1$
input= OpenActionUtil.selectJavaElement(candidates, window.getShell(), title, message);
} else {
input= candidates[0];
}
if (input == null)
return null;
return openInViewPart(window, input);
}
private static void openEditor(Object input, boolean activate) throws PartInitException, JavaModelException {
IEditorPart part= EditorUtility.openInEditor(input, activate);
if (input instanceof IJavaElement)
EditorUtility.revealInEditor(part, (IJavaElement) input);
}
private static CallHierarchyViewPart openInViewPart(IWorkbenchWindow window, IJavaElement input) {
IWorkbenchPage page= window.getActivePage();
try {
CallHierarchyViewPart result= (CallHierarchyViewPart)page.showView(CallHierarchyViewPart.ID_CALL_HIERARCHY);
result.setMethod((IMethod)input);
openEditor(input, false);
return result;
} catch (CoreException e) {
ExceptionHandler.handle(e, window.getShell(),
CallHierarchyMessages.getString("CallHierarchyUI.error.open_view"), e.getMessage()); //$NON-NLS-1$
}
return null;
}
}
|
38,496 |
Bug 38496 sort members: should be disabled on types with no members [code manipulation]
|
20030604 currently what you get is a no-op. not even an info dialog
|
resolved fixed
|
e7d5c5f
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-16T13:19:16Z | 2003-06-05T10:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SortMembersAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.internal.corext.codemanipulation.SortMembersOperation;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.javaeditor.AnnotationType;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
/**
* Sorts the members of a compilation unit with the sort order as specified in
* the Sort Order preference page.
* <p>
* The action will open the parent compilation unit in a Java editor. The result
* is unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing a single
* <code>ICompilationUnit</code> or top level <code>IType</code> in a
* compilation unit.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.1
*/
public class SortMembersAction extends SelectionDispatchAction {
private CompilationUnitEditor fEditor;
/**
* Creates a new <code>SortMembersAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public SortMembersAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("SortMembersAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("SortMembersAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("SortMembersAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.SORT_MEMBERS_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public SortMembersAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(checkEnabledEditor());
}
private boolean checkEnabledEditor() {
return fEditor != null && SelectionConverter.canOperateOn(fEditor);
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
boolean enabled= false;
try {
enabled= getSelectedCompilationUnit(selection) != null;
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
}
setEnabled(enabled);
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
Shell shell= getShell();
try {
ICompilationUnit cu= getSelectedCompilationUnit(selection);
if (cu == null || !ElementValidator.check(cu, getShell(), getDialogTitle(), false)) {
return;
}
// open an editor and work on a working copy
IEditorPart editor= EditorUtility.openInEditor(cu);
if (editor != null) {
run(shell, JavaModelUtil.toWorkingCopy(cu), editor);
}
} catch (CoreException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
}
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
Shell shell= getShell();
IJavaElement input= SelectionConverter.getInput(fEditor);
if (input instanceof ICompilationUnit) {
if (ElementValidator.check(input, getShell(), getDialogTitle(), true)) {
run(shell, (ICompilationUnit) input, fEditor);
}
} else {
MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.getString("SortMembersAction.not_applicable")); //$NON-NLS-1$
}
}
//---- Helpers -------------------------------------------------------------------
private boolean containsRelevantMarkers(IEditorPart editor) {
IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
Iterator iterator= model.getAnnotationIterator();
while (iterator.hasNext()) {
Object element= iterator.next();
if (element instanceof IJavaAnnotation) {
IJavaAnnotation annot= (IJavaAnnotation) element;
if (annot.isRelevant() && !annot.isTemporary()) {
AnnotationType type= annot.getAnnotationType();
return (type == AnnotationType.BOOKMARK || type == AnnotationType.TASK || type == AnnotationType.UNKNOWN);
}
}
}
return false;
}
private void run(Shell shell, ICompilationUnit cu, IEditorPart editor) {
if (!ActionUtil.isProcessable(getShell(), cu)) {
return;
}
if (containsRelevantMarkers(editor)) {
if (!MessageDialog.openConfirm(getShell(), getDialogTitle(), ActionMessages.getString("SortMembersAction.containsmarkers"))) { //$NON-NLS-1$
return;
}
}
SortMembersOperation op= new SortMembersOperation(cu, null);
try {
BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();
context.run(false, true, new WorkbenchRunnableAdapter(op));
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
} catch (InterruptedException e) {
// Do nothing. Operation has been canceled by user.
}
}
private ICompilationUnit getSelectedCompilationUnit(IStructuredSelection selection) throws JavaModelException {
if (selection.size() == 1) {
Object element= selection.getFirstElement();
if (element instanceof ICompilationUnit) {
return (ICompilationUnit) element;
} else if (element instanceof IType) {
IType type= (IType) element;
if (type.getParent() instanceof ICompilationUnit) { // only top level types
return type.getCompilationUnit();
}
}
}
return null;
}
private String getDialogTitle() {
return ActionMessages.getString("SortMembersAction.error.title"); //$NON-NLS-1$
}
}
|
36,902 |
Bug 36902 [preferences] IllegalArgumentException in JavaEditorHoverConfigurationBlock$3.keyReleased
| null |
resolved fixed
|
04a6632
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-16T16:04:20Z | 2003-04-25T14:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorHoverConfigurationBlock.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
import java.util.HashMap;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Assert;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
/**
* Configures Java Editor hover preferences.
*
* @since 2.1
*/
class JavaEditorHoverConfigurationBlock {
private static final String DELIMITER= PreferencesMessages.getString("JavaEditorHoverConfigurationBlock.delimiter"); //$NON-NLS-1$
// Data structure to hold the values which are edited by the user
private static class HoverConfig {
private String fModifierString;
private boolean fIsEnabled;
private int fStateMask;
private HoverConfig(String modifier, int stateMask, boolean enabled) {
fModifierString= modifier;
fIsEnabled= enabled;
fStateMask= stateMask;
}
}
private IPreferenceStore fStore;
private HoverConfig[] fHoverConfigs;
private Text fModifierEditor;
private Button fEnableField;
private List fHoverList;
private Text fDescription;
private JavaEditorPreferencePage fMainPreferencePage;
private StatusInfo fStatus;
public JavaEditorHoverConfigurationBlock(JavaEditorPreferencePage mainPreferencePage, IPreferenceStore store) {
Assert.isNotNull(mainPreferencePage);
Assert.isNotNull(store);
fMainPreferencePage= mainPreferencePage;
fStore= store;
}
/**
* Creates page for hover preferences.
*/
public Control createControl(Composite parent) {
Composite hoverComposite= new Composite(parent, SWT.NULL);
GridLayout layout= new GridLayout();
layout.numColumns= 2;
hoverComposite.setLayout(layout);
GridData gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
hoverComposite.setLayoutData(gd);
Label label= new Label(hoverComposite, SWT.NONE);
label.setText(PreferencesMessages.getString("JavaEditorHoverConfigurationBlock.hoverPreferences")); //$NON-NLS-1$
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment= GridData.BEGINNING;
gd.horizontalSpan= 2;
label.setLayoutData(gd);
gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
// Hover list
fHoverList= new List(hoverComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
gd.heightHint= convertHeightInCharsToPixels(parent, 10);
fHoverList.setLayoutData(gd);
fHoverList.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
handleHoverListSelection();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
Composite stylesComposite= new Composite(hoverComposite, SWT.NONE);
layout= new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 2;
stylesComposite.setLayout(layout);
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint= convertHeightInCharsToPixels(parent, 10) + (2 * fHoverList.getBorderWidth());
stylesComposite.setLayoutData(gd);
// Enabled checkbox
fEnableField= new Button(stylesComposite, SWT.CHECK);
fEnableField.setText(PreferencesMessages.getString("JavaEditorHoverConfigurationBlock.enabled")); //$NON-NLS-1$
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment= GridData.BEGINNING;
gd.horizontalSpan= 2;
fEnableField.setLayoutData(gd);
fEnableField.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
int i= fHoverList.getSelectionIndex();
boolean state= fEnableField.getSelection();
fModifierEditor.setEnabled(state);
fHoverConfigs[i].fIsEnabled= state;
handleModifierModified();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// Text field for modifier string
label= new Label(stylesComposite, SWT.LEFT);
label.setText(PreferencesMessages.getString("JavaEditorHoverConfigurationBlock.keyModifier")); //$NON-NLS-1$
fModifierEditor= new Text(stylesComposite, SWT.BORDER);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
fModifierEditor.setLayoutData(gd);
fModifierEditor.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
public void keyPressed(KeyEvent e) {
isModifierCandidate= e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {// && e.time -time < 1000) {
String text= fModifierEditor.getText();
Point selection= fModifierEditor.getSelection();
int i= selection.x - 1;
while (i > -1 && Character.isWhitespace(text.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter= i > -1 && !String.valueOf(text.charAt(i)).equals(DELIMITER);
i= selection.y;
while (i < text.length() && Character.isWhitespace(text.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter= i < text.length() && !String.valueOf(text.charAt(i)).equals(DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString= PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.insertDelimiterAndModifierAndDelimiter", new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
else if (needsPrefixDelimiter)
insertString= PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.insertDelimiterAndModifier", new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
else if (needsPostfixDelimiter)
insertString= PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.insertModifierAndDelimiter", new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
else
insertString= Action.findModifierString(e.stateMask);
fModifierEditor.insert(insertString);
}
}
});
fModifierEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
handleModifierModified();
}
});
// Description
Label descriptionLabel= new Label(stylesComposite, SWT.LEFT);
descriptionLabel.setText(PreferencesMessages.getString("JavaEditorHoverConfigurationBlock.description")); //$NON-NLS-1$
gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
gd.horizontalSpan= 2;
descriptionLabel.setLayoutData(gd);
fDescription= new Text(stylesComposite, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
gd= new GridData(GridData.FILL_BOTH);
gd.horizontalSpan= 2;
fDescription.setLayoutData(gd);
initialize();
Dialog.applyDialogFont(hoverComposite);
return hoverComposite;
}
private JavaEditorTextHoverDescriptor[] getContributedHovers() {
return JavaPlugin.getDefault().getJavaEditorTextHoverDescriptors();
}
void initialize() {
JavaEditorTextHoverDescriptor[] hoverDescs= getContributedHovers();
fHoverConfigs= new HoverConfig[hoverDescs.length];
for (int i= 0; i < hoverDescs.length; i++) {
fHoverConfigs[i]= new HoverConfig(hoverDescs[i].getModifierString(), hoverDescs[i].getStateMask(), hoverDescs[i].isEnabled());
fHoverList.add(hoverDescs[i].getLabel());
}
initializeFields();
}
void initializeFields() {
fHoverList.getDisplay().asyncExec(new Runnable() {
public void run() {
if (fHoverList != null && !fHoverList.isDisposed()) {
fHoverList.select(0);
handleHoverListSelection();
}
}
});
}
void performOk() {
StringBuffer buf= new StringBuffer();
StringBuffer maskBuf= new StringBuffer();
for (int i= 0; i < fHoverConfigs.length; i++) {
buf.append(getContributedHovers()[i].getId());
buf.append(JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
if (!fHoverConfigs[i].fIsEnabled)
buf.append(JavaEditorTextHoverDescriptor.DISABLED_TAG);
String modifier= fHoverConfigs[i].fModifierString;
if (modifier == null || modifier.length() == 0)
modifier= JavaEditorTextHoverDescriptor.NO_MODIFIER;
buf.append(modifier);
buf.append(JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
maskBuf.append(getContributedHovers()[i].getId());
maskBuf.append(JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
maskBuf.append(fHoverConfigs[i].fStateMask);
maskBuf.append(JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
}
fStore.setValue(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS, buf.toString());
fStore.setValue(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS, maskBuf.toString());
JavaPlugin.getDefault().resetJavaEditorTextHoverDescriptors();
}
void performDefaults() {
restoreFromPreferences();
initializeFields();
}
private void restoreFromPreferences() {
String compiledTextHoverModifiers= fStore.getString(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS);
StringTokenizer tokenizer= new StringTokenizer(compiledTextHoverModifiers, JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
HashMap idToModifier= new HashMap(tokenizer.countTokens() / 2);
while (tokenizer.hasMoreTokens()) {
String id= tokenizer.nextToken();
if (tokenizer.hasMoreTokens())
idToModifier.put(id, tokenizer.nextToken());
}
String compiledTextHoverModifierMasks= JavaPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS);
tokenizer= new StringTokenizer(compiledTextHoverModifierMasks, JavaEditorTextHoverDescriptor.VALUE_SEPARATOR);
HashMap idToModifierMask= new HashMap(tokenizer.countTokens() / 2);
while (tokenizer.hasMoreTokens()) {
String id= tokenizer.nextToken();
if (tokenizer.hasMoreTokens())
idToModifierMask.put(id, tokenizer.nextToken());
}
for (int i= 0; i < fHoverConfigs.length; i++) {
String modifierString= (String)idToModifier.get(getContributedHovers()[i].getId());
boolean enabled= true;
if (modifierString == null)
modifierString= JavaEditorTextHoverDescriptor.DISABLED_TAG;
if (modifierString.startsWith(JavaEditorTextHoverDescriptor.DISABLED_TAG)) {
enabled= false;
modifierString= modifierString.substring(1);
}
if (modifierString.equals(JavaEditorTextHoverDescriptor.NO_MODIFIER))
modifierString= ""; //$NON-NLS-1$
fHoverConfigs[i].fModifierString= modifierString;
fHoverConfigs[i].fIsEnabled= enabled;
fHoverConfigs[i].fStateMask= JavaEditorTextHoverDescriptor.computeStateMask(modifierString);
if (fHoverConfigs[i].fStateMask == -1) {
try {
fHoverConfigs[i].fStateMask= Integer.parseInt((String)idToModifierMask.get(getContributedHovers()[i].getId()));
} catch (NumberFormatException ex) {
fHoverConfigs[i].fStateMask= -1;
}
}
}
}
private void handleModifierModified() {
int i= fHoverList.getSelectionIndex();
String modifiers= fModifierEditor.getText();
fHoverConfigs[i].fModifierString= modifiers;
fHoverConfigs[i].fStateMask= JavaEditorTextHoverDescriptor.computeStateMask(modifiers);
if (fHoverConfigs[i].fIsEnabled && fHoverConfigs[i].fStateMask == -1)
fStatus= new StatusInfo(StatusInfo.ERROR, PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.modifierIsNotValid", fHoverConfigs[i].fModifierString)); //$NON-NLS-1$
else
fStatus= new StatusInfo();
updateStatus();
}
private void handleHoverListSelection() {
int i= fHoverList.getSelectionIndex();
boolean enabled= fHoverConfigs[i].fIsEnabled;
fEnableField.setSelection(enabled);
fModifierEditor.setEnabled(enabled);
fModifierEditor.setText(fHoverConfigs[i].fModifierString);
String description= getContributedHovers()[i].getDescription();
if (description == null)
description= ""; //$NON-NLS-1$
fDescription.setText(description);
}
private int convertHeightInCharsToPixels(Control control, int chars) {
GC gc = new GC(control);
gc.setFont(control.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
if (fontMetrics == null)
return 0;
return Dialog.convertHeightInCharsToPixels(fontMetrics, chars);
}
IStatus getStatus() {
if (fStatus == null)
fStatus= new StatusInfo();
return fStatus;
}
private void updateStatus() {
int i= 0;
HashMap stateMasks= new HashMap(fHoverConfigs.length);
while (fStatus.isOK() && i < fHoverConfigs.length) {
if (fHoverConfigs[i].fIsEnabled) {
String label= getContributedHovers()[i].getLabel();
Integer stateMask= new Integer(fHoverConfigs[i].fStateMask);
if (fHoverConfigs[i].fStateMask == -1)
fStatus= new StatusInfo(StatusInfo.ERROR, PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.modifierIsNotValidForHover", new String[] {fHoverConfigs[i].fModifierString, label})); //$NON-NLS-1$
else if (stateMasks.containsKey(stateMask))
fStatus= new StatusInfo(StatusInfo.ERROR, PreferencesMessages.getFormattedString("JavaEditorHoverConfigurationBlock.duplicateModifier", new String[] {label, (String)stateMasks.get(stateMask)})); //$NON-NLS-1$
else
stateMasks.put(stateMask, label);
}
i++;
}
if (fStatus.isOK())
fMainPreferencePage.updateStatus(fStatus);
else {
fMainPreferencePage.setValid(false);
StatusUtil.applyToStatusLine(fMainPreferencePage, fStatus);
}
}
}
|
38,485 |
Bug 38485 add constructors: incorrect text selection after [code manipulation]
|
20030604 class A extedns ArrayList{ } after adding all 3 constructors, the text selection is set to something in the middle of a comment not, to to something meaningful
|
resolved fixed
|
e2eafeb
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-16T16:49:33Z | 2003-06-05T10:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddUnimplementedConstructorsAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
/**
* Creates unimplemented constructors for a type.
* <p>
* Will open the parent compilation unit in a Java editor. Opens a dialog
* with a list of constructors from the super class which can be generated.
* User is able to check or uncheck items before constructors are generated.
* The result is unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class AddUnimplementedConstructorsAction extends SelectionDispatchAction {
private CompilationUnitEditor fEditor;
private static final String dialogTitle= ActionMessages.getString("AddUnimplementedConstructorsAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>AddUnimplementedConstructorsAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddUnimplementedConstructorsAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddUnimplementedConstructorsAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddUnimplementedConstructorsAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddUnimplementedConstructorsAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_UNIMPLEMENTED_CONSTRUCTORS_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddUnimplementedConstructorsAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(checkEnabledEditor());
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
Shell shell= getShell();
try {
IType type= getSelectedType(selection);
if (type == null) {
MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.not_applicable")); //$NON-NLS-1$
return;
}
// open an editor and work on a working copy
IEditorPart editor= EditorUtility.openInEditor(type);
type= (IType)EditorUtility.getWorkingCopy(type);
if (type == null) {
MessageDialog.openError(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.type_removed_in_editor")); //$NON-NLS-1$
return;
}
run(shell, type, editor, false);
} catch (CoreException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
}
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
protected void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
Shell shell= getShell();
try {
IType type= SelectionConverter.getTypeAtOffset(fEditor);
if (type != null)
run(shell, type, fEditor, true);
else
MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.not_applicable")); //$NON-NLS-1$
} catch (JavaModelException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
}
}
private boolean checkEnabledEditor() {
return fEditor != null && SelectionConverter.canOperateOn(fEditor);
}
//---- Helpers -------------------------------------------------------------------
private void run(Shell shell, IType type, IEditorPart editor, boolean activatedFromEditor) throws CoreException {
if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) {
return;
}
if (!ActionUtil.isProcessable(getShell(), type)) {
return;
}
IMethod[] constructorMethods= StubUtility.getOverridableConstructors(type);
if (constructorMethods.length == 0) {
MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.nothing_found")); //$NON-NLS-1$
return;
}
JavaElementLabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
AddUnimplementedConstructorsContentProvider contentProvider = new AddUnimplementedConstructorsContentProvider(constructorMethods);
SourceActionDialog dialog= new SourceActionDialog(shell, labelProvider, contentProvider, fEditor, type);
dialog.setCommentString(ActionMessages.getString("SourceActionDialog.createConstructorComment")); //$NON-NLS-1$
dialog.setTitle(getDialogTitle());
dialog.setInitialSelections(constructorMethods);
dialog.setContainerMode(true);
dialog.setSorter(new JavaElementSorter());
dialog.setSize(60, 18);
dialog.setInput(new Object());
dialog.setMessage(ActionMessages.getString("AddUnimplementedConstructorsAction.dialog.label")); //$NON-NLS-1$
dialog.setValidator(createValidator(constructorMethods.length));
IMethod[] selected= null;
int dialogResult = dialog.open();
if (dialogResult == Window.OK) {
Object[] checkedElements = dialog.getResult();
if (checkedElements == null)
return;
ArrayList result= new ArrayList(checkedElements.length);
for (int i= 0; i < checkedElements.length; i++) {
Object curr= checkedElements[i];
if (curr instanceof IMethod) {
result.add(curr);
}
}
selected= (IMethod[]) result.toArray(new IMethod[result.size()]);
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= dialog.getGenerateComment();
IJavaElement elementPosition= dialog.getElementPosition();
AddUnimplementedMethodsOperation op= new AddUnimplementedMethodsOperation(type, settings, selected, false, elementPosition);
IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null;
if (target != null) {
target.beginCompoundChange();
}
try {
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod[] res= op.getCreatedMethods();
if (res == null || res.length == 0) {
MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.nothing_found")); //$NON-NLS-1$
} else if (editor != null) {
EditorUtility.revealInEditor(editor, res[0]);
}
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
} catch (InterruptedException e) {
// Do nothing. Operation has been canceled by user.
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddUnimplementedConstructorsValidator validator= new AddUnimplementedConstructorsValidator(entries);
return validator;
}
private IType getSelectedType(IStructuredSelection selection) throws JavaModelException {
Object[] elements= selection.toArray();
if (elements.length == 1 && (elements[0] instanceof IType)) {
IType type= (IType) elements[0];
if (type.getCompilationUnit() != null && type.isClass()) {
return type;
}
}
else if (elements[0] instanceof ICompilationUnit) {
ICompilationUnit cu= (ICompilationUnit) elements[0];
IType type= cu.findPrimaryType();
if (type != null && !type.isInterface())
return type;
}
return null;
}
private String getDialogTitle() {
return dialogTitle;
}
private static class AddUnimplementedConstructorsContentProvider implements ITreeContentProvider {
private IMethod[] fMethodsList;
private static final Object[] EMPTY= new Object[0];
public AddUnimplementedConstructorsContentProvider(IMethod[] methodList) {
fMethodsList= methodList;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fMethodsList;
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
private static class AddUnimplementedConstructorsValidator implements ISelectionStatusValidator {
private static int fEntries;
AddUnimplementedConstructorsValidator(int entries) {
super();
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedMethods(selection);
if (count == 0)
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
String message= ActionMessages.getFormattedString("AddUnimplementedConstructorsAction.methods_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedMethods(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof IMethod)
count++;
}
return count;
}
}
}
|
36,908 |
Bug 36908 [Workbench] Workbench Window becomes disabled
|
The workbench window's client area becomes completely disabled sometimes when I save a java file. Everything from the toolbar (inclusively) down is disabled to mouse and keyboard. Is there somewhere that setEnabled(false) is being called? Only the menu can be used, and I am forced to close the window because there is no way to get it enabled again. This happens to me more than once per day. For some users, they would be forced to exit Eclipse.
|
resolved fixed
|
7c9e598
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-17T08:38:28Z | 2003-04-25T14:13:20Z |
org.eclipse.jdt.ui/ui
| |
36,908 |
Bug 36908 [Workbench] Workbench Window becomes disabled
|
The workbench window's client area becomes completely disabled sometimes when I save a java file. Everything from the toolbar (inclusively) down is disabled to mouse and keyboard. Is there somewhere that setEnabled(false) is being called? Only the menu can be used, and I am forced to close the window because there is no way to get it enabled again. This happens to me more than once per day. For some users, they would be forced to exit Eclipse.
|
resolved fixed
|
7c9e598
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-17T08:38:28Z | 2003-04-25T14:13:20Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringWizardDialog2.java
| |
3,888 |
Bug 3888 Single click in type hierarchy not working (1GF278R)
|
Single click in type hierarchy on an already opened file should bring it to front. NOTES: MA (03.08.2001 15:27:31) seems to work now (200), cant reproduce the PR
|
verified fixed
|
9906f48
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-17T09:19:45Z | 2001-10-11T03:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.infoviews;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.util.WorkingCopyUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.search.SearchUtil;
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* Abstract class for views which show information for a given element.
*
* @since 3.0
*/
abstract class AbstractInfoView extends ViewPart implements ISelectionListener {
private static final int TITLE_LABEL_FLAGS= 0; // JavaElementLabels.DEFAULT_QUALIFIED | JavaElementLabels.ROOT_POST_QUALIFIED;
private static final int TOOLTIP_LABEL_FLAGS= JavaElementLabels.DEFAULT_QUALIFIED | JavaElementLabels.ROOT_POST_QUALIFIED | JavaElementLabels.APPEND_ROOT_PATH |
JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_APP_RETURNTYPE | JavaElementLabels.M_EXCEPTIONS |
JavaElementLabels.F_APP_TYPE_SIGNATURE;
protected IJavaElement fCurrentInput;
private IWorkbenchPart fLastActivatedPart;
private IPartListener2 fPartListener= new IPartListener2() {
public void partVisible(IWorkbenchPartReference ref) {
if (ref.getId().equals(getSite().getId()))
startListeningForSelectionChanges();
}
public void partHidden(IWorkbenchPartReference ref) {
if (ref.getId().equals(getSite().getId()))
stopListeningForSelectionChanges();
}
public void partInputChanged(IWorkbenchPartReference ref) {
if (!ref.getId().equals(getSite().getId()))
setInputFrom(ref.getPart(false));
}
public void partActivated(IWorkbenchPartReference ref) {
fLastActivatedPart= ref.getPart(false);
}
public void partBroughtToTop(IWorkbenchPartReference ref) {
}
public void partClosed(IWorkbenchPartReference ref) {
}
public void partDeactivated(IWorkbenchPartReference ref) {
}
public void partOpened(IWorkbenchPartReference ref) {
}
};
abstract protected boolean setInput(Object input);
abstract protected void internalCreatePartControl(Composite parent);
abstract protected void setForeground(Color color);
abstract protected void setBackground(Color color);
public final void createPartControl(Composite parent) {
internalCreatePartControl(parent);
setInfoColor();
getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener);
}
private void setInfoColor() {
if (getSite().getShell().isDisposed())
return;
Display display= getSite().getShell().getDisplay();
if (display == null || display.isDisposed())
return;
setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
}
protected void startListeningForSelectionChanges() {
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
}
protected void stopListeningForSelectionChanges() {
getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part.equals(this))
return;
if (fLastActivatedPart != null && fLastActivatedPart.equals(part)) {
fLastActivatedPart= null;
return;
}
fLastActivatedPart= null;
setInputFrom(part);
}
private IJavaElement findJavaElement(IWorkbenchPart part) {
Object element;
try {
IStructuredSelection sel= SelectionConverter.getStructuredSelection(part);
element= SelectionUtil.getSingleElement(sel);
} catch (JavaModelException e) {
return null;
}
if (SearchUtil.isISearchResultViewEntry(element)) {
IJavaElement je= SearchUtil.getJavaElement(element);
if (je != null)
return je;
element= SearchUtil.getResource(element);
}
IJavaElement je= null;
if (element instanceof IAdaptable)
je= (IJavaElement)((IAdaptable)element).getAdapter(IJavaElement.class);
if (je != null && je.getElementType() == IJavaElement.COMPILATION_UNIT)
je= WorkingCopyUtil.getWorkingCopyIfExists((ICompilationUnit)je);
return je;
}
protected IType getTypeForCU(ICompilationUnit cu) {
if (cu == null || !cu.exists())
return null;
cu= WorkingCopyUtil.getWorkingCopyIfExists(cu);
// Use primary type if possible
IType primaryType= cu.findPrimaryType();
if (primaryType != null)
return primaryType;
// Use first top-level type
try {
IType[] types= cu.getTypes();
if (types.length > 0)
return types[0];
else
return null;
} catch (JavaModelException ex) {
return null;
}
}
private void setInputFrom(IWorkbenchPart part) {
IJavaElement je= findJavaElement(part);
if (fCurrentInput != null && fCurrentInput.equals(je))
return;
if (!setInput(je))
return;
fCurrentInput= je;
setTitle(getSite().getRegisteredName() + " (" + JavaElementLabels.getElementLabel(je, TITLE_LABEL_FLAGS) + ")"); //$NON-NLS-1$//$NON-NLS-2$
setTitleToolTip(JavaElementLabels.getElementLabel(je, TOOLTIP_LABEL_FLAGS)); //$NON-NLS-1$//$NON-NLS-2$
}
final public void dispose() {
getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
internalDispose();
}
/*
* @see IWorkbenchPart#dispose()
*/
protected void internalDispose() {
}
}
|
38,487 |
Bug 38487 add constructors: does not see the default constructor
|
20030604 public class Ad extends Object{ } class D extends Ad{ } it will not let me add a constructor to D even though D(){ super(); } would be what i want to have generated
|
resolved fixed
|
ecfdbdb
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-17T13:15:49Z | 2003-06-05T10:46:40Z |
org.eclipse.jdt.ui/core
| |
38,487 |
Bug 38487 add constructors: does not see the default constructor
|
20030604 public class Ad extends Object{ } class D extends Ad{ } it will not let me add a constructor to D even though D(){ super(); } would be what i want to have generated
|
resolved fixed
|
ecfdbdb
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-17T13:15:49Z | 2003-06-05T10:46:40Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility.java
| |
38,481 |
Bug 38481 getters/setters: insertion point incorrect
|
20020604 public class Ad { void f(){} int foo; int foo1; int foo2; } i seleced f() as the insert point and it added the getter after all the fields
|
resolved fixed
|
93dca26
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T12:14:19Z | 2003-06-05T10:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/SourceActionDialog.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility.GenStubSettings;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* An advanced version of CheckedTreeSelectionDialog with right-side button layout and
* extra buttons and composites.
*/
public class SourceActionDialog extends CheckedTreeSelectionDialog {
private int fInsertionIndex;
private CompilationUnitEditor fEditor;
private ISourceActionContentProvider fContentProvider;
private boolean fGenerateComment;
private IType fType;
private int fWidth = 60;
private int fHeight = 18;
private String fCommentString;
public SourceActionDialog(Shell parent, ILabelProvider labelProvider, ISourceActionContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider);
fEditor= editor;
fContentProvider= contentProvider;
fType= type;
fCommentString= ActionMessages.getString("SourceActionDialog.createMethodComment"); //$NON-NLS-1$
// Take the default from the default for generating comments from the code gen prefs
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
GenStubSettings genStubSettings= new GenStubSettings(settings);
fGenerateComment= genStubSettings.createComments;
}
public void setCommentString(String string) {
fCommentString= string;
}
protected ISourceActionContentProvider getContentProvider() {
return fContentProvider;
}
public int getInsertionIndex() {
return fInsertionIndex;
}
private void setInsertionIndex(int index) {
fInsertionIndex = index;
}
public boolean getGenerateComment() {
return fGenerateComment;
}
private void setGenerateComment(boolean comment) {
fGenerateComment= comment;
}
/**
* Sets the size of the tree in unit of characters.
* @param width the width of the tree.
* @param height the height of the tree.
*/
public void setSize(int width, int height) {
fWidth = width;
fHeight = height;
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case IDialogConstants.OK_ID: {
okPressed();
break;
}
case IDialogConstants.CANCEL_ID: {
cancelPressed();
break;
}
}
}
/**
* Returns a composite containing the label created at the top of the dialog. Returns null if there is the
* message for the label is null.
*/
protected Label createMessageArea(Composite composite) {
if (getMessage() != null) {
Label label = new Label(composite,SWT.NONE);
label.setText(getMessage());
label.setFont(composite.getFont());
return label;
}
return null;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
GridData gd= null;
layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setFont(parent.getFont());
Label messageLabel = createMessageArea(composite);
if (messageLabel != null) {
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
messageLabel.setLayoutData(gd);
}
Composite inner= new Composite(composite, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns= 2;
innerLayout.marginHeight= 0;
innerLayout.marginWidth= 0;
inner.setLayout(innerLayout);
inner.setFont(parent.getFont());
CheckboxTreeViewer treeViewer= createTreeViewer(inner);
gd= new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(fWidth);
gd.heightHint = convertHeightInCharsToPixels(fHeight);
treeViewer.getControl().setLayoutData(gd);
Composite buttonComposite= createSelectionButtons(inner);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
buttonComposite.setLayoutData(gd);
gd= new GridData(GridData.FILL_BOTH);
inner.setLayoutData(gd);
Composite entryComposite= createEntryPtCombo(composite);
entryComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Composite commentComposite= createCommentSelection(composite);
commentComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
gd= new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gd);
return composite;
}
protected Composite createCommentSelection(Composite composite) {
Composite commentComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
commentComposite.setLayout(layout);
commentComposite.setFont(composite.getFont());
Button commentButton= new Button(commentComposite, SWT.CHECK);
commentButton.setText(fCommentString); //$NON-NLS-1$
commentButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
commentButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean isSelected= (((Button) e.widget).getSelection());
setGenerateComment(isSelected);
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
commentButton.setSelection(getGenerateComment());
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
commentButton.setLayoutData(gd);
return commentComposite;
}
protected Composite createEntryPtCombo(Composite composite) {
Composite selectionComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
selectionComposite.setLayout(layout);
selectionComposite.setFont(composite.getFont());
addOrderEntryChoices(selectionComposite);
return selectionComposite;
}
private Composite addOrderEntryChoices(Composite buttonComposite) {
Label enterLabel= new Label(buttonComposite, SWT.NONE);
enterLabel.setText(ActionMessages.getString("SourceActionDialog.enterAt_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
enterLabel.setLayoutData(gd);
final Combo enterCombo= new Combo(buttonComposite, SWT.READ_ONLY);
fillWithPossibleInsertPositions(enterCombo);
gd= new GridData(GridData.FILL_BOTH);
gd.grabExcessHorizontalSpace= true;
enterCombo.setLayoutData(gd);
enterCombo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
int index= enterCombo.getSelectionIndex();
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getContentProvider().setInsertPosition(index);
setInsertionIndex(index);
}
});
return buttonComposite;
}
private void fillWithPossibleInsertPositions(Combo combo) {
try {
int position= 0;
int presetOffset= 0;
if (fEditor != null) {
presetOffset= ((TextSelection) fEditor.getSelectionProvider().getSelection()).getOffset();
}
else {
List preselected= getInitialElementSelections();
int size= preselected.size();
if ((size > 1) || (size == 0))
presetOffset= 0;
else {
IJavaElement element= (IJavaElement) preselected.get(0);
int type= element.getElementType();
if (type == IJavaElement.FIELD)
presetOffset= ((IField)element).getSourceRange().getOffset();
else if (type == IJavaElement.METHOD)
presetOffset= ((IMethod)element).getSourceRange().getOffset();
}
}
IMethod[] methods= fType.getMethods();
combo.add(ActionMessages.getString("SourceActionDialog.first_method")); //$NON-NLS-1$
combo.add(ActionMessages.getString("SourceActionDialog.last_method")); //$NON-NLS-1$
int bestDiff= Integer.MAX_VALUE;
for (int i= 0; i < methods.length; i++) {
int currDiff= 0;
IMethod curr= methods[i];
combo.add(JavaElementLabels.getElementLabel(methods[i], JavaElementLabels.M_PARAMETER_TYPES));
// calculate method to pre-select
currDiff= presetOffset - curr.getSourceRange().getOffset();
if (currDiff >= 0)
if(currDiff < bestDiff) {
bestDiff= currDiff;
position= i + 2; // first two entries are first/last
}
else
break;
}
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int index= getContentProvider().getInsertPosition();
if ((index == 0) || (index == 1))
combo.select(index);
else
combo.select(position);
setInsertionIndex(combo.getSelectionIndex());
} catch (JavaModelException e) {
}
}
/*
* Determine where in the file to enter the newly created methods.
*/
public IJavaElement getElementPosition() {
int comboBoxIndex= getInsertionIndex();
try {
if (comboBoxIndex == 0) // as first method
return asFirstMethod(fType);
else if (comboBoxIndex == 1) // as last method
return null;
else // method position
return atMethodPosition(fType, comboBoxIndex);
} catch (JavaModelException e) {
return null;
}
}
private IMethod asFirstMethod(IType type) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
if (methods.length > 0) {
return methods[0];
}
}
return null;
}
private IMethod atMethodPosition(IType type, int index) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
if ((index-1) < methods.length) {
return methods[index-1]; // first two entries are first/last
}
}
return null;
}
}
|
38,514 |
Bug 38514 getters/setters dialog: layout [code manipulation]
|
I20030604 label and comboboxes should be aligned horizontally (not vertically) -> more space efficient -> required for accessability?
|
resolved fixed
|
4f7b088
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T12:17:10Z | 2003-06-05T13:33:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/SourceActionDialog.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility.GenStubSettings;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* An advanced version of CheckedTreeSelectionDialog with right-side button layout and
* extra buttons and composites.
*/
public class SourceActionDialog extends CheckedTreeSelectionDialog {
private int fInsertionIndex;
private CompilationUnitEditor fEditor;
private ISourceActionContentProvider fContentProvider;
private boolean fGenerateComment;
private IType fType;
private int fWidth = 60;
private int fHeight = 18;
private String fCommentString;
public SourceActionDialog(Shell parent, ILabelProvider labelProvider, ISourceActionContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider);
fEditor= editor;
fContentProvider= contentProvider;
fType= type;
fCommentString= ActionMessages.getString("SourceActionDialog.createMethodComment"); //$NON-NLS-1$
// Take the default from the default for generating comments from the code gen prefs
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
GenStubSettings genStubSettings= new GenStubSettings(settings);
fGenerateComment= genStubSettings.createComments;
}
public void setCommentString(String string) {
fCommentString= string;
}
protected ISourceActionContentProvider getContentProvider() {
return fContentProvider;
}
public int getInsertionIndex() {
return fInsertionIndex;
}
private void setInsertionIndex(int index) {
fInsertionIndex = index;
}
public boolean getGenerateComment() {
return fGenerateComment;
}
private void setGenerateComment(boolean comment) {
fGenerateComment= comment;
}
/**
* Sets the size of the tree in unit of characters.
* @param width the width of the tree.
* @param height the height of the tree.
*/
public void setSize(int width, int height) {
fWidth = width;
fHeight = height;
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case IDialogConstants.OK_ID: {
okPressed();
break;
}
case IDialogConstants.CANCEL_ID: {
cancelPressed();
break;
}
}
}
/**
* Returns a composite containing the label created at the top of the dialog. Returns null if there is the
* message for the label is null.
*/
protected Label createMessageArea(Composite composite) {
if (getMessage() != null) {
Label label = new Label(composite,SWT.NONE);
label.setText(getMessage());
label.setFont(composite.getFont());
return label;
}
return null;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
GridData gd= null;
layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setFont(parent.getFont());
Label messageLabel = createMessageArea(composite);
if (messageLabel != null) {
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
messageLabel.setLayoutData(gd);
}
Composite inner= new Composite(composite, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns= 2;
innerLayout.marginHeight= 0;
innerLayout.marginWidth= 0;
inner.setLayout(innerLayout);
inner.setFont(parent.getFont());
CheckboxTreeViewer treeViewer= createTreeViewer(inner);
gd= new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(fWidth);
gd.heightHint = convertHeightInCharsToPixels(fHeight);
treeViewer.getControl().setLayoutData(gd);
Composite buttonComposite= createSelectionButtons(inner);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
buttonComposite.setLayoutData(gd);
gd= new GridData(GridData.FILL_BOTH);
inner.setLayoutData(gd);
Composite entryComposite= createEntryPtCombo(composite);
entryComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Composite commentComposite= createCommentSelection(composite);
commentComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
gd= new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gd);
return composite;
}
protected Composite createCommentSelection(Composite composite) {
Composite commentComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
commentComposite.setLayout(layout);
commentComposite.setFont(composite.getFont());
Button commentButton= new Button(commentComposite, SWT.CHECK);
commentButton.setText(fCommentString); //$NON-NLS-1$
commentButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
commentButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean isSelected= (((Button) e.widget).getSelection());
setGenerateComment(isSelected);
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
commentButton.setSelection(getGenerateComment());
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
commentButton.setLayoutData(gd);
return commentComposite;
}
protected Composite createEntryPtCombo(Composite composite) {
Composite selectionComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
selectionComposite.setLayout(layout);
selectionComposite.setFont(composite.getFont());
addOrderEntryChoices(selectionComposite);
return selectionComposite;
}
private Composite addOrderEntryChoices(Composite buttonComposite) {
Label enterLabel= new Label(buttonComposite, SWT.NONE);
enterLabel.setText(ActionMessages.getString("SourceActionDialog.enterAt_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
enterLabel.setLayoutData(gd);
final Combo enterCombo= new Combo(buttonComposite, SWT.READ_ONLY);
fillWithPossibleInsertPositions(enterCombo);
gd= new GridData(GridData.FILL_BOTH);
gd.grabExcessHorizontalSpace= true;
enterCombo.setLayoutData(gd);
enterCombo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
int index= enterCombo.getSelectionIndex();
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getContentProvider().setInsertPosition(index);
setInsertionIndex(index);
}
});
return buttonComposite;
}
private void fillWithPossibleInsertPositions(Combo combo) {
try {
int position= 0;
int presetOffset= 0;
if (fEditor != null) {
presetOffset= ((TextSelection) fEditor.getSelectionProvider().getSelection()).getOffset();
}
else {
List preselected= getInitialElementSelections();
int size= preselected.size();
if ((size > 1) || (size == 0))
presetOffset= 0;
else {
IJavaElement element= (IJavaElement) preselected.get(0);
int type= element.getElementType();
if (type == IJavaElement.FIELD)
presetOffset= ((IField)element).getSourceRange().getOffset();
else if (type == IJavaElement.METHOD)
presetOffset= ((IMethod)element).getSourceRange().getOffset();
}
}
IMethod[] methods= fType.getMethods();
combo.add(ActionMessages.getString("SourceActionDialog.first_method")); //$NON-NLS-1$
combo.add(ActionMessages.getString("SourceActionDialog.last_method")); //$NON-NLS-1$
int bestDiff= Integer.MAX_VALUE;
for (int i= 0; i < methods.length; i++) {
int currDiff= 0;
IMethod curr= methods[i];
combo.add(JavaElementLabels.getElementLabel(methods[i], JavaElementLabels.M_PARAMETER_TYPES));
// calculate method to pre-select
currDiff= presetOffset - curr.getSourceRange().getOffset();
if (currDiff >= 0)
if(currDiff < bestDiff) {
bestDiff= currDiff;
position= i + 2; // first two entries are first/last
}
else
break;
}
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int index= getContentProvider().getInsertPosition();
if ((index == 0) || (index == 1))
combo.select(index);
else
combo.select(position);
setInsertionIndex(combo.getSelectionIndex());
} catch (JavaModelException e) {
}
}
/*
* Determine where in the file to enter the newly created methods.
*/
public IJavaElement getElementPosition() {
int comboBoxIndex= getInsertionIndex();
try {
if (comboBoxIndex == 0) // as first method
return asFirstMethod(fType);
else if (comboBoxIndex == 1) // as last method
return null;
else // method position
return atElementPosition(fType, comboBoxIndex);
} catch (JavaModelException e) {
return null;
}
}
private IMethod asFirstMethod(IType type) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
if (methods.length > 0) {
return methods[0];
}
}
return null;
}
/* Returns the element directly following the method to insert after. Index should never
* always be > 2 since 0 means first method, and 1 means last method.
*/
private IJavaElement atElementPosition(IType type, int index) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
IJavaElement[] elements= type.getChildren();
for (int i= 0; i < (elements.length-1); i++) {
if (methods[index-2] == elements[i]) // first two entries are first/last
return elements[i+1];
}
}
return null;
}
}
|
38,514 |
Bug 38514 getters/setters dialog: layout [code manipulation]
|
I20030604 label and comboboxes should be aligned horizontally (not vertically) -> more space efficient -> required for accessability?
|
resolved fixed
|
4f7b088
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T12:17:10Z | 2003-06-05T13:33:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.ui.JavaElementImageDescriptor;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil;
import org.eclipse.jdt.internal.corext.codemanipulation.IRequestQuery;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.refactoring.IVisibilityChangeListener;
import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* Creates getter and setter methods for a type's fields. Opens a dialog
* with a list of fields for which a setter or getter can be generated.
* User is able to check or uncheck items before setters or getters
* are generated.
* <p>
* Will open the parent compilation unit in a Java editor. The result is
* unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IField</code> or <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class AddGetterSetterAction extends SelectionDispatchAction {
private boolean fSort;
private boolean fSynchronized;
private boolean fFinal;
private int fVisibility;
private boolean fGenerateComment;
private int fNumEntries;
private CompilationUnitEditor fEditor;
private static final String dialogTitle= ActionMessages.getString("AddGetterSetterAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>AddGetterSetterAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddGetterSetterAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddGetterSetterAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddGetterSetterAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddGetterSetterAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.GETTERSETTER_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddGetterSetterAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null);
fEditor.getEditorSite();
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
try {
IField[] selectedFields= getSelectedFields(selection);
if (canRunOn(selectedFields)){
run(selectedFields[0].getDeclaringType(), selectedFields, false);
return;
}
Object firstElement= selection.getFirstElement();
if (firstElement instanceof IType)
run((IType)firstElement, new IField[0], false);
else if (firstElement instanceof ICompilationUnit) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38500
IType type= ((ICompilationUnit) firstElement).findPrimaryType();
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
else
run(((ICompilationUnit) firstElement).findPrimaryType(), new IField[0], false);
}
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if (getSelectedFields(selection) != null)
return true;
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
private static boolean canRunOn(IField[] fields) throws JavaModelException {
return fields != null && fields.length > 0;
}
private void resetNumEntries() {
fNumEntries= 0;
}
private void incNumEntries() {
fNumEntries++;
}
private void run(IType type, IField[] preselected, boolean editor) throws CoreException {
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
if (!ElementValidator.check(type, getShell(), dialogTitle, editor))
return;
if (!ActionUtil.isProcessable(getShell(), type))
return;
ILabelProvider lp= new AddGetterSetterLabelProvider();
resetNumEntries();
Map entries= createGetterSetterMapping(type);
if (entries.isEmpty()){
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGettSetterAction.typeContainsNoFields.message")); //$NON-NLS-1$
return;
}
AddGetterSetterContentProvider cp= new AddGetterSetterContentProvider(entries);
GetterSetterTreeSelectionDialog dialog= new GetterSetterTreeSelectionDialog(getShell(), lp, cp, fEditor, type);
dialog.setSorter(new JavaElementSorter());
dialog.setTitle(dialogTitle);
String message= ActionMessages.getString("AddGetterSetterAction.dialog.label");//$NON-NLS-1$
dialog.setMessage(message);
dialog.setValidator(createValidator(fNumEntries));
dialog.setContainerMode(true);
dialog.setSize(60, 18);
dialog.setInput(type);
if (preselected.length > 0) {
dialog.setInitialSelections(preselected);
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
cp.setPreselected(preselected[0]);
}
int dialogResult= dialog.open();
if (dialogResult == Window.OK) {
Object[] result= dialog.getResult();
if (result == null)
return;
fSort= dialog.getSort();
fSynchronized= dialog.getSynchronized();
fFinal= dialog.getFinal();
fVisibility= dialog.getVisibility();
fGenerateComment= dialog.getGenerateComment();
IField[] getterFields, setterFields, getterSetterFields;
if (fSort) {
getterFields= getGetterFields(result);
setterFields= getSetterFields(result);
getterSetterFields= new IField[0];
}
else {
getterFields= getGetterOnlyFields(result);
setterFields= getSetterOnlyFields(result);
getterSetterFields= getGetterSetterFields(result);
}
IJavaElement elementPosition= dialog.getElementPosition();
generate(getterFields, setterFields, getterSetterFields, elementPosition);
}
}
private static class AddGetterSetterSelectionStatusValidator implements ISelectionStatusValidator {
private static int fEntries;
AddGetterSetterSelectionStatusValidator(int entries) {
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedMethods(selection);
if (count == 0)
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
String message= ActionMessages.getFormattedString("AddGetterSetterAction.methods_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedMethods(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof GetterSetterEntry)
count++;
}
return count;
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddGetterSetterSelectionStatusValidator validator= new AddGetterSetterSelectionStatusValidator(entries);
return validator;
}
// returns a list of fields with setter entries checked
private static IField[] getSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (! entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with getter entries checked
private static IField[] getGetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only getter entires checked
private static IField[] getGetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.remove(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only setter entries checked
private static IField[] getSetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet != true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with both entries checked
private static IField[] getGetterSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
private void generate(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) throws CoreException{
if (getterFields.length == 0 && setterFields.length == 0 && getterSetterFields.length == 0)
return;
ICompilationUnit cu= null;
if (getterFields.length != 0)
cu= getterFields[0].getCompilationUnit();
else if (setterFields.length != 0)
cu= setterFields[0].getCompilationUnit();
else
cu= getterSetterFields[0].getCompilationUnit();
//open the editor, forces the creation of a working copy
IEditorPart editor= EditorUtility.openInEditor(cu);
IField[] workingCopyGetterFields= getWorkingCopyFields(getterFields);
IField[] workingCopySetterFields= getWorkingCopyFields(setterFields);
IField[] workingCopyGetterSetterFields= getWorkingCopyFields(getterSetterFields);
IJavaElement workingCopyElementPosition= getWorkingCopy(elementPosition);
if (workingCopyGetterFields != null && workingCopySetterFields != null && workingCopyGetterSetterFields != null)
run(workingCopyGetterFields, workingCopySetterFields, workingCopyGetterSetterFields, editor, workingCopyElementPosition);
}
private static IJavaElement getWorkingCopy(IJavaElement elementPosition) {
if(elementPosition instanceof IMember)
return JavaModelUtil.toWorkingCopy((IMember)elementPosition);
return elementPosition;
}
private IField[] getWorkingCopyFields(IField[] fields) throws CoreException{
if (fields.length == 0)
return new IField[0];
ICompilationUnit cu= fields[0].getCompilationUnit();
ICompilationUnit workingCopyCU;
IField[] workingCopyFields;
if (cu.isWorkingCopy()) {
workingCopyCU= cu;
workingCopyFields= fields;
} else {
workingCopyCU= EditorUtility.getWorkingCopy(cu);
if (workingCopyCU == null) {
showError(ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
return null;
}
workingCopyFields= new IField[fields.length];
for (int i= 0; i < fields.length; i++) {
IField field= fields[i];
IField workingCopyField= (IField) JavaModelUtil.findMemberInCompilationUnit(workingCopyCU, field);
if (workingCopyField == null) {
showError(ActionMessages.getFormattedString("AddGetterSetterAction.error.fieldNotExisting", field.getElementName())); //$NON-NLS-1$
return null;
}
workingCopyFields[i]= workingCopyField;
}
}
return workingCopyFields;
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
try {
IJavaElement input= SelectionConverter.getInput(fEditor);
if (!ActionUtil.isProcessable(getShell(), input))
return;
IJavaElement[] elements= SelectionConverter.codeResolve(fEditor);
if (elements.length == 1 && (elements[0] instanceof IField)) {
IField field= (IField)elements[0];
run(field.getDeclaringType(), new IField[] {field}, true);
return;
}
IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
if (element != null){
IType type= (IType)element.getAncestor(IJavaElement.TYPE);
if (type != null) {
if (type.getFields().length > 0){
run(type, new IField[0], true);
return;
}
}
}
MessageDialog.openInformation(getShell(), dialogTitle,
ActionMessages.getString("AddGetterSetterAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
//---- Helpers -------------------------------------------------------------------
private void run(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IEditorPart editor, IJavaElement elementPosition) {
IRewriteTarget target= (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
}
try {
AddGetterSetterOperation op= createAddGetterSetterOperation(getterFields, setterFields, getterSetterFields, elementPosition);
setOperationStatusFields(op);
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod[] createdMethods= op.getCreatedAccessors();
if (createdMethods.length > 0) {
EditorUtility.revealInEditor(editor, createdMethods[0]);
}
} catch (InvocationTargetException e) {
String message= ActionMessages.getString("AddGetterSetterAction.error.actionfailed"); //$NON-NLS-1$
ExceptionHandler.handle(e, getShell(), dialogTitle, message);
} catch (InterruptedException e) {
// operation cancelled
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
private void setOperationStatusFields(AddGetterSetterOperation op) {
// Set the status fields corresponding to the visibility and modifiers set
op.setSort(fSort);
op.setVisibility(fVisibility);
op.setSynchronized(fSynchronized);
op.setFinal(fFinal);
}
private AddGetterSetterOperation createAddGetterSetterOperation(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) {
IRequestQuery skipSetterForFinalQuery= skipSetterForFinalQuery();
IRequestQuery skipReplaceQuery= skipReplaceQuery();
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= fGenerateComment;
return new AddGetterSetterOperation(getterFields, setterFields, getterSetterFields, settings, skipSetterForFinalQuery, skipReplaceQuery, elementPosition);
}
private IRequestQuery skipSetterForFinalQuery() {
return new IRequestQuery() {
public int doQuery(IMember field) {
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19367
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.YES_ALL, IRequestQuery.NO, IRequestQuery.CANCEL};
String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
String fieldName= JavaElementLabels.getElementLabel(field, 0);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipSetterForFinalDialog.message", fieldName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private IRequestQuery skipReplaceQuery() {
return new IRequestQuery() {
public int doQuery(IMember method) {
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.NO, IRequestQuery.YES_ALL, IRequestQuery.CANCEL};
String skipLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skip.label"); //$NON-NLS-1$
String replaceLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.replace.label"); //$NON-NLS-1$
String skipAllLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skipAll.label"); //$NON-NLS-1$
String[] options= { skipLabel, replaceLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL};
String methodName= JavaElementLabels.getElementLabel(method, JavaElementLabels.M_PARAMETER_TYPES);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipExistingDialog.message", methodName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) {
final Shell shell= getShell();
if (shell == null) {
JavaPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$
return IRequestQuery.CANCEL;
}
final int[] result= { MessageDialog.CANCEL };
shell.getDisplay().syncExec(new Runnable() {
public void run() {
String title= ActionMessages.getString("AddGetterSetterAction.QueryDialog.title"); //$NON-NLS-1$
MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0);
result[0]= dialog.open();
}
});
int returnVal= result[0];
return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal];
}
private void showError(String message) {
MessageDialog.openError(getShell(), dialogTitle, message);
}
/*
* Returns fields in the selection or <code>null</code> if the selection is
* empty or not valid.
*/
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements= selection.toList();
int nElements= elements.size();
if (nElements > 0) {
IField[] res= new IField[nElements];
ICompilationUnit cu= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (curr instanceof IField) {
IField fld= (IField)curr;
if (i == 0) {
// remember the cu of the first element
cu= fld.getCompilationUnit();
if (cu == null) {
return null;
}
} else if (!cu.equals(fld.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
if (fld.getDeclaringType().isInterface()) {
// no setters/getters for interfaces
return null;
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
return null;
}
res[i]= fld;
} else {
return null;
}
}
return res;
}
return null;
}
private static class AddGetterSetterLabelProvider extends JavaElementLabelProvider {
AddGetterSetterLabelProvider() {
}
/*
* @see ILabelProvider#getText(Object)
*/
public String getText(Object element) {
if (element instanceof GetterSetterEntry) {
GetterSetterEntry entry= (GetterSetterEntry) element;
try {
if (entry.fGetterEntry) {
return GetterSetterUtil.getGetterName(entry.fField, null) + "()"; //$NON-NLS-1$
} else {
return GetterSetterUtil.getSetterName(entry.fField, null) + '(' + Signature.getSimpleName(Signature.toString(entry.fField.getTypeSignature())) + ')';
}
} catch (JavaModelException e) {
return ""; //$NON-NLS-1$
}
}
return super.getText(element);
}
/*
* @see ILabelProvider#getImage(Object)
*/
public Image getImage(Object element) {
if (element instanceof GetterSetterEntry) {
int flags= 0;
try {
flags= ((GetterSetterEntry) element).fField.getFlags();
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
ImageDescriptor desc= JavaElementImageProvider.getFieldImageDescriptor(false, Flags.AccPublic);
int adornmentFlags= Flags.isStatic(flags) ? JavaElementImageDescriptor.STATIC : 0;
desc= new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
return JavaPlugin.getImageDescriptorRegistry().get(desc);
}
return super.getImage(element);
}
}
/**
* @return map IField -> GetterSetterEntry[]
*/
private Map createGetterSetterMapping(IType type) throws JavaModelException{
IField[] fields= type.getFields();
Map result= new HashMap();
for (int i= 0; i < fields.length; i++) {
List l= new ArrayList(2);
if (GetterSetterUtil.getGetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], true));
incNumEntries();
}
if (GetterSetterUtil.getSetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], false));
incNumEntries();
}
if (! l.isEmpty())
result.put(fields[i], (GetterSetterEntry[]) l.toArray(new GetterSetterEntry[l.size()]));
}
return result;
}
private static class AddGetterSetterContentProvider implements ISourceActionContentProvider {
private final String SETTINGS_SECTION= "AddGetterSetterDialog"; //$NON-NLS-1$
private final String VISIBILITY_MODIFIER= "VisibilityModifier"; //$NON-NLS-1$
private final String FINAL_MODIFIER= "FinalModifier"; //$NON-NLS-1$
private final String SYNCHRONIZED_MODIFIER= "SynchronizedModifier"; //$NON-NLS-1$
private final String SORT_ORDER= "SortOrdering"; //$NON-NLS-1$
private static final Object[] EMPTY= new Object[0];
private Viewer fViewer;
private Map fGetterSetterEntries; //IField -> Object[] (with 0 to 2 elements of type GetterSetterEntry)
private IField fPreselected;
private IDialogSettings fSettings;
private int fInsertPosition;
private int fVisibilityModifier;
private boolean fFinal;
private boolean fSynchronized;
private boolean fSortOrder;
public AddGetterSetterContentProvider(Map entries) throws JavaModelException {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
fSettings= dialogSettings.getSection(SETTINGS_SECTION);
if (fSettings == null) {
fSettings= dialogSettings.addNewSection(SETTINGS_SECTION);
fSettings.put(SETTINGS_INSERTPOSITION, 0); //$NON-NLS-1$
fSettings.put(VISIBILITY_MODIFIER, Modifier.PUBLIC); //$NON-NLS-1$
fSettings.put(FINAL_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SYNCHRONIZED_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SORT_ORDER, false); //$NON-NLS-1$
}
fInsertPosition= fSettings.getInt(SETTINGS_INSERTPOSITION);
fVisibilityModifier= fSettings.getInt(VISIBILITY_MODIFIER);
fFinal= fSettings.getBoolean(FINAL_MODIFIER);
fSynchronized= fSettings.getBoolean(SYNCHRONIZED_MODIFIER);
fSortOrder= fSettings.getBoolean(SORT_ORDER);
fGetterSetterEntries= entries;
}
public boolean isFinal() {
return fFinal;
}
/***
* Returns 0 for the first method, 1 for the last method, > 1 for all else.
*/
public int getInsertPosition() {
return fInsertPosition;
}
public boolean isSynchronized() {
return fSynchronized;
}
public int getVisibilityModifier() {
return fVisibilityModifier;
}
public boolean getSortOrder() {
return fSortOrder;
}
/***
* Set insert position valid input is 0 for the first position, 1 for the last position, > 1 for all else.
*/
public void setInsertPosition(int insert) {
if (fInsertPosition != insert) {
fInsertPosition= insert;
fSettings.put(SETTINGS_INSERTPOSITION, insert);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setVisibility(int visibility) {
if (fVisibilityModifier != visibility) {
fVisibilityModifier= visibility;
fSettings.put(VISIBILITY_MODIFIER, visibility);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setFinal(boolean value) {
if (fFinal != value) {
fFinal= value;
fSettings.put(FINAL_MODIFIER, value);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setSynchronized(boolean value) {
if (fSynchronized != value) {
fSynchronized= value;
fSettings.put(SYNCHRONIZED_MODIFIER, value);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setSort(boolean sort) {
if (fSortOrder != sort) {
fSortOrder= sort;
fSettings.put(SORT_ORDER, sort);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public IField getPreselected() {
return fPreselected;
}
public void setPreselected(IField preselected) {
fPreselected= preselected;
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
fViewer= viewer;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IField)
return (Object[])fGetterSetterEntries.get(parentElement);
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
if (element instanceof IMember)
return ((IMember)element).getDeclaringType();
if (element instanceof GetterSetterEntry)
return ((GetterSetterEntry)element).fField;
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fGetterSetterEntries.keySet().toArray();
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
fGetterSetterEntries.clear();
fGetterSetterEntries= null;
}
}
private static class GetterSetterTreeSelectionDialog extends SourceActionDialog {
private int fVisibility;
private boolean fFinal;
private boolean fSynchronized;
private boolean fSort;
private IType fType;
private AddGetterSetterContentProvider fContentProvider;
private static final int SELECT_GETTERS_ID= IDialogConstants.CLIENT_ID + 1;
private static final int SELECT_SETTERS_ID= IDialogConstants.CLIENT_ID + 2;
public GetterSetterTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, AddGetterSetterContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider, editor, type);
fContentProvider= contentProvider;
fSynchronized= fContentProvider.isSynchronized();
fFinal= fContentProvider.isFinal();
fVisibility= fContentProvider.getVisibilityModifier();
fSort= fContentProvider.getSortOrder();
fType= type;
}
public int getVisibility() {
return fVisibility;
}
public boolean getSort() {
return fSort;
}
public boolean getFinal() {
return fFinal;
}
public boolean getSynchronized() {
return fSynchronized;
}
protected void createGetterSetterButtons(Composite buttonComposite) {
createButton(buttonComposite, SELECT_GETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_getters"), false); //$NON-NLS-1$
createButton(buttonComposite, SELECT_SETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_setters"), false); //$NON-NLS-1$
}
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
switch(buttonId) {
case SELECT_GETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(true));
updateOKStatus();
break;
}
case SELECT_SETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(false));
updateOKStatus();
break;
}
}
}
protected Composite createEntryPtCombo(Composite composite) {
Composite entryComposite= super.createEntryPtCombo(composite);
entryComposite= addSortOrder(entryComposite);
entryComposite= addVisibilityAndModifiersChoices(entryComposite);
return entryComposite;
}
private Composite addSortOrder(Composite composite) {
Label label= new Label(composite, SWT.NONE);
label.setText(ActionMessages.getString("GetterSetterTreeSelectionDialog.sort_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
label.setLayoutData(gd);
final Combo combo= new Combo(composite, SWT.READ_ONLY);
combo.setItems(new String[]{ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_pair_sort"), //$NON-NLS-1$
ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_method_sort")}); //$NON-NLS-1$
final int methodIndex= 1; // Hard-coded. Change this if the list gets more complicated.
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int sort= fContentProvider.getSortOrder() ? 1 : 0;
combo.setText(combo.getItem(sort));
gd= new GridData(GridData.FILL_BOTH);
gd.grabExcessHorizontalSpace= true;
combo.setLayoutData(gd);
combo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
fSort= (combo.getSelectionIndex() == methodIndex);
fContentProvider.setSort(fSort);
}
});
return composite;
}
private Composite addVisibilityAndModifiersChoices(Composite buttonComposite) {
// Add visibility and modifiers buttons: http://bugs.eclipse.org/bugs/show_bug.cgi?id=35870
// Add persistence of options: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
IVisibilityChangeListener visibilityChangeListener = new IVisibilityChangeListener(){
public void visibilityChanged(int newVisibility) {
fVisibility= newVisibility;
fContentProvider.setVisibility(fVisibility);
}
public void modifierChanged(int modifier, boolean isChecked) {
switch (modifier) {
case Modifier.FINAL: {
fFinal= isChecked;
fContentProvider.setFinal(fFinal) ;
return;
}
case Modifier.SYNCHRONIZED: {
fSynchronized= isChecked;
fContentProvider.setSynchronized(fSynchronized);
return;
}
default: return;
}
}
};
int initialVisibility= fContentProvider.getVisibilityModifier();
int[] availableVisibilities= new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE, Modifier.NONE};
Composite visibilityComposite= createVisibilityControlAndModifiers(buttonComposite, visibilityChangeListener, availableVisibilities, initialVisibility);
return visibilityComposite;
}
private List convertToIntegerList(int[] array) {
List result= new ArrayList(array.length);
for (int i= 0; i < array.length; i++) {
result.add(new Integer(array[i]));
}
return result;
}
private Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
List allowedVisibilities= convertToIntegerList(availableVisibilities);
if (allowedVisibilities.size() == 1)
return null;
Group group= new Group(parent, SWT.NONE);
group.setText(RefactoringMessages.getString("VisibilityControlUtil.Access_modifier")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_HORIZONTAL);
group.setLayoutData(gd);
GridLayout layout= new GridLayout();
layout.makeColumnsEqualWidth= true;
layout.numColumns= 4;
group.setLayout(layout);
String[] labels= new String[] {
"&public", //$NON-NLS-1$
"pro&tected", //$NON-NLS-1$
RefactoringMessages.getString("VisibilityControlUtil.defa&ult_4"), //$NON-NLS-1$
"pri&vate" //$NON-NLS-1$
};
Integer[] data= new Integer[] {
new Integer(Modifier.PUBLIC),
new Integer(Modifier.PROTECTED),
new Integer(Modifier.NONE),
new Integer(Modifier.PRIVATE)};
Integer initialVisibility= new Integer(correctVisibility);
for (int i= 0; i < labels.length; i++) {
Button radio= new Button(group, SWT.RADIO);
Integer visibilityCode= data[i];
radio.setText(labels[i]);
radio.setData(visibilityCode);
radio.setSelection(visibilityCode.equals(initialVisibility));
radio.setEnabled(allowedVisibilities.contains(visibilityCode));
radio.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.visibilityChanged(((Integer)event.widget.getData()).intValue());
}
});
}
group.setLayoutData((new GridData(GridData.FILL_HORIZONTAL)));
return group;
}
private Composite createVisibilityControlAndModifiers(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
Composite visibilityComposite= createVisibilityControl(parent, visibilityChangeListener, availableVisibilities, correctVisibility);
Button finalCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
finalCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.final")); //$NON-NLS-1$
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
finalCheckboxButton.setLayoutData(gd);
finalCheckboxButton.setData(new Integer(Modifier.FINAL));
finalCheckboxButton.setEnabled(true);
finalCheckboxButton.setSelection(fContentProvider.isFinal());
finalCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
Button syncCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
syncCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.synchronized")); //$NON-NLS-1$
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
syncCheckboxButton.setLayoutData(gd);
syncCheckboxButton.setData(new Integer(Modifier.SYNCHRONIZED));
syncCheckboxButton.setEnabled(true);
syncCheckboxButton.setSelection(fContentProvider.isSynchronized());
syncCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
return visibilityComposite;
}
private Object[] getGetterSetterElements(boolean isGetter){
Object[] allFields= fContentProvider.getElements(null);
Set result= new HashSet();
for (int i = 0; i < allFields.length; i++) {
IField field= (IField)allFields[i];
GetterSetterEntry[] entries= getEntries(field);
for (int j = 0; j < entries.length; j++) {
AddGetterSetterAction.GetterSetterEntry entry= entries[j];
if (entry.fGetterEntry == isGetter)
result.add(entry);
}
}
return result.toArray();
}
private GetterSetterEntry[] getEntries(IField field) {
List result= Arrays.asList(fContentProvider.getChildren(field));
return (GetterSetterEntry[]) result.toArray(new GetterSetterEntry[result.size()]);
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
createGetterSetterButtons(buttonComposite);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
Control control= super.createDialogArea(parent);
try {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getTreeViewer().setExpandedElements(fType.getFields());
getTreeViewer().reveal(fContentProvider.getPreselected());
getTreeViewer().refresh();
} catch (JavaModelException e) {
}
return control;
}
}
private static class GetterSetterEntry {
public final IField fField;
public final boolean fGetterEntry;
GetterSetterEntry(IField field, boolean isGetterEntry){
fField= field;
fGetterEntry= isGetterEntry;
}
}
}
|
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
org.eclipse.jdt.ui/core
| |
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/AddGetterSetterOperation.java
| |
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
org.eclipse.jdt.ui/core
| |
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/CodeGenerationSettings.java
| |
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaPreferencesSettings.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
import java.util.StringTokenizer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
public class JavaPreferencesSettings {
public static CodeGenerationSettings getCodeGenerationSettings() {
IPreferenceStore store= PreferenceConstants.getPreferenceStore();
CodeGenerationSettings res= new CodeGenerationSettings();
res.createComments= store.getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS);
res.importOrder= getImportOrderPreference(store);
res.importThreshold= getImportNumberThreshold(store);
res.tabWidth= JavaCore.getPlugin().getPluginPreferences().getInt(JavaCore.FORMATTER_TAB_SIZE);
return res;
}
public static int getImportNumberThreshold(IPreferenceStore prefs) {
int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD);
if (threshold < 0) {
threshold= Integer.MAX_VALUE;
}
return threshold;
}
public static String[] getImportOrderPreference(IPreferenceStore prefs) {
String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER);
if (str != null) {
return unpackList(str, ";"); //$NON-NLS-1$
}
return new String[0];
}
private static String[] unpackList(String str, String separator) {
StringTokenizer tok= new StringTokenizer(str, separator); //$NON-NLS-1$
int nTokens= tok.countTokens();
String[] res= new String[nTokens];
for (int i= 0; i < nTokens; i++) {
res[i]= tok.nextToken().trim();
}
return res;
}
}
|
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/NameConventionConfigurationBlock.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.JavaElementImageDescriptor;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.dialogs.StatusDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.jdt.internal.ui.util.SWTUtil;
import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
/*
* The page to configure name conventions
*/
public class NameConventionConfigurationBlock extends OptionsConfigurationBlock {
private final static int FIELD= 1;
private final static int STATIC= 2;
private final static int ARGUMENT= 3;
private final static int LOCAL= 4;
// Preference store keys, see JavaCore.getOptions
private static final String PREF_FIELD_PREFIXES= JavaCore.CODEASSIST_FIELD_PREFIXES;
private static final String PREF_FIELD_SUFFIXES= JavaCore.CODEASSIST_FIELD_SUFFIXES;
private static final String PREF_STATIC_FIELD_PREFIXES= JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES;
private static final String PREF_STATIC_FIELD_SUFFIXES= JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES;
private static final String PREF_ARGUMENT_PREFIXES= JavaCore.CODEASSIST_ARGUMENT_PREFIXES;
private static final String PREF_ARGUMENT_SUFFIXES= JavaCore.CODEASSIST_ARGUMENT_SUFFIXES;
private static final String PREF_LOCAL_PREFIXES= JavaCore.CODEASSIST_LOCAL_PREFIXES;
private static final String PREF_LOCAL_SUFFIXES= JavaCore.CODEASSIST_LOCAL_SUFFIXES;
private static class NameConventionEntry {
public int kind;
public String prefix;
public String suffix;
public String prefixkey;
public String suffixkey;
}
private class NameConventionInputDialog extends StatusDialog implements IDialogFieldListener {
private StringDialogField fPrefixField;
private StringDialogField fSuffixField;
private NameConventionEntry fEntry;
private DialogField fMessageField;
public NameConventionInputDialog(Shell parent, String title, String message, NameConventionEntry entry) {
super(parent);
fEntry= entry;
setTitle(title);
fMessageField= new DialogField();
fMessageField.setLabelText(message);
fPrefixField= new StringDialogField();
fPrefixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.prefix")); //$NON-NLS-1$
fPrefixField.setDialogFieldListener(this);
fSuffixField= new StringDialogField();
fSuffixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.suffix")); //$NON-NLS-1$
fSuffixField.setDialogFieldListener(this);
fPrefixField.setText(entry.prefix);
fSuffixField.setText(entry.suffix);
}
public NameConventionEntry getResult() {
NameConventionEntry res= new NameConventionEntry();
res.prefix= fPrefixField.getText();
res.suffix= fSuffixField.getText();
res.prefixkey= fEntry.prefixkey;
res.suffixkey= fEntry.suffixkey;
res.kind= fEntry.kind;
return res;
}
protected Control createDialogArea(Composite parent) {
Composite composite= (Composite) super.createDialogArea(parent);
Composite inner= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 2;
inner.setLayout(layout);
fMessageField.doFillIntoGrid(inner, 2);
fPrefixField.doFillIntoGrid(inner, 2);
fSuffixField.doFillIntoGrid(inner, 2);
LayoutUtil.setHorizontalGrabbing(fPrefixField.getTextControl(null));
LayoutUtil.setWidthHint(fPrefixField.getTextControl(null), convertWidthInCharsToPixels(45));
LayoutUtil.setWidthHint(fSuffixField.getTextControl(null), convertWidthInCharsToPixels(45));
fPrefixField.postSetFocusOnDialogField(parent.getDisplay());
applyDialogFont(composite);
return composite;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
*/
public void dialogFieldChanged(DialogField field) {
// validate
IStatus prefixStatus= validateIdentifiers(getTokens(fPrefixField.getText(), ","), true); //$NON-NLS-1$
IStatus suffixStatus= validateIdentifiers(getTokens(fSuffixField.getText(), ","), false); //$NON-NLS-1$
updateStatus(StatusUtil.getMoreSevere(suffixStatus, prefixStatus));
}
private IStatus validateIdentifiers(String[] values, boolean prefix) {
for (int i= 0; i < values.length; i++) {
String val= values[i];
if (val.length() == 0) {
if (prefix) {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptyprefix")); //$NON-NLS-1$
} else {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptysuffix")); //$NON-NLS-1$
}
}
String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
IStatus status= JavaConventions.validateFieldName(name);
if (status.matches(IStatus.ERROR)) {
if (prefix) {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidprefix", val)); //$NON-NLS-1$
} else {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidsuffix", val)); //$NON-NLS-1$
}
}
}
return new StatusInfo();
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
//WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.IMPORT_ORGANIZE_INPUT_DIALOG);
}
}
private static class NameConventionLabelProvider extends LabelProvider implements ITableLabelProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
return getColumnImage(element, 0);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
return getColumnText(element, 0);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
*/
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex != 0) {
return null;
}
NameConventionEntry entry= (NameConventionEntry) element;
ImageDescriptorRegistry registry= JavaPlugin.getImageDescriptorRegistry();
switch (entry.kind) {
case FIELD:
return registry.get(JavaPluginImages.DESC_FIELD_PUBLIC);
case STATIC:
return registry.get(new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE));
case ARGUMENT:
return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
default:
return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object element, int columnIndex) {
NameConventionEntry entry= (NameConventionEntry) element;
if (columnIndex == 0) {
switch (entry.kind) {
case FIELD:
return PreferencesMessages.getString("NameConventionConfigurationBlock.field.label"); //$NON-NLS-1$
case STATIC:
return PreferencesMessages.getString("NameConventionConfigurationBlock.static.label"); //$NON-NLS-1$
case ARGUMENT:
return PreferencesMessages.getString("NameConventionConfigurationBlock.arg.label"); //$NON-NLS-1$
default:
return PreferencesMessages.getString("NameConventionConfigurationBlock.local.label"); //$NON-NLS-1$
}
} else if (columnIndex == 1) {
return entry.prefix;
} else {
return entry.suffix;
}
}
}
private class NameConventionAdapter implements IListAdapter, IDialogFieldListener {
private boolean canEdit(ListDialogField field) {
return field.getSelectedElements().size() == 1;
}
public void customButtonPressed(ListDialogField field, int index) {
doEditButtonPressed(index);
}
public void selectionChanged(ListDialogField field) {
field.enableButton(0, canEdit(field));
}
public void doubleClicked(ListDialogField field) {
if (canEdit(field)) {
doEditButtonPressed(0);
}
}
public void dialogFieldChanged(DialogField field) {
validateSettings(null, null);
}
}
private ListDialogField fNameConventionList;
public NameConventionConfigurationBlock(IStatusChangeListener context, IJavaProject project) {
super(context, project);
NameConventionAdapter adapter= new NameConventionAdapter();
String[] buttons= new String[] {
/* 0 */ PreferencesMessages.getString("NameConventionConfigurationBlock.list.edit.button") //$NON-NLS-1$
};
fNameConventionList= new ListDialogField(adapter, buttons, new NameConventionLabelProvider());
fNameConventionList.setDialogFieldListener(adapter);
fNameConventionList.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.list.label")); //$NON-NLS-1$
String[] columnsHeaders= new String[] {
PreferencesMessages.getString("NameConventionConfigurationBlock.list.name.column"), //$NON-NLS-1$
PreferencesMessages.getString("NameConventionConfigurationBlock.list.prefix.column"), //$NON-NLS-1$
PreferencesMessages.getString("NameConventionConfigurationBlock.list.suffix.column"), //$NON-NLS-1$
};
ColumnLayoutData[] data= new ColumnLayoutData[] {
new ColumnWeightData(3),
new ColumnWeightData(2),
new ColumnWeightData(2)
};
fNameConventionList.setTableColumns(new ListDialogField.ColumnsDescription(data, columnsHeaders, true));
unpackEntries();
if (fNameConventionList.getSize() > 0) {
fNameConventionList.selectFirstElement();
} else {
fNameConventionList.enableButton(0, false);
}
}
protected String[] getAllKeys() {
return new String[] {
PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES,
PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES
};
}
protected Control createContents(Composite parent) {
setShell(parent.getShell());
GridLayout layout= new GridLayout();
layout.numColumns= 2;
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayout(layout);
fNameConventionList.doFillIntoGrid(composite, 3);
LayoutUtil.setHorizontalSpan(fNameConventionList.getLabelControl(null), 2);
Table table= fNameConventionList.getTableViewer().getTable();
GridData data= (GridData)fNameConventionList.getListControl(null).getLayoutData();
data.grabExcessHorizontalSpace= true;
data.verticalAlignment= 0;
data.heightHint= SWTUtil.getTableHeightHint(table, 5);
return composite;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String, java.lang.String)
*/
protected void validateSettings(String changedKey, String newValue) {
// no validation
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateControls()
*/
protected void updateControls() {
unpackEntries();
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
*/
protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
return null; // no build required
}
private void createEntry(List list, String prefixKey, String suffixKey, int kind) {
NameConventionEntry entry= new NameConventionEntry();
entry.kind= kind;
entry.suffixkey= suffixKey;
entry.prefixkey= prefixKey;
entry.suffix= (String) fWorkingValues.get(suffixKey);
entry.prefix= (String) fWorkingValues.get(prefixKey);
list.add(entry);
}
private void unpackEntries() {
ArrayList list= new ArrayList(4);
createEntry(list, PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, FIELD);
createEntry(list, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES, STATIC);
createEntry(list, PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, ARGUMENT);
createEntry(list, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES, LOCAL);
fNameConventionList.setElements(list);
}
private void packEntries() {
for (int i= 0; i < fNameConventionList.getSize(); i++) {
NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getElement(i);
fWorkingValues.put(entry.suffixkey, entry.suffix);
fWorkingValues.put(entry.prefixkey, entry.prefix);
}
}
private void doEditButtonPressed(int index) {
NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getSelectedElements().get(0);
String title;
String message;
switch (entry.kind) {
case FIELD:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.message"); //$NON-NLS-1$
break;
case STATIC:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.message"); //$NON-NLS-1$
break;
case ARGUMENT:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.message"); //$NON-NLS-1$
break;
default:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.message"); //$NON-NLS-1$
}
NameConventionInputDialog dialog= new NameConventionInputDialog(getShell(), title, message, entry);
if (dialog.open() == TodoTaskInputDialog.OK) {
fNameConventionList.replaceElement(entry, dialog.getResult());
}
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk(boolean)
*/
public boolean performOk(boolean enabled) {
packEntries();
return super.performOk(enabled);
}
}
|
38,879 |
Bug 38879 Getter/setter code gen
|
Build 3.0-M1 Amongst the options offered to generate code should figure one allowing non- static field accesses to be qualified with 'this'. We (jdt/core) use this convention instead of 'f' prefixes.
|
resolved fixed
|
7a5c342
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-18T15:40:27Z | 2003-06-13T10:26:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.text.IJavaColorConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
/**
* Preference constants used in the JDT-UI preference store. Clients should only read the
* JDT-UI preference store using these values. Clients are not allowed to modify the
* preference store programmatically.
*
* @since 2.0
*/
public class PreferenceConstants {
private PreferenceConstants() {
}
/**
* A named preference that controls return type rendering of methods in the UI.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> return types
* are rendered
* </p>
*/
public static final String APPEARANCE_METHOD_RETURNTYPE= "org.eclipse.jdt.ui.methodreturntype";//$NON-NLS-1$
/**
* A named preference that controls if override indicators are rendered in the UI.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> override
* indicators are rendered
* </p>
*/
public static final String APPEARANCE_OVERRIDE_INDICATOR= "org.eclipse.jdt.ui.overrideindicator";//$NON-NLS-1$
/**
* A named preference that defines the pattern used for package name compression.
* <p>
* Value is of type <code>String</code>. For example foe the given package name 'org.eclipse.jdt' pattern
* '.' will compress it to '..jdt', '1~' to 'o~.e~.jdt'.
* </p>
*/
public static final String APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW= "PackagesView.pkgNamePatternForPackagesView";//$NON-NLS-1$
/**
* A named preference that controls if package name compression is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @see #APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW
*/
public static final String APPEARANCE_COMPRESS_PACKAGE_NAMES= "org.eclipse.jdt.ui.compresspackagenames";//$NON-NLS-1$
/**
* A named preference that controls if empty inner packages are folded in
* the hierarchical mode of the package explorer.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> empty
* inner packages are folded.
* </p>
* @since 2.1
*/
public static final String APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER= "org.eclipse.jdt.ui.flatPackagesInPackageExplorer";//$NON-NLS-1$
/**
* A named preference that defines how member elements are ordered by the
* Java views using the <code>JavaElementSorter</code>.
* <p>
* Value is of type <code>String</code>: A comma separated list of the
* following entries. Each entry must be in the list, no duplication. List
* order defines the sort order.
* <ul>
* <li><b>T</b>: Types</li>
* <li><b>C</b>: Constructors</li>
* <li><b>I</b>: Initializers</li>
* <li><b>M</b>: Methods</li>
* <li><b>F</b>: Fields</li>
* <li><b>SI</b>: Static Initializers</li>
* <li><b>SM</b>: Static Methods</li>
* <li><b>SF</b>: Static Fields</li>
* </ul>
* </p>
* @since 2.1
*/
public static final String APPEARANCE_MEMBER_SORT_ORDER= "outlinesortoption"; //$NON-NLS-1$
/**
* A named preference that controls if prefix removal during setter/getter generation is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_USE_GETTERSETTER_PREFIX= "org.eclipse.jdt.ui.gettersetter.prefix.enable";//$NON-NLS-1$
/**
* A named preference that holds a list of prefixes to be removed from a local variable to compute setter
* and gettter names.
* <p>
* Value is of type <code>String</code>: comma separated list of prefixed
* </p>
*
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_GETTERSETTER_PREFIX= "org.eclipse.jdt.ui.gettersetter.prefix.list";//$NON-NLS-1$
/**
* A named preference that controls if suffix removal during setter/getter generation is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_USE_GETTERSETTER_SUFFIX= "org.eclipse.jdt.ui.gettersetter.suffix.enable";//$NON-NLS-1$
/**
* A named preference that holds a list of suffixes to be removed from a local variable to compute setter
* and getter names.
* <p>
* Value is of type <code>String</code>: comma separated list of suffixes
* </p>
* @deprecated Use setting from JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_SUFFIXES and CODEASSIST_STATIC_FIELD_SUFFIXES)
*/
public static final String CODEGEN_GETTERSETTER_SUFFIX= "org.eclipse.jdt.ui.gettersetter.suffix.list"; //$NON-NLS-1$
/**
* A named preference that controls if comment stubs will be added
* automatically to newly created types and methods.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String CODEGEN_ADD_COMMENTS= "org.eclipse.jdt.ui.javadoc"; //$NON-NLS-1$
/**
* A named preference that controls if a comment stubs will be added
* automatocally to newly created types and methods.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use CODEGEN_ADD_COMMENTS instead (Name is more precice).
*/
public static final String CODEGEN__JAVADOC_STUBS= CODEGEN_ADD_COMMENTS;
/**
* A named preference that controls if a non-javadoc comment gets added to methods generated via the
* "Override Methods" operation.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated New code template story: user can
* specify the overriding method comment.
*/
public static final String CODEGEN__NON_JAVADOC_COMMENTS= "org.eclipse.jdt.ui.seecomments"; //$NON-NLS-1$
/**
* A named preference that controls if a file comment gets added to newly created files.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated New code template story: user can
* specify the new type code template.
*/
public static final String CODEGEN__FILE_COMMENTS= "org.eclipse.jdt.ui.filecomments"; //$NON-NLS-1$
/**
* A named preference that holds a list of comma separated package names. The list specifies the import order used by
* the "Organize Imports" opeation.
* <p>
* Value is of type <code>String</code>: semicolon separated list of package
* names
* </p>
*/
public static final String ORGIMPORTS_IMPORTORDER= "org.eclipse.jdt.ui.importorder"; //$NON-NLS-1$
/**
* A named preference that specifies the number of imports added before a star-import declaration is used.
* <p>
* Value is of type <code>Int</code>: positive value specifing the number of non star-import is used
* </p>
*/
public static final String ORGIMPORTS_ONDEMANDTHRESHOLD= "org.eclipse.jdt.ui.ondemandthreshold"; //$NON-NLS-1$
/**
* A named preferences that controls if types that start with a lower case letters get added by the
* "Organize Import" operation.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String ORGIMPORTS_IGNORELOWERCASE= "org.eclipse.jdt.ui.ignorelowercasenames"; //$NON-NLS-1$
/**
* A named preference that speficies whether children of a compilation unit are shown in the package explorer.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String SHOW_CU_CHILDREN= "org.eclipse.jdt.ui.packages.cuchildren"; //$NON-NLS-1$
/**
* A named preference that controls whether the package explorer's selection is linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String LINK_PACKAGES_TO_EDITOR= "org.eclipse.jdt.ui.packages.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the hierarchy view's selection is linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String LINK_TYPEHIERARCHY_TO_EDITOR= "org.eclipse.jdt.ui.packages.linktypehierarchytoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the projects view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_PROJECTS_TO_EDITOR= "org.eclipse.jdt.ui.browsing.projectstoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the packages view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_PACKAGES_TO_EDITOR= "org.eclipse.jdt.ui.browsing.packagestoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the types view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_TYPES_TO_EDITOR= "org.eclipse.jdt.ui.browsing.typestoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the members view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_MEMBERS_TO_EDITOR= "org.eclipse.jdt.ui.browsing.memberstoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether new projects are generated using source and output folder.
* <p>
* Value is of type <code>Boolean</code>. if <code>true</code> new projects are created with a source and
* output folder. If <code>false</code> source and output folder equals to the project.
* </p>
*/
public static final String SRCBIN_FOLDERS_IN_NEWPROJ= "org.eclipse.jdt.ui.wizards.srcBinFoldersInNewProjects"; //$NON-NLS-1$
/**
* A named preference that specifies the source folder name used when creating a new Java project. Value is inactive
* if <code>SRCBIN_FOLDERS_IN_NEWPROJ</code> is set to <code>false</code>.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #SRCBIN_FOLDERS_IN_NEWPROJ
*/
public static final String SRCBIN_SRCNAME= "org.eclipse.jdt.ui.wizards.srcBinFoldersSrcName"; //$NON-NLS-1$
/**
* A named preference that specifies the output folder name used when creating a new Java project. Value is inactive
* if <code>SRCBIN_FOLDERS_IN_NEWPROJ</code> is set to <code>false</code>.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #SRCBIN_FOLDERS_IN_NEWPROJ
*/
public static final String SRCBIN_BINNAME= "org.eclipse.jdt.ui.wizards.srcBinFoldersBinName"; //$NON-NLS-1$
/**
* A named preference that holds a list of possible JRE libraries used by the New Java Project wizard. An library
* consists of a description and an arbitrary number of <code>IClasspathEntry</code>s, that will represent the
* JRE on the new project's classpath.
* <p>
* Value is of type <code>String</code>: a semicolon separated list of encoded JRE libraries.
* <code>NEWPROJECT_JRELIBRARY_INDEX</code> defines the currently used library. Clients
* should use the method <code>encodeJRELibrary</code> to encode a JRE library into a string
* and the methods <code>decodeJRELibraryDescription(String)</code> and <code>
* decodeJRELibraryClasspathEntries(String)</code> to decode the description and the array
* of classpath entries from an encoded string.
* </p>
*
* @see #NEWPROJECT_JRELIBRARY_INDEX
* @see #encodeJRELibrary(String, IClasspathEntry[])
* @see #decodeJRELibraryDescription(String)
* @see #decodeJRELibraryClasspathEntries(String)
*/
public static final String NEWPROJECT_JRELIBRARY_LIST= "org.eclipse.jdt.ui.wizards.jre.list"; //$NON-NLS-1$
/**
* A named preferences that specifies the current active JRE library.
* <p>
* Value is of type <code>Int</code>: an index into the list of possible JRE libraries.
* </p>
*
* @see #NEWPROJECT_JRELIBRARY_LIST
*/
public static final String NEWPROJECT_JRELIBRARY_INDEX= "org.eclipse.jdt.ui.wizards.jre.index"; //$NON-NLS-1$
/**
* A named preference that controls if a new type hierarchy gets opened in a
* new type hierarchy perspective or inside the type hierarchy view part.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE</code> or <code>
* OPEN_TYPE_HIERARCHY_IN_VIEW_PART</code>.
* </p>
*
* @see #OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE
* @see #OPEN_TYPE_HIERARCHY_IN_VIEW_PART
*/
public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.jdt.ui.openTypeHierarchy"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>OPEN_TYPE_HIERARCHY</code>.
*
* @see #OPEN_TYPE_HIERARCHY
*/
public static final String OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE= "perspective"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>OPEN_TYPE_HIERARCHY</code>.
*
* @see #OPEN_TYPE_HIERARCHY
*/
public static final String OPEN_TYPE_HIERARCHY_IN_VIEW_PART= "viewPart"; //$NON-NLS-1$
/**
* A named preference that controls the behaviour when double clicking on a container in the packages view.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* DOUBLE_CLICK_GOES_INTO</code> or <code>
* DOUBLE_CLICK_EXPANDS</code>.
* </p>
*
* @see #DOUBLE_CLICK_EXPANDS
* @see #DOUBLE_CLICK_GOES_INTO
*/
public static final String DOUBLE_CLICK= "packageview.doubleclick"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>DOUBLE_CLICK</code>.
*
* @see #DOUBLE_CLICK
*/
public static final String DOUBLE_CLICK_GOES_INTO= "packageview.gointo"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>DOUBLE_CLICK</code>.
*
* @see #DOUBLE_CLICK
*/
public static final String DOUBLE_CLICK_EXPANDS= "packageview.doubleclick.expands"; //$NON-NLS-1$
/**
* A named preference that controls whether Java views update their presentation while editing or when saving the
* content of an editor.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* UPDATE_ON_SAVE</code> or <code>
* UPDATE_WHILE_EDITING</code>.
* </p>
*
* @see #UPDATE_ON_SAVE
* @see #UPDATE_WHILE_EDITING
*/
public static final String UPDATE_JAVA_VIEWS= "JavaUI.update"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>UPDATE_JAVA_VIEWS</code>
*
* @see #UPDATE_JAVA_VIEWS
*/
public static final String UPDATE_ON_SAVE= "JavaUI.update.onSave"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>UPDATE_JAVA_VIEWS</code>
*
* @see #UPDATE_JAVA_VIEWS
*/
public static final String UPDATE_WHILE_EDITING= "JavaUI.update.whileEditing"; //$NON-NLS-1$
/**
* A named preference that holds the path of the Javadoc command used by the Javadoc creation wizard.
* <p>
* Value is of type <code>String</code>.
* </p>
*/
public static final String JAVADOC_COMMAND= "command"; //$NON-NLS-1$
/**
* A named preference that defines the key for the hover modifiers.
*
* @see JavaUI
* @since 2.1
*/
public static final String EDITOR_TEXT_HOVER_MODIFIERS= "hoverModifiers"; //$NON-NLS-1$
/**
* A named preference that defines the key for the hover modifier state masks.
* The value is only used if the value of <code>EDITOR_TEXT_HOVER_MODIFIERS</code>
* cannot be resolved to valid SWT modifier bits.
*
* @see JavaUI
* @see #EDITOR_TEXT_HOVER_MODIFIERS
* @since 2.1.1
*/
public static final String EDITOR_TEXT_HOVER_MODIFIER_MASKS= "hoverModifierMasks"; //$NON-NLS-1$
/**
* The id of the best match hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_BESTMATCH_HOVER= "org.eclipse.jdt.ui.BestMatchHover"; //$NON-NLS-1$
/**
* The id of the source code hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_SOURCE_HOVER= "org.eclipse.jdt.ui.JavaSourceHover"; //$NON-NLS-1$
/**
* The id of the javadoc hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_JAVADOC_HOVER= "org.eclipse.jdt.ui.JavadocHover"; //$NON-NLS-1$
/**
* The id of the problem hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_PROBLEM_HOVER= "org.eclipse.jdt.ui.ProblemHover"; //$NON-NLS-1$
/**
* A named preference that controls whether bracket matching highlighting is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_MATCHING_BRACKETS= "matchingBrackets"; //$NON-NLS-1$
/**
* A named preference that holds the color used to highlight matching brackets.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_MATCHING_BRACKETS_COLOR= "matchingBracketsColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the current line highlighting is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_CURRENT_LINE= "currentLine"; //$NON-NLS-1$
/**
* A named preference that holds the color used to highlight the current line.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_CURRENT_LINE_COLOR= "currentLineColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the print margin is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_PRINT_MARGIN= "printMargin"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render the print margin.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_PRINT_MARGIN_COLOR= "printMarginColor"; //$NON-NLS-1$
/**
* Print margin column. Int value.
*/
public final static String EDITOR_PRINT_MARGIN_COLUMN= "printMarginColumn"; //$NON-NLS-1$
/**
* A named preference that holds the color used for the find/replace scope.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_FIND_SCOPE_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FIND_SCOPE;
/**
* A named preference that specifies if the editor uses spaces for tabs.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code>spaces instead of tabs are used
* in the editor. If <code>false</code> the editor inserts a tab character when pressing the tab
* key.
* </p>
*/
public final static String EDITOR_SPACES_FOR_TABS= "spacesForTabs"; //$NON-NLS-1$
/**
* A named preference that holds the number of spaces used per tab in the editor.
* <p>
* Value is of type <code>Int</code>: positive int value specifying the number of
* spaces per tab.
* </p>
*/
public final static String EDITOR_TAB_WIDTH= "org.eclipse.jdt.ui.editor.tab.width"; //$NON-NLS-1$
/**
* A named preference that controls whether the outline view selection
* should stay in sync with with the element at the current cursor position.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE= "JavaEditor.SyncOutlineOnCursorMove"; //$NON-NLS-1$
/**
* A named preference that controls if correction indicators are shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_CORRECTION_INDICATION= "JavaEditor.ShowTemporaryProblem"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows problem indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_PROBLEM_INDICATION= "problemIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render problem indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_PROBLEM_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_PROBLEM_INDICATION_COLOR= "problemIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows warning indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION= "warningIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render warning indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_WARNING_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION_COLOR= "warningIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows task indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION= "taskIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render task indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_TASK_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION_COLOR= "taskIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows bookmark
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION= "bookmarkIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render bookmark indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_BOOKMARK_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION_COLOR= "bookmarkIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows search
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION= "searchResultIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render search indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_SEARCH_RESULT_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION_COLOR= "searchResultIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows unknown
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION= "othersIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render unknown
* indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_UNKNOWN_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION_COLOR= "othersIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows error
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER= "errorIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows warning
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER= "warningIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows task
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER= "taskIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* bookmark indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER= "bookmarkIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* search result indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER= "searchResultIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* unknown indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER= "othersIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close strings' feature
* is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_STRINGS= "closeStrings"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'wrap strings' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WRAP_STRINGS= "wrapStrings"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close brackets' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_BRACKETS= "closeBrackets"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close braces' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_BRACES= "closeBraces"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close java docs' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_JAVADOCS= "closeJavaDocs"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'add JavaDoc tags' feature
* is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_ADD_JAVADOC_TAGS= "addJavaDocTags"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'format Javadoc tags'
* feature is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_FORMAT_JAVADOCS= "autoFormatJavaDocs"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'smart paste' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SMART_PASTE= "smartPaste"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'smart home-end' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SMART_HOME_END= AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END;
/**
* A named preference that controls if temporary problems are evaluated and shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_EVALUTE_TEMPORARY_PROBLEMS= "handleTemporaryProblems"; //$NON-NLS-1$
/**
* A named preference that controls if the overview ruler is shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_OVERVIEW_RULER= "overviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls if the line number ruler is shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_LINE_NUMBER_RULER= "lineNumberRuler"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render line numbers inside the line number ruler.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @see #EDITOR_LINE_NUMBER_RULER
*/
public final static String EDITOR_LINE_NUMBER_RULER_COLOR= "lineNumberColor"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render linked positions inside code templates.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_LINKED_POSITION_COLOR= "linkedPositionColor"; //$NON-NLS-1$
/**
* A named preference that holds the color used as the text foreground.
* This value has not effect if the system default color is used.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_FOREGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND;
/**
* A named preference that describes if the system default foreground color
* is used as the text foreground.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_FOREGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT;
/**
* A named preference that holds the color used as the text background.
* This value has not effect if the system default color is used.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_BACKGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND;
/**
* A named preference that describes if the system default background color
* is used as the text background.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_BACKGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT;
/**
* Preference key suffix for bold text style preference keys.
*
* @since 2.1
*/
public static final String EDITOR_BOLD_SUFFIX= "_bold"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render multi line comments.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_MULTI_LINE_COMMENT_COLOR= IJavaColorConstants.JAVA_MULTI_LINE_COMMENT;
/**
* The symbolic font name for the Java editor text font
* (value <code>"org.eclipse.jdt.ui.editors.textfont"</code>).
*
* @since 2.1
*/
public final static String EDITOR_TEXT_FONT= "org.eclipse.jdt.ui.editors.textfont"; //$NON-NLS-1$
/**
* A named preference that controls whether multi line comments are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> multi line comments are rendered
* in bold. If <code>false</code> the are rendered using no font style attribute.
* </p>
*/
public final static String EDITOR_MULTI_LINE_COMMENT_BOLD= IJavaColorConstants.JAVA_MULTI_LINE_COMMENT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render single line comments.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_SINGLE_LINE_COMMENT_COLOR= IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT;
/**
* A named preference that controls whether sinle line comments are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> single line comments are rendered
* in bold. If <code>false</code> the are rendered using no font style attribute.
* </p>
*/
public final static String EDITOR_SINGLE_LINE_COMMENT_BOLD= IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render java keywords.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVA_KEYWORD_COLOR= IJavaColorConstants.JAVA_KEYWORD;
/**
* A named preference that controls whether keywords are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVA_KEYWORD_BOLD= IJavaColorConstants.JAVA_KEYWORD + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render string constants.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_STRING_COLOR= IJavaColorConstants.JAVA_STRING;
/**
* A named preference that controls whether string constants are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_STRING_BOLD= IJavaColorConstants.JAVA_STRING + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render java default text.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVA_DEFAULT_COLOR= IJavaColorConstants.JAVA_DEFAULT;
/**
* A named preference that controls whether Java default text is rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVA_DEFAULT_BOLD= IJavaColorConstants.JAVA_DEFAULT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render task tags.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_TASK_TAG_COLOR= IJavaColorConstants.TASK_TAG;
/**
* A named preference that controls whether task tags are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_TAG_BOLD= IJavaColorConstants.TASK_TAG + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc keywords.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_KEYWORD_COLOR= IJavaColorConstants.JAVADOC_KEYWORD;
/**
* A named preference that controls whether javadoc keywords are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_KEYWORD_BOLD= IJavaColorConstants.JAVADOC_KEYWORD + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc tags.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_TAG_COLOR= IJavaColorConstants.JAVADOC_TAG;
/**
* A named preference that controls whether javadoc tags are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_TAG_BOLD= IJavaColorConstants.JAVADOC_TAG + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc links.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_LINKS_COLOR= IJavaColorConstants.JAVADOC_LINK;
/**
* A named preference that controls whether javadoc links are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_LINKS_BOLD= IJavaColorConstants.JAVADOC_LINK + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc default text.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_DEFAULT_COLOR= IJavaColorConstants.JAVADOC_DEFAULT;
/**
* A named preference that controls whether javadoc default text is rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_DEFAULT_BOLD= IJavaColorConstants.JAVADOC_DEFAULT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used for 'linked-mode' underline.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_LINK_COLOR= "linkColor"; //$NON-NLS-1$
/**
* A named preference that controls whether hover tooltips in the editor are turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String EDITOR_SHOW_HOVER= "org.eclipse.jdt.ui.editor.showHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when no control key is
* pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a hover
* contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_NONE_HOVER= "noneHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_CTRL_HOVER= "ctrlHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>SHIFT</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_SHIFT_HOVER= "shiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + ALT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
*/
public static final String EDITOR_CTRL_ALT_HOVER= "ctrlAltHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + ALT + SHIFT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
*/
public static final String EDITOR_CTRL_ALT_SHIFT_HOVER= "ctrlAltShiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + SHIFT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
* @deprecated Will be removed in one of the next builds.
*/
public static final String EDITOR_CTRL_SHIFT_HOVER= "ctrlShiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>ALT</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code>,
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
* @since 2.1
*/
public static final String EDITOR_ALT_SHIFT_HOVER= "altShiftHover"; //$NON-NLS-1$
/**
* A string value used by the named preferences for hover configuration to
* descibe that no hover should be shown for the given key modifiers.
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
* @since 2.1
*/
public static final String EDITOR_NO_HOVER_CONFIGURED_ID= "noHoverConfiguredId"; //$NON-NLS-1$
/**
* A string value used by the named preferences for hover configuration to
* descibe that the default hover should be shown for the given key
* modifiers. The default hover is described by the
* <code>EDITOR_DEFAULT_HOVER</code> property.
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_DEFAULT_HOVER_CONFIGURED_ID= "defaultHoverConfiguredId"; //$NON-NLS-1$
/**
* A named preference that defines the hover named the 'default hover'.
* Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or <code> the hover id of a hover
* contributed as <code>javaEditorTextHovers</code>.
* </p>
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_DEFAULT_HOVER= "defaultHover"; //$NON-NLS-1$
/**
* A named preference that controls if segmented view (show selected element only) is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String EDITOR_SHOW_SEGMENTS= "org.eclipse.jdt.ui.editor.showSegments"; //$NON-NLS-1$
/**
* A named preference that controls if browser like links are turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 2.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS= "browserLikeLinks"; //$NON-NLS-1$
/**
* A named preference that controls the key modifier for browser like links.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @since 2.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER= "browserLikeLinksKeyModifier"; //$NON-NLS-1$
/**
* A named preference that controls the key modifier mask for browser like links.
* The value is only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code>
* cannot be resolved to valid SWT modifier bits.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER
* @since 2.1.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK= "browserLikeLinksKeyModifierMask"; //$NON-NLS-1$
/**
* A named preference that controls disabling of the overwrite mode.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_DISABLE_OVERWRITE_MODE= "disable_overwrite_mode"; //$NON-NLS-1$
/**
* A named preference that controls the "smart semicolon" smart typing handler
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_SMART_SEMICOLON= "smart_semicolon"; //$NON-NLS-1$
/**
* A named preference that controls the "smart opening brace" smart typing handler
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_SMART_OPENING_BRACE= "smart_opening_brace"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist gets auto activated.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION= "content_assist_autoactivation"; //$NON-NLS-1$
/**
* A name preference that holds the auto activation delay time in milli seconds.
* <p>
* Value is of type <code>Int</code>.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_DELAY= "content_assist_autoactivation_delay"; //$NON-NLS-1$
/**
* A named preference that controls if code assist contains only visible proposals.
* <p>
* Value is of type <code>Boolean</code>. if <code>true<code> code assist only contains visible members. If
* <code>false</code> all members are included.
* </p>
*/
public final static String CODEASSIST_SHOW_VISIBLE_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist inserts a
* proposal automatically if only one proposal is available.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_AUTOINSERT= "content_assist_autoinsert"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist adds import
* statements.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_ADDIMPORT= "content_assist_add_import"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist only inserts
* completions. If set to false the proposals can also _replace_ code.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_INSERT_COMPLETION= "content_assist_insert_completion"; //$NON-NLS-1$
/**
* A named preference that controls whether code assist proposals filtering is case sensitive or not.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_CASE_SENSITIVITY= "content_assist_case_sensitivity"; //$NON-NLS-1$
/**
* A named preference that defines if code assist proposals are sorted in alphabetical order.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> that are sorted in alphabetical
* order. If <code>false</code> that are unsorted.
* </p>
*/
public final static String CODEASSIST_ORDER_PROPOSALS= "content_assist_order_proposals"; //$NON-NLS-1$
/**
* A named preference that controls if argument names are filled in when a method is selected from as list
* of code assist proposal.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_FILL_ARGUMENT_NAMES= "content_assist_fill_method_arguments"; //$NON-NLS-1$
/**
* A named preference that controls if method arguments are guessed when a
* method is selected from as list of code assist proposal.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_GUESS_METHOD_ARGUMENTS= "content_assist_guess_method_arguments"; //$NON-NLS-1$
/**
* A named preference that holds the characters that auto activate code assist in Java code.
* <p>
* Value is of type <code>Sring</code>. All characters that trigger auto code assist in Java code.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA= "content_assist_autoactivation_triggers_java"; //$NON-NLS-1$
/**
* A named preference that holds the characters that auto activate code assist in Javadoc.
* <p>
* Value is of type <code>Sring</code>. All characters that trigger auto code assist in Javadoc.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC= "content_assist_autoactivation_triggers_javadoc"; //$NON-NLS-1$
/**
* A named preference that holds the background color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PROPOSALS_BACKGROUND= "content_assist_proposals_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PROPOSALS_FOREGROUND= "content_assist_proposals_foreground"; //$NON-NLS-1$
/**
* A named preference that holds the background color used for parameter hints.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PARAMETERS_BACKGROUND= "content_assist_parameters_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PARAMETERS_FOREGROUND= "content_assist_parameters_foreground"; //$NON-NLS-1$
/**
* A named preference that holds the background color used in the code
* assist selection dialog to mark replaced code.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String CODEASSIST_REPLACEMENT_BACKGROUND= "content_assist_completion_replacement_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code
* assist selection dialog to mark replaced code.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String CODEASSIST_REPLACEMENT_FOREGROUND= "content_assist_completion_replacement_foreground"; //$NON-NLS-1$
/**
* A named preference that controls the behaviour of the refactoring wizard for showing the error page.
* <p>
* Value is of type <code>String</code>. Valid values are:
* <code>REFACTOR_FATAL_SEVERITY</code>,
* <code>REFACTOR_ERROR_SEVERITY</code>,
* <code>REFACTOR_WARNING_SEVERITY</code>
* <code>REFACTOR_INFO_SEVERITY</code>,
* <code>REFACTOR_OK_SEVERITY</code>.
* </p>
*
* @see #REFACTOR_FATAL_SEVERITY
* @see #REFACTOR_ERROR_SEVERITY
* @see #REFACTOR_WARNING_SEVERITY
* @see #REFACTOR_INFO_SEVERITY
* @see #REFACTOR_OK_SEVERITY
*/
public static final String REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD= "Refactoring.ErrorPage.severityThreshold"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_FATAL_SEVERITY= "4"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_ERROR_SEVERITY= "3"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_WARNING_SEVERITY= "2"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_INFO_SEVERITY= "1"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_OK_SEVERITY= "0"; //$NON-NLS-1$
/**
* A named preference thet controls whether all dirty editors are automatically saved before a refactoring is
* executed.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String REFACTOR_SAVE_ALL_EDITORS= "Refactoring.savealleditors"; //$NON-NLS-1$
/**
* A named preference that controls if the Java Browsing views are linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @see #LINK_PACKAGES_TO_EDITOR
*/
public static final String BROWSING_LINK_VIEW_TO_EDITOR= "org.eclipse.jdt.ui.browsing.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls the layout of the Java Browsing views vertically. Boolean value.
* <p>
* Value is of type <code>Boolean</code>. If <code>true<code> the views are stacked vertical.
* If <code>false</code> they are stacked horizontal.
* </p>
*/
public static final String BROWSING_STACK_VERTICALLY= "org.eclipse.jdt.ui.browsing.stackVertically"; //$NON-NLS-1$
/**
* A named preference that controls if templates are formatted when applied.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 2.1
*/
public static final String TEMPLATES_USE_CODEFORMATTER= "org.eclipse.jdt.ui.template.format"; //$NON-NLS-1$
/**
* Initializes the given preference store with the default values.
*
* @param store the preference store to be initialized
*
* @since 2.1
*/
public static void initializeDefaultValues(IPreferenceStore store) {
store.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false);
// JavaBasePreferencePage
store.setDefault(PreferenceConstants.LINK_PACKAGES_TO_EDITOR, false);
store.setDefault(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR, false);
store.setDefault(PreferenceConstants.OPEN_TYPE_HIERARCHY, PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_VIEW_PART);
store.setDefault(PreferenceConstants.DOUBLE_CLICK, PreferenceConstants.DOUBLE_CLICK_EXPANDS);
store.setDefault(PreferenceConstants.UPDATE_JAVA_VIEWS, PreferenceConstants.UPDATE_WHILE_EDITING);
store.setDefault(PreferenceConstants.LINK_BROWSING_PROJECTS_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_PACKAGES_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_TYPES_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_MEMBERS_TO_EDITOR, true);
// AppearancePreferencePage
store.setDefault(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES, false);
store.setDefault(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE, false);
store.setDefault(PreferenceConstants.SHOW_CU_CHILDREN, true);
store.setDefault(PreferenceConstants.APPEARANCE_OVERRIDE_INDICATOR, true);
store.setDefault(PreferenceConstants.BROWSING_STACK_VERTICALLY, false);
store.setDefault(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW, ""); //$NON-NLS-1$
store.setDefault(PreferenceConstants.APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER, true);
// ImportOrganizePreferencePage
store.setDefault(PreferenceConstants.ORGIMPORTS_IMPORTORDER, "java;javax;org;com"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, 99);
store.setDefault(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, true);
// ClasspathVariablesPreferencePage
// CodeFormatterPreferencePage
// CompilerPreferencePage
// no initialization needed
// RefactoringPreferencePage
store.setDefault(PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD, PreferenceConstants.REFACTOR_ERROR_SEVERITY);
store.setDefault(PreferenceConstants.REFACTOR_SAVE_ALL_EDITORS, false);
// TemplatePreferencePage
store.setDefault(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER, true);
// CodeGenerationPreferencePage
// compatibility code
if (store.getBoolean(PreferenceConstants.CODEGEN_USE_GETTERSETTER_PREFIX)) {
String prefix= store.getString(PreferenceConstants.CODEGEN_GETTERSETTER_PREFIX);
if (prefix.length() > 0) {
JavaCore.getPlugin().getPluginPreferences().setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, prefix);
store.setToDefault(PreferenceConstants.CODEGEN_USE_GETTERSETTER_PREFIX);
store.setToDefault(PreferenceConstants.CODEGEN_GETTERSETTER_PREFIX);
}
}
if (store.getBoolean(PreferenceConstants.CODEGEN_USE_GETTERSETTER_SUFFIX)) {
String suffix= store.getString(PreferenceConstants.CODEGEN_GETTERSETTER_SUFFIX);
if (suffix.length() > 0) {
JavaCore.getPlugin().getPluginPreferences().setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, suffix);
store.setToDefault(PreferenceConstants.CODEGEN_USE_GETTERSETTER_SUFFIX);
store.setToDefault(PreferenceConstants.CODEGEN_GETTERSETTER_SUFFIX);
}
}
store.setDefault(PreferenceConstants.CODEGEN_ADD_COMMENTS, true);
// MembersOrderPreferencePage
store.setDefault(PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER, "T,SI,SF,SM,I,F,C,M"); //$NON-NLS-1$
// must add here to guarantee that it is the first in the listener list
store.addPropertyChangeListener(JavaPlugin.getDefault().getMemberOrderPreferenceCache());
// JavaEditorPreferencePage
store.setDefault(PreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR, new RGB(192, 192,192));
store.setDefault(PreferenceConstants.EDITOR_CURRENT_LINE, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_CURRENT_LINE_COLOR, new RGB(225, 235, 224));
store.setDefault(PreferenceConstants.EDITOR_PRINT_MARGIN, false);
store.setDefault(PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 80);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, new RGB(176, 180 , 185));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_FIND_SCOPE_COLOR, new RGB(185, 176 , 180));
store.setDefault(PreferenceConstants.EDITOR_PROBLEM_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR, new RGB(255, 0 , 128));
store.setDefault(PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_WARNING_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR, new RGB(244, 200 , 45));
store.setDefault(PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_TASK_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_TASK_INDICATION_COLOR, new RGB(0, 128, 255));
store.setDefault(PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_BOOKMARK_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR, new RGB(34, 164, 99));
store.setDefault(PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR, new RGB(192, 192, 192));
store.setDefault(PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_UNKNOWN_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR, new RGB(0, 0, 0));
store.setDefault(PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER, false);
store.setDefault(PreferenceConstants.EDITOR_CORRECTION_INDICATION, true);
store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true);
store.setDefault(PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, true);
store.setDefault(PreferenceConstants.EDITOR_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_LINE_NUMBER_RULER, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINKED_POSITION_COLOR, new RGB(0, 200 , 100));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINK_COLOR, new RGB(0, 0, 255));
store.setDefault(PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR, true);
store.setDefault(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR, true);
store.setDefault(PreferenceConstants.EDITOR_TAB_WIDTH, 4);
store.setDefault(PreferenceConstants.EDITOR_SPACES_FOR_TABS, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR, new RGB(63, 127, 95));
store.setDefault(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR, new RGB(63, 127, 95));
store.setDefault(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR, new RGB(127, 0, 85));
store.setDefault(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_STRING_COLOR, new RGB(42, 0, 255));
store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR, new RGB(0, 0, 0));
store.setDefault(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_TASK_TAG_COLOR, new RGB(127, 159, 191));
store.setDefault(PreferenceConstants.EDITOR_TASK_TAG_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR, new RGB(127, 159, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_KEYWORD_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR, new RGB(127, 127, 159));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR, new RGB(63, 63, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR, new RGB(63, 95, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD, false);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION, true);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY, 500);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOINSERT, true);
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, new RGB(254, 241, 233));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND, new RGB(254, 241, 233));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, new RGB(255, 255, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, new RGB(255, 0, 0));
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA, "."); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC, "@"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS, true);
store.setDefault(PreferenceConstants.CODEASSIST_CASE_SENSITIVITY, false);
store.setDefault(PreferenceConstants.CODEASSIST_ORDER_PROPOSALS, false);
store.setDefault(PreferenceConstants.CODEASSIST_ADDIMPORT, true);
store.setDefault(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, true);
store.setDefault(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, false);
store.setDefault(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, true);
store.setDefault(PreferenceConstants.EDITOR_SMART_HOME_END, true);
store.setDefault(PreferenceConstants.EDITOR_SMART_PASTE, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_STRINGS, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACKETS, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACES, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_JAVADOCS, true);
store.setDefault(PreferenceConstants.EDITOR_WRAP_STRINGS, true);
store.setDefault(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, true);
store.setDefault(PreferenceConstants.EDITOR_FORMAT_JAVADOCS, false);
String ctrl= Action.findModifierString(SWT.CTRL);
store.setDefault(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS, "org.eclipse.jdt.ui.BestMatchHover;0;org.eclipse.jdt.ui.JavaSourceHover;" + ctrl); //$NON-NLS-1$
store.setDefault(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS, "org.eclipse.jdt.ui.BestMatchHover;0;org.eclipse.jdt.ui.JavaSourceHover;" + SWT.CTRL); //$NON-NLS-1$
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, true);
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, ctrl);
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK, SWT.CTRL);
// work in progress
store.setDefault(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE, false);
store.setDefault(PreferenceConstants.EDITOR_SMART_SEMICOLON, false);
store.setDefault(PreferenceConstants.EDITOR_SMART_OPENING_BRACE, false);
// do more complicated stuff
NewJavaProjectPreferencePage.initDefaults(store);
}
/**
* Returns the JDT-UI preference store.
*
* @return the JDT-UI preference store
*/
public static IPreferenceStore getPreferenceStore() {
return JavaPlugin.getDefault().getPreferenceStore();
}
/**
* Encodes a JRE library to be used in the named preference <code>NEWPROJECT_JRELIBRARY_LIST</code>.
*
* @param description a string value describing the JRE library. The description is used
* to indentify the JDR library in the UI
* @param entries an array of classpath entries to be encoded
*
* @return the encoded string.
*/
public static String encodeJRELibrary(String description, IClasspathEntry[] entries) {
return NewJavaProjectPreferencePage.encodeJRELibrary(description, entries);
}
/**
* Decodes an encoded JRE library and returns its description string.
*
* @return the description of an encoded JRE library
*
* @see #encodeJRELibrary(String, IClasspathEntry[])
*/
public static String decodeJRELibraryDescription(String encodedLibrary) {
return NewJavaProjectPreferencePage.decodeJRELibraryDescription(encodedLibrary);
}
/**
* Decodes an encoded JRE library and returns its classpath entries.
*
* @return the array of classpath entries of an encoded JRE library.
*
* @see #encodeJRELibrary(String, IClasspathEntry[])
*/
public static IClasspathEntry[] decodeJRELibraryClasspathEntries(String encodedLibrary) {
return NewJavaProjectPreferencePage.decodeJRELibraryClasspathEntries(encodedLibrary);
}
/**
* Returns the current configuration for the JRE to be used as default in new Java projects.
* This is a convenience method to access the named preference <code>NEWPROJECT_JRELIBRARY_LIST
* </code> with the index defined by <code> NEWPROJECT_JRELIBRARY_INDEX</code>.
*
* @return the current default set of classpath entries
*
* @see #NEWPROJECT_JRELIBRARY_LIST
* @see #NEWPROJECT_JRELIBRARY_INDEX
*/
public static IClasspathEntry[] getDefaultJRELibrary() {
return NewJavaProjectPreferencePage.getDefaultJRELibrary();
}
}
|
39,056 |
Bug 39056 Add constructors from Superclass no longer finding duplicates
|
The following test case finds two constructors to override in class SmallTestB when it should find none. public class SmallTestA { private int fDummyInt; SmallTestA() { super(); } SmallTestA(int a) { super(); fDummyInt= a; } } public class SmallTestB extends SmallTestA { SmallTestB() { super(); } SmallTestB(int a) { super(a); } }
|
resolved fixed
|
e340723
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-19T11:49:26Z | 2003-06-18T09:53:20Z |
org.eclipse.jdt.ui/core
| |
39,056 |
Bug 39056 Add constructors from Superclass no longer finding duplicates
|
The following test case finds two constructors to override in class SmallTestB when it should find none. public class SmallTestA { private int fDummyInt; SmallTestA() { super(); } SmallTestA(int a) { super(); fDummyInt= a; } } public class SmallTestB extends SmallTestA { SmallTestB() { super(); } SmallTestB(int a) { super(a); } }
|
resolved fixed
|
e340723
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-19T11:49:26Z | 2003-06-18T09:53:20Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility.java
| |
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/core
| |
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java
| |
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/ISourceActionContentProvider.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import org.eclipse.jface.viewers.ITreeContentProvider;
public interface ISourceActionContentProvider extends ITreeContentProvider {
public final String SETTINGS_INSERTPOSITION= "InsertPosition"; //$NON-NLS-1$
public int getInsertPosition();
public void setInsertPosition(int insert);
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OverrideMethodDialog.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.JavaUIMessages;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.util.ViewerPane;
public class OverrideMethodDialog extends SourceActionDialog {
private class OverrideFlatTreeAction extends Action {
private boolean fToggle;
public OverrideFlatTreeAction() {
super(); //$NON-NLS-1$
setToolTipText(JavaUIMessages.getString("OverrideMethodDialog.groupMethodsByTypes")); //$NON-NLS-1$
JavaPluginImages.setLocalImageDescriptors(this, "impl_co.gif"); //$NON-NLS-1$
fToggle= getOverrideContentProvider().isShowTypes();
setChecked(fToggle);
}
public void run() {
fToggle= !fToggle;
setChecked(fToggle);
getOverrideContentProvider().setShowTypes(fToggle);
}
private OverrideMethodContentProvider getOverrideContentProvider() {
return (OverrideMethodContentProvider) getContentProvider();
}
}
private static class OverrideMethodContentProvider implements ISourceActionContentProvider {
private final String SETTINGS_SECTION= "OverrideMethodDialog"; //$NON-NLS-1$
private final String SETTINGS_SHOWTYPES= "showtypes"; //$NON-NLS-1$
private Object[] fTypes;
private IMethod[] fMethods;
private final Object[] fEmpty= new Object[0];
private boolean fShowTypes;
private Viewer fViewer;
private IDialogSettings fSettings;
/**
* Constructor for OverrideMethodContentProvider.
*/
public OverrideMethodContentProvider() {
IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
fSettings= dialogSettings.getSection(SETTINGS_SECTION);
if (fSettings == null) {
fSettings= dialogSettings.addNewSection(SETTINGS_SECTION);
fSettings.put(SETTINGS_SHOWTYPES, true);
}
fShowTypes= fSettings.getBoolean(SETTINGS_SHOWTYPES);
}
public void init(IMethod[] methods, IType[] types) {
fMethods= methods;
fTypes= types;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IType) {
ArrayList result= new ArrayList(fMethods.length);
for (int i= 0; i < fMethods.length; i++) {
if (fMethods[i].getDeclaringType().equals(parentElement)) {
result.add(fMethods[i]);
}
}
return result.toArray();
}
return fEmpty;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
if (element instanceof IMethod) {
return ((IMethod)element).getDeclaringType();
}
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fShowTypes ? fTypes : fMethods;
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
fViewer= viewer;
}
public boolean isShowTypes() {
return fShowTypes;
}
public void setShowTypes(boolean showTypes) {
if (fShowTypes != showTypes) {
fShowTypes= showTypes;
fSettings.put(SETTINGS_SHOWTYPES, showTypes);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public int getInsertPosition() {
return 0;
}
public void setInsertPosition(int insert) {
}
}
private static class OverrideMethodSorter extends ViewerSorter {
private IType[] fAllTypes;
public OverrideMethodSorter(ITypeHierarchy typeHierarchy) {
IType curr= typeHierarchy.getType();
IType[] superTypes= typeHierarchy.getAllSupertypes(curr);
fAllTypes= new IType[superTypes.length + 1];
fAllTypes[0]= curr;
System.arraycopy(superTypes, 0, fAllTypes, 1, superTypes.length);
}
/*
* @see ViewerSorter#compare(Viewer, Object, Object)
*/
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof IType && e2 instanceof IType) {
if (e1.equals(e2)) {
return 0;
}
for (int i= 0; i < fAllTypes.length; i++) {
IType curr= fAllTypes[i];
if (curr.equals(e1)) {
return -1;
}
if (curr.equals(e2)) {
return 1;
}
}
return 0;
} else {
return super.compare(viewer, e1, e2);
}
}
}
private static class OverrideMethodValidator implements ISelectionStatusValidator {
private static int fNumMethods;
public OverrideMethodValidator(int entries) {
super();
fNumMethods= entries;
}
/*
* @see ISelectionValidator#validate(Object[])
*/
public IStatus validate(Object[] selection) {
int count= 0;
for (int i= 0; i < selection.length; i++) {
if (selection[i] instanceof IMethod) {
count++;
}
}
if (count == 0) {
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
}
String[] args= { String.valueOf(count), String.valueOf(fNumMethods)};
String message= JavaUIMessages.getFormattedString("OverrideMethodDialog.selectioninfo.more", args); //$NON-NLS-1$
return new StatusInfo(IStatus.INFO, message);
}
}
public OverrideMethodDialog(Shell parent, CompilationUnitEditor editor, IType type, boolean isSubType) throws JavaModelException {
super(parent, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), new OverrideMethodContentProvider(), editor, type);
init(type, isSubType);
}
public boolean hasMethodsToOverride() {
return getContentProvider().getElements(null).length > 0;
}
private void init(IType type, boolean isSubType) throws JavaModelException {
ITypeHierarchy typeHierarchy= type.newSupertypeHierarchy(null);
IMethod[] inheritedMethods= StubUtility.getOverridableMethods(type, typeHierarchy, isSubType);
List toImplement= new ArrayList();
for (int i= 0; i < inheritedMethods.length; i++) {
IMethod curr= inheritedMethods[i];
if (JdtFlags.isAbstract(curr)) {
toImplement.add(curr);
}
}
IMethod[] toImplementArray= (IMethod[]) toImplement.toArray(new IMethod[toImplement.size()]);
setInitialSelections(toImplementArray);
HashSet expanded= new HashSet(toImplementArray.length);
for (int i= 0; i < toImplementArray.length; i++) {
expanded.add(toImplementArray[i].getDeclaringType());
}
HashSet types= new HashSet(inheritedMethods.length);
for (int i= 0; i < inheritedMethods.length; i++) {
types.add(inheritedMethods[i].getDeclaringType());
}
IType[] typesArrays= (IType[]) types.toArray(new IType[types.size()]);
ViewerSorter sorter= new OverrideMethodSorter(typeHierarchy);
if (expanded.isEmpty() && typesArrays.length > 0) {
sorter.sort(null, typesArrays); // sort to get the first one
expanded.add(typesArrays[0]);
}
setExpandedElements(expanded.toArray());
ITreeContentProvider contentProvider= getContentProvider();
((OverrideMethodContentProvider) contentProvider).init(inheritedMethods, typesArrays);
setTitle(JavaUIMessages.getString("OverrideMethodDialog.dialog.title")); //$NON-NLS-1$
setMessage(null);
setValidator(new OverrideMethodValidator(inheritedMethods.length));
setSorter(sorter);
setContainerMode(true);
setSize(60, 18);
setInput(new Object());
}
/*
* @see CheckedTreeSelectionDialog#createTreeViewer(Composite)
*/
protected CheckboxTreeViewer createTreeViewer(Composite composite) {
initializeDialogUnits(composite);
ViewerPane pane= new ViewerPane(composite, SWT.BORDER | SWT.FLAT);
pane.setText(JavaUIMessages.getString("OverrideMethodDialog.dialog.description")); //$NON-NLS-1$
CheckboxTreeViewer treeViewer= super.createTreeViewer(pane);
pane.setContent(treeViewer.getControl());
GridLayout paneLayout= new GridLayout();
paneLayout.marginHeight= 0;
paneLayout.marginWidth= 0;
paneLayout.numColumns= 1;
pane.setLayout(paneLayout);
GridData gd= new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(55);
gd.heightHint = convertHeightInCharsToPixels(15);
pane.setLayoutData(gd);
ToolBarManager tbm= pane.getToolBarManager();
tbm.add(new OverrideFlatTreeAction()); // create after tree is created
tbm.update(true);
return treeViewer;
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.OVERRIDE_TREE_SELECTION_DIALOG);
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/SourceActionDialog.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility.GenStubSettings;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* An advanced version of CheckedTreeSelectionDialog with right-side button layout and
* extra buttons and composites.
*/
public class SourceActionDialog extends CheckedTreeSelectionDialog {
private int fInsertionIndex;
private CompilationUnitEditor fEditor;
private ISourceActionContentProvider fContentProvider;
private boolean fGenerateComment;
private IType fType;
private int fWidth = 60;
private int fHeight = 18;
private String fCommentString;
public SourceActionDialog(Shell parent, ILabelProvider labelProvider, ISourceActionContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider);
fEditor= editor;
fContentProvider= contentProvider;
fType= type;
fCommentString= ActionMessages.getString("SourceActionDialog.createMethodComment"); //$NON-NLS-1$
// Take the default from the default for generating comments from the code gen prefs
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
GenStubSettings genStubSettings= new GenStubSettings(settings);
fGenerateComment= genStubSettings.createComments;
}
public void setCommentString(String string) {
fCommentString= string;
}
protected ISourceActionContentProvider getContentProvider() {
return fContentProvider;
}
public int getInsertionIndex() {
return fInsertionIndex;
}
private void setInsertionIndex(int index) {
fInsertionIndex = index;
}
public boolean getGenerateComment() {
return fGenerateComment;
}
private void setGenerateComment(boolean comment) {
fGenerateComment= comment;
}
/**
* Sets the size of the tree in unit of characters.
* @param width the width of the tree.
* @param height the height of the tree.
*/
public void setSize(int width, int height) {
fWidth = width;
fHeight = height;
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case IDialogConstants.OK_ID: {
okPressed();
break;
}
case IDialogConstants.CANCEL_ID: {
cancelPressed();
break;
}
}
}
/**
* Returns a composite containing the label created at the top of the dialog. Returns null if there is the
* message for the label is null.
*/
protected Label createMessageArea(Composite composite) {
if (getMessage() != null) {
Label label = new Label(composite,SWT.NONE);
label.setText(getMessage());
label.setFont(composite.getFont());
return label;
}
return null;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
GridData gd= null;
layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setFont(parent.getFont());
Label messageLabel = createMessageArea(composite);
if (messageLabel != null) {
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
messageLabel.setLayoutData(gd);
}
Composite inner= new Composite(composite, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns= 2;
innerLayout.marginHeight= 0;
innerLayout.marginWidth= 0;
inner.setLayout(innerLayout);
inner.setFont(parent.getFont());
CheckboxTreeViewer treeViewer= createTreeViewer(inner);
gd= new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(fWidth);
gd.heightHint = convertHeightInCharsToPixels(fHeight);
treeViewer.getControl().setLayoutData(gd);
Composite buttonComposite= createSelectionButtons(inner);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
buttonComposite.setLayoutData(gd);
gd= new GridData(GridData.FILL_BOTH);
inner.setLayoutData(gd);
Composite entryComposite= createEntryPtCombo(composite);
entryComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite commentComposite= createCommentSelection(composite);
commentComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
gd= new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gd);
return composite;
}
protected Composite createCommentSelection(Composite composite) {
Composite commentComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
commentComposite.setLayout(layout);
commentComposite.setFont(composite.getFont());
Button commentButton= new Button(commentComposite, SWT.CHECK);
commentButton.setText(fCommentString); //$NON-NLS-1$
commentButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
commentButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean isSelected= (((Button) e.widget).getSelection());
setGenerateComment(isSelected);
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
commentButton.setSelection(getGenerateComment());
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
commentButton.setLayoutData(gd);
return commentComposite;
}
protected Composite createEntryPtCombo(Composite composite) {
Composite selectionComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
selectionComposite.setLayout(layout);
addOrderEntryChoices(selectionComposite);
return selectionComposite;
}
private Composite addOrderEntryChoices(Composite buttonComposite) {
Label enterLabel= new Label(buttonComposite, SWT.NONE);
enterLabel.setText(ActionMessages.getString("SourceActionDialog.enterAt_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
enterLabel.setLayoutData(gd);
final Combo enterCombo= new Combo(buttonComposite, SWT.READ_ONLY);
fillWithPossibleInsertPositions(enterCombo);
gd= new GridData(GridData.FILL_BOTH);
enterCombo.setLayoutData(gd);
enterCombo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
int index= enterCombo.getSelectionIndex();
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getContentProvider().setInsertPosition(index);
setInsertionIndex(index);
}
});
return buttonComposite;
}
private void fillWithPossibleInsertPositions(Combo combo) {
try {
int position= 0;
int presetOffset= 0;
if (fEditor != null) {
presetOffset= ((TextSelection) fEditor.getSelectionProvider().getSelection()).getOffset();
}
else {
List preselected= getInitialElementSelections();
int size= preselected.size();
if ((size > 1) || (size == 0))
presetOffset= 0;
else {
IJavaElement element= (IJavaElement) preselected.get(0);
int type= element.getElementType();
if (type == IJavaElement.FIELD)
presetOffset= ((IField)element).getSourceRange().getOffset();
else if (type == IJavaElement.METHOD)
presetOffset= ((IMethod)element).getSourceRange().getOffset();
}
}
IMethod[] methods= fType.getMethods();
combo.add(ActionMessages.getString("SourceActionDialog.first_method")); //$NON-NLS-1$
combo.add(ActionMessages.getString("SourceActionDialog.last_method")); //$NON-NLS-1$
int bestDiff= Integer.MAX_VALUE;
for (int i= 0; i < methods.length; i++) {
int currDiff= 0;
IMethod curr= methods[i];
combo.add(JavaElementLabels.getElementLabel(methods[i], JavaElementLabels.M_PARAMETER_TYPES));
// calculate method to pre-select
currDiff= presetOffset - curr.getSourceRange().getOffset();
if (currDiff >= 0)
if(currDiff < bestDiff) {
bestDiff= currDiff;
position= i + 2; // first two entries are first/last
}
else
break;
}
// Add persistence only if first or last method: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int index= getContentProvider().getInsertPosition();
if ((index == 0) || (index == 1))
combo.select(index);
else
combo.select(position);
setInsertionIndex(combo.getSelectionIndex());
} catch (JavaModelException e) {
}
}
/*
* Determine where in the file to enter the newly created methods.
*/
public IJavaElement getElementPosition() {
int comboBoxIndex= getInsertionIndex();
try {
if (comboBoxIndex == 0) // as first method
return asFirstMethod(fType);
else if (comboBoxIndex == 1) // as last method
return null;
else // method position
return atElementPosition(fType, comboBoxIndex);
} catch (JavaModelException e) {
return null;
}
}
private IMethod asFirstMethod(IType type) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
if (methods.length > 0) {
return methods[0];
}
}
return null;
}
/* Returns the element directly following the method to insert after. Index should never
* always be > 2 since 0 means first method, and 1 means last method.
*/
private IJavaElement atElementPosition(IType type, int index) throws JavaModelException {
if (type != null) {
IMethod[] methods= type.getMethods();
IJavaElement[] elements= type.getChildren();
for (int i= 0; i < (elements.length-1); i++) {
if (methods[index-2] == elements[i]) // first two entries are first/last
return elements[i+1];
}
}
return null;
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/NameConventionConfigurationBlock.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.preferences;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.JavaElementImageDescriptor;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.dialogs.StatusDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.jdt.internal.ui.util.SWTUtil;
import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
/*
* The page to configure name conventions
*/
public class NameConventionConfigurationBlock extends OptionsConfigurationBlock {
private final static int FIELD= 1;
private final static int STATIC= 2;
private final static int ARGUMENT= 3;
private final static int LOCAL= 4;
// Preference store keys, see JavaCore.getOptions
private static final String PREF_FIELD_PREFIXES= JavaCore.CODEASSIST_FIELD_PREFIXES;
private static final String PREF_FIELD_SUFFIXES= JavaCore.CODEASSIST_FIELD_SUFFIXES;
private static final String PREF_STATIC_FIELD_PREFIXES= JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES;
private static final String PREF_STATIC_FIELD_SUFFIXES= JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES;
private static final String PREF_ARGUMENT_PREFIXES= JavaCore.CODEASSIST_ARGUMENT_PREFIXES;
private static final String PREF_ARGUMENT_SUFFIXES= JavaCore.CODEASSIST_ARGUMENT_SUFFIXES;
private static final String PREF_LOCAL_PREFIXES= JavaCore.CODEASSIST_LOCAL_PREFIXES;
private static final String PREF_LOCAL_SUFFIXES= JavaCore.CODEASSIST_LOCAL_SUFFIXES;
private static class NameConventionEntry {
public int kind;
public String prefix;
public String suffix;
public String prefixkey;
public String suffixkey;
}
private class NameConventionInputDialog extends StatusDialog implements IDialogFieldListener {
private StringDialogField fPrefixField;
private StringDialogField fSuffixField;
private NameConventionEntry fEntry;
private DialogField fMessageField;
public NameConventionInputDialog(Shell parent, String title, String message, NameConventionEntry entry) {
super(parent);
fEntry= entry;
setTitle(title);
fMessageField= new DialogField();
fMessageField.setLabelText(message);
fPrefixField= new StringDialogField();
fPrefixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.prefix")); //$NON-NLS-1$
fPrefixField.setDialogFieldListener(this);
fSuffixField= new StringDialogField();
fSuffixField.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.dialog.suffix")); //$NON-NLS-1$
fSuffixField.setDialogFieldListener(this);
fPrefixField.setText(entry.prefix);
fSuffixField.setText(entry.suffix);
}
public NameConventionEntry getResult() {
NameConventionEntry res= new NameConventionEntry();
res.prefix= fPrefixField.getText();
res.suffix= fSuffixField.getText();
res.prefixkey= fEntry.prefixkey;
res.suffixkey= fEntry.suffixkey;
res.kind= fEntry.kind;
return res;
}
protected Control createDialogArea(Composite parent) {
Composite composite= (Composite) super.createDialogArea(parent);
Composite inner= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 2;
inner.setLayout(layout);
fMessageField.doFillIntoGrid(inner, 2);
fPrefixField.doFillIntoGrid(inner, 2);
fSuffixField.doFillIntoGrid(inner, 2);
LayoutUtil.setHorizontalGrabbing(fPrefixField.getTextControl(null));
LayoutUtil.setWidthHint(fPrefixField.getTextControl(null), convertWidthInCharsToPixels(45));
LayoutUtil.setWidthHint(fSuffixField.getTextControl(null), convertWidthInCharsToPixels(45));
fPrefixField.postSetFocusOnDialogField(parent.getDisplay());
applyDialogFont(composite);
return composite;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
*/
public void dialogFieldChanged(DialogField field) {
// validate
IStatus prefixStatus= validateIdentifiers(getTokens(fPrefixField.getText(), ","), true); //$NON-NLS-1$
IStatus suffixStatus= validateIdentifiers(getTokens(fSuffixField.getText(), ","), false); //$NON-NLS-1$
updateStatus(StatusUtil.getMoreSevere(suffixStatus, prefixStatus));
}
private IStatus validateIdentifiers(String[] values, boolean prefix) {
for (int i= 0; i < values.length; i++) {
String val= values[i];
if (val.length() == 0) {
if (prefix) {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptyprefix")); //$NON-NLS-1$
} else {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getString("NameConventionConfigurationBlock.error.emptysuffix")); //$NON-NLS-1$
}
}
String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
IStatus status= JavaConventions.validateFieldName(name);
if (status.matches(IStatus.ERROR)) {
if (prefix) {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidprefix", val)); //$NON-NLS-1$
} else {
return new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString("NameConventionConfigurationBlock.error.invalidsuffix", val)); //$NON-NLS-1$
}
}
}
return new StatusInfo();
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
//WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.IMPORT_ORGANIZE_INPUT_DIALOG);
}
}
private static class NameConventionLabelProvider extends LabelProvider implements ITableLabelProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
return getColumnImage(element, 0);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
return getColumnText(element, 0);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
*/
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex != 0) {
return null;
}
NameConventionEntry entry= (NameConventionEntry) element;
ImageDescriptorRegistry registry= JavaPlugin.getImageDescriptorRegistry();
switch (entry.kind) {
case FIELD:
return registry.get(JavaPluginImages.DESC_FIELD_PUBLIC);
case STATIC:
return registry.get(new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE));
case ARGUMENT:
return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
default:
return registry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE);
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object element, int columnIndex) {
NameConventionEntry entry= (NameConventionEntry) element;
if (columnIndex == 0) {
switch (entry.kind) {
case FIELD:
return PreferencesMessages.getString("NameConventionConfigurationBlock.field.label"); //$NON-NLS-1$
case STATIC:
return PreferencesMessages.getString("NameConventionConfigurationBlock.static.label"); //$NON-NLS-1$
case ARGUMENT:
return PreferencesMessages.getString("NameConventionConfigurationBlock.arg.label"); //$NON-NLS-1$
default:
return PreferencesMessages.getString("NameConventionConfigurationBlock.local.label"); //$NON-NLS-1$
}
} else if (columnIndex == 1) {
return entry.prefix;
} else {
return entry.suffix;
}
}
}
private class NameConventionAdapter implements IListAdapter, IDialogFieldListener {
private boolean canEdit(ListDialogField field) {
return field.getSelectedElements().size() == 1;
}
public void customButtonPressed(ListDialogField field, int index) {
doEditButtonPressed(index);
}
public void selectionChanged(ListDialogField field) {
field.enableButton(0, canEdit(field));
}
public void doubleClicked(ListDialogField field) {
if (canEdit(field)) {
doEditButtonPressed(0);
}
}
public void dialogFieldChanged(DialogField field) {
validateSettings(null, null);
}
}
private ListDialogField fNameConventionList;
private SelectionButtonDialogField fUseKeywordThisBox;
private static final String PREF_KEYWORD_THIS= PreferenceConstants.CODEGEN_KEYWORD_THIS;
public NameConventionConfigurationBlock(IStatusChangeListener context, IJavaProject project) {
super(context, project);
NameConventionAdapter adapter= new NameConventionAdapter();
String[] buttons= new String[] {
/* 0 */ PreferencesMessages.getString("NameConventionConfigurationBlock.list.edit.button") //$NON-NLS-1$
};
fNameConventionList= new ListDialogField(adapter, buttons, new NameConventionLabelProvider());
fNameConventionList.setDialogFieldListener(adapter);
fNameConventionList.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.list.label")); //$NON-NLS-1$
String[] columnsHeaders= new String[] {
PreferencesMessages.getString("NameConventionConfigurationBlock.list.name.column"), //$NON-NLS-1$
PreferencesMessages.getString("NameConventionConfigurationBlock.list.prefix.column"), //$NON-NLS-1$
PreferencesMessages.getString("NameConventionConfigurationBlock.list.suffix.column"), //$NON-NLS-1$
};
ColumnLayoutData[] data= new ColumnLayoutData[] {
new ColumnWeightData(3),
new ColumnWeightData(2),
new ColumnWeightData(2)
};
fNameConventionList.setTableColumns(new ListDialogField.ColumnsDescription(data, columnsHeaders, true));
unpackEntries();
if (fNameConventionList.getSize() > 0) {
fNameConventionList.selectFirstElement();
} else {
fNameConventionList.enableButton(0, false);
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=38879
fUseKeywordThisBox= new SelectionButtonDialogField(SWT.CHECK | SWT.WRAP);
fUseKeywordThisBox.setLabelText(PreferencesMessages.getString("NameConventionConfigurationBlock.keywordthis.label")); //$NON-NLS-1$ fUseKeywordThisBox.setSelection(false);
fUseKeywordThisBox.setSelection(PreferenceConstants.getPreferenceStore().getBoolean(PREF_KEYWORD_THIS));
}
protected String[] getAllKeys() {
return new String[] {
PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES,
PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES
};
}
protected Control createContents(Composite parent) {
setShell(parent.getShell());
GridLayout layout= new GridLayout();
layout.numColumns= 2;
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayout(layout);
fNameConventionList.doFillIntoGrid(composite, 3);
LayoutUtil.setHorizontalSpan(fNameConventionList.getLabelControl(null), 2);
Table table= fNameConventionList.getTableViewer().getTable();
GridData data= (GridData)fNameConventionList.getListControl(null).getLayoutData();
data.grabExcessHorizontalSpace= true;
data.verticalAlignment= 0;
data.heightHint= SWTUtil.getTableHeightHint(table, 5);
fUseKeywordThisBox.doFillIntoGrid(composite, 2);
return composite;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String, java.lang.String)
*/
protected void validateSettings(String changedKey, String newValue) {
// no validation
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateControls()
*/
protected void updateControls() {
unpackEntries();
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
*/
protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
return null; // no build required
}
private void createEntry(List list, String prefixKey, String suffixKey, int kind) {
NameConventionEntry entry= new NameConventionEntry();
entry.kind= kind;
entry.suffixkey= suffixKey;
entry.prefixkey= prefixKey;
entry.suffix= (String) fWorkingValues.get(suffixKey);
entry.prefix= (String) fWorkingValues.get(prefixKey);
list.add(entry);
}
private void unpackEntries() {
ArrayList list= new ArrayList(4);
createEntry(list, PREF_FIELD_PREFIXES, PREF_FIELD_SUFFIXES, FIELD);
createEntry(list, PREF_STATIC_FIELD_PREFIXES, PREF_STATIC_FIELD_SUFFIXES, STATIC);
createEntry(list, PREF_ARGUMENT_PREFIXES, PREF_ARGUMENT_SUFFIXES, ARGUMENT);
createEntry(list, PREF_LOCAL_PREFIXES, PREF_LOCAL_SUFFIXES, LOCAL);
fNameConventionList.setElements(list);
}
private void packEntries() {
for (int i= 0; i < fNameConventionList.getSize(); i++) {
NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getElement(i);
fWorkingValues.put(entry.suffixkey, entry.suffix);
fWorkingValues.put(entry.prefixkey, entry.prefix);
}
}
private void doEditButtonPressed(int index) {
NameConventionEntry entry= (NameConventionEntry) fNameConventionList.getSelectedElements().get(0);
String title;
String message;
switch (entry.kind) {
case FIELD:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.field.dialog.message"); //$NON-NLS-1$
break;
case STATIC:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.static.dialog.message"); //$NON-NLS-1$
break;
case ARGUMENT:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.arg.dialog.message"); //$NON-NLS-1$
break;
default:
title= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.title"); //$NON-NLS-1$
message= PreferencesMessages.getString("NameConventionConfigurationBlock.local.dialog.message"); //$NON-NLS-1$
}
NameConventionInputDialog dialog= new NameConventionInputDialog(getShell(), title, message, entry);
if (dialog.open() == TodoTaskInputDialog.OK) {
fNameConventionList.replaceElement(entry, dialog.getResult());
}
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults()
*/
public void performDefaults() {
super.performDefaults();
IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
fUseKeywordThisBox.setSelection(prefs.getDefaultBoolean(PREF_KEYWORD_THIS));
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk(boolean)
*/
public boolean performOk(boolean enabled) {
IPreferenceStore prefs= PreferenceConstants.getPreferenceStore();
prefs.setValue(PREF_KEYWORD_THIS, fUseKeywordThisBox.isSelected());
JavaPlugin.getDefault().savePluginPreferences();
packEntries();
return super.performOk(enabled);
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.text.IJavaColorConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
/**
* Preference constants used in the JDT-UI preference store. Clients should only read the
* JDT-UI preference store using these values. Clients are not allowed to modify the
* preference store programmatically.
*
* @since 2.0
*/
public class PreferenceConstants {
private PreferenceConstants() {
}
/**
* A named preference that controls return type rendering of methods in the UI.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> return types
* are rendered
* </p>
*/
public static final String APPEARANCE_METHOD_RETURNTYPE= "org.eclipse.jdt.ui.methodreturntype";//$NON-NLS-1$
/**
* A named preference that controls if override indicators are rendered in the UI.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> override
* indicators are rendered
* </p>
*/
public static final String APPEARANCE_OVERRIDE_INDICATOR= "org.eclipse.jdt.ui.overrideindicator";//$NON-NLS-1$
/**
* A named preference that defines the pattern used for package name compression.
* <p>
* Value is of type <code>String</code>. For example foe the given package name 'org.eclipse.jdt' pattern
* '.' will compress it to '..jdt', '1~' to 'o~.e~.jdt'.
* </p>
*/
public static final String APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW= "PackagesView.pkgNamePatternForPackagesView";//$NON-NLS-1$
/**
* A named preference that controls if package name compression is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @see #APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW
*/
public static final String APPEARANCE_COMPRESS_PACKAGE_NAMES= "org.eclipse.jdt.ui.compresspackagenames";//$NON-NLS-1$
/**
* A named preference that controls if empty inner packages are folded in
* the hierarchical mode of the package explorer.
* <p>
* Value is of type <code>Boolean</code>: if <code>true</code> empty
* inner packages are folded.
* </p>
* @since 2.1
*/
public static final String APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER= "org.eclipse.jdt.ui.flatPackagesInPackageExplorer";//$NON-NLS-1$
/**
* A named preference that defines how member elements are ordered by the
* Java views using the <code>JavaElementSorter</code>.
* <p>
* Value is of type <code>String</code>: A comma separated list of the
* following entries. Each entry must be in the list, no duplication. List
* order defines the sort order.
* <ul>
* <li><b>T</b>: Types</li>
* <li><b>C</b>: Constructors</li>
* <li><b>I</b>: Initializers</li>
* <li><b>M</b>: Methods</li>
* <li><b>F</b>: Fields</li>
* <li><b>SI</b>: Static Initializers</li>
* <li><b>SM</b>: Static Methods</li>
* <li><b>SF</b>: Static Fields</li>
* </ul>
* </p>
* @since 2.1
*/
public static final String APPEARANCE_MEMBER_SORT_ORDER= "outlinesortoption"; //$NON-NLS-1$
/**
* A named preference that controls if prefix removal during setter/getter generation is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_USE_GETTERSETTER_PREFIX= "org.eclipse.jdt.ui.gettersetter.prefix.enable";//$NON-NLS-1$
/**
* A named preference that holds a list of prefixes to be removed from a local variable to compute setter
* and gettter names.
* <p>
* Value is of type <code>String</code>: comma separated list of prefixed
* </p>
*
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_GETTERSETTER_PREFIX= "org.eclipse.jdt.ui.gettersetter.prefix.list";//$NON-NLS-1$
/**
* A named preference that controls if suffix removal during setter/getter generation is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_PREFIXES and CODEASSIST_STATIC_FIELD_PREFIXES)
*/
public static final String CODEGEN_USE_GETTERSETTER_SUFFIX= "org.eclipse.jdt.ui.gettersetter.suffix.enable";//$NON-NLS-1$
/**
* A named preference that holds a list of suffixes to be removed from a local variable to compute setter
* and getter names.
* <p>
* Value is of type <code>String</code>: comma separated list of suffixes
* </p>
* @deprecated Use setting from JavaCore preference store (key JavaCore.
* CODEASSIST_FIELD_SUFFIXES and CODEASSIST_STATIC_FIELD_SUFFIXES)
*/
public static final String CODEGEN_GETTERSETTER_SUFFIX= "org.eclipse.jdt.ui.gettersetter.suffix.list"; //$NON-NLS-1$
/**
* A named preference that controls wheter the keyword "this" will be added
* automatically to field accesses in autogenerated methods.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 3.0
*/
public static final String CODEGEN_KEYWORD_THIS= "org.eclipse.jdt.ui.keywordthis"; //$NON-NLS-1$
/**
* A named preference that controls if comment stubs will be added
* automatically to newly created types and methods.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String CODEGEN_ADD_COMMENTS= "org.eclipse.jdt.ui.javadoc"; //$NON-NLS-1$
/**
* A named preference that controls if a comment stubs will be added
* automatocally to newly created types and methods.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated Use CODEGEN_ADD_COMMENTS instead (Name is more precice).
*/
public static final String CODEGEN__JAVADOC_STUBS= CODEGEN_ADD_COMMENTS;
/**
* A named preference that controls if a non-javadoc comment gets added to methods generated via the
* "Override Methods" operation.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated New code template story: user can
* specify the overriding method comment.
*/
public static final String CODEGEN__NON_JAVADOC_COMMENTS= "org.eclipse.jdt.ui.seecomments"; //$NON-NLS-1$
/**
* A named preference that controls if a file comment gets added to newly created files.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @deprecated New code template story: user can
* specify the new type code template.
*/
public static final String CODEGEN__FILE_COMMENTS= "org.eclipse.jdt.ui.filecomments"; //$NON-NLS-1$
/**
* A named preference that holds a list of comma separated package names. The list specifies the import order used by
* the "Organize Imports" opeation.
* <p>
* Value is of type <code>String</code>: semicolon separated list of package
* names
* </p>
*/
public static final String ORGIMPORTS_IMPORTORDER= "org.eclipse.jdt.ui.importorder"; //$NON-NLS-1$
/**
* A named preference that specifies the number of imports added before a star-import declaration is used.
* <p>
* Value is of type <code>Int</code>: positive value specifing the number of non star-import is used
* </p>
*/
public static final String ORGIMPORTS_ONDEMANDTHRESHOLD= "org.eclipse.jdt.ui.ondemandthreshold"; //$NON-NLS-1$
/**
* A named preferences that controls if types that start with a lower case letters get added by the
* "Organize Import" operation.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String ORGIMPORTS_IGNORELOWERCASE= "org.eclipse.jdt.ui.ignorelowercasenames"; //$NON-NLS-1$
/**
* A named preference that speficies whether children of a compilation unit are shown in the package explorer.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String SHOW_CU_CHILDREN= "org.eclipse.jdt.ui.packages.cuchildren"; //$NON-NLS-1$
/**
* A named preference that controls whether the package explorer's selection is linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String LINK_PACKAGES_TO_EDITOR= "org.eclipse.jdt.ui.packages.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the hierarchy view's selection is linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String LINK_TYPEHIERARCHY_TO_EDITOR= "org.eclipse.jdt.ui.packages.linktypehierarchytoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the projects view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_PROJECTS_TO_EDITOR= "org.eclipse.jdt.ui.browsing.projectstoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the packages view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_PACKAGES_TO_EDITOR= "org.eclipse.jdt.ui.browsing.packagestoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the types view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_TYPES_TO_EDITOR= "org.eclipse.jdt.ui.browsing.typestoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether the members view's selection is
* linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public static final String LINK_BROWSING_MEMBERS_TO_EDITOR= "org.eclipse.jdt.ui.browsing.memberstoeditor"; //$NON-NLS-1$
/**
* A named preference that controls whether new projects are generated using source and output folder.
* <p>
* Value is of type <code>Boolean</code>. if <code>true</code> new projects are created with a source and
* output folder. If <code>false</code> source and output folder equals to the project.
* </p>
*/
public static final String SRCBIN_FOLDERS_IN_NEWPROJ= "org.eclipse.jdt.ui.wizards.srcBinFoldersInNewProjects"; //$NON-NLS-1$
/**
* A named preference that specifies the source folder name used when creating a new Java project. Value is inactive
* if <code>SRCBIN_FOLDERS_IN_NEWPROJ</code> is set to <code>false</code>.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #SRCBIN_FOLDERS_IN_NEWPROJ
*/
public static final String SRCBIN_SRCNAME= "org.eclipse.jdt.ui.wizards.srcBinFoldersSrcName"; //$NON-NLS-1$
/**
* A named preference that specifies the output folder name used when creating a new Java project. Value is inactive
* if <code>SRCBIN_FOLDERS_IN_NEWPROJ</code> is set to <code>false</code>.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #SRCBIN_FOLDERS_IN_NEWPROJ
*/
public static final String SRCBIN_BINNAME= "org.eclipse.jdt.ui.wizards.srcBinFoldersBinName"; //$NON-NLS-1$
/**
* A named preference that holds a list of possible JRE libraries used by the New Java Project wizard. An library
* consists of a description and an arbitrary number of <code>IClasspathEntry</code>s, that will represent the
* JRE on the new project's classpath.
* <p>
* Value is of type <code>String</code>: a semicolon separated list of encoded JRE libraries.
* <code>NEWPROJECT_JRELIBRARY_INDEX</code> defines the currently used library. Clients
* should use the method <code>encodeJRELibrary</code> to encode a JRE library into a string
* and the methods <code>decodeJRELibraryDescription(String)</code> and <code>
* decodeJRELibraryClasspathEntries(String)</code> to decode the description and the array
* of classpath entries from an encoded string.
* </p>
*
* @see #NEWPROJECT_JRELIBRARY_INDEX
* @see #encodeJRELibrary(String, IClasspathEntry[])
* @see #decodeJRELibraryDescription(String)
* @see #decodeJRELibraryClasspathEntries(String)
*/
public static final String NEWPROJECT_JRELIBRARY_LIST= "org.eclipse.jdt.ui.wizards.jre.list"; //$NON-NLS-1$
/**
* A named preferences that specifies the current active JRE library.
* <p>
* Value is of type <code>Int</code>: an index into the list of possible JRE libraries.
* </p>
*
* @see #NEWPROJECT_JRELIBRARY_LIST
*/
public static final String NEWPROJECT_JRELIBRARY_INDEX= "org.eclipse.jdt.ui.wizards.jre.index"; //$NON-NLS-1$
/**
* A named preference that controls if a new type hierarchy gets opened in a
* new type hierarchy perspective or inside the type hierarchy view part.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE</code> or <code>
* OPEN_TYPE_HIERARCHY_IN_VIEW_PART</code>.
* </p>
*
* @see #OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE
* @see #OPEN_TYPE_HIERARCHY_IN_VIEW_PART
*/
public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.jdt.ui.openTypeHierarchy"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>OPEN_TYPE_HIERARCHY</code>.
*
* @see #OPEN_TYPE_HIERARCHY
*/
public static final String OPEN_TYPE_HIERARCHY_IN_PERSPECTIVE= "perspective"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>OPEN_TYPE_HIERARCHY</code>.
*
* @see #OPEN_TYPE_HIERARCHY
*/
public static final String OPEN_TYPE_HIERARCHY_IN_VIEW_PART= "viewPart"; //$NON-NLS-1$
/**
* A named preference that controls the behaviour when double clicking on a container in the packages view.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* DOUBLE_CLICK_GOES_INTO</code> or <code>
* DOUBLE_CLICK_EXPANDS</code>.
* </p>
*
* @see #DOUBLE_CLICK_EXPANDS
* @see #DOUBLE_CLICK_GOES_INTO
*/
public static final String DOUBLE_CLICK= "packageview.doubleclick"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>DOUBLE_CLICK</code>.
*
* @see #DOUBLE_CLICK
*/
public static final String DOUBLE_CLICK_GOES_INTO= "packageview.gointo"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>DOUBLE_CLICK</code>.
*
* @see #DOUBLE_CLICK
*/
public static final String DOUBLE_CLICK_EXPANDS= "packageview.doubleclick.expands"; //$NON-NLS-1$
/**
* A named preference that controls whether Java views update their presentation while editing or when saving the
* content of an editor.
* <p>
* Value is of type <code>String</code>: possible values are <code>
* UPDATE_ON_SAVE</code> or <code>
* UPDATE_WHILE_EDITING</code>.
* </p>
*
* @see #UPDATE_ON_SAVE
* @see #UPDATE_WHILE_EDITING
*/
public static final String UPDATE_JAVA_VIEWS= "JavaUI.update"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>UPDATE_JAVA_VIEWS</code>
*
* @see #UPDATE_JAVA_VIEWS
*/
public static final String UPDATE_ON_SAVE= "JavaUI.update.onSave"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>UPDATE_JAVA_VIEWS</code>
*
* @see #UPDATE_JAVA_VIEWS
*/
public static final String UPDATE_WHILE_EDITING= "JavaUI.update.whileEditing"; //$NON-NLS-1$
/**
* A named preference that holds the path of the Javadoc command used by the Javadoc creation wizard.
* <p>
* Value is of type <code>String</code>.
* </p>
*/
public static final String JAVADOC_COMMAND= "command"; //$NON-NLS-1$
/**
* A named preference that defines the key for the hover modifiers.
*
* @see JavaUI
* @since 2.1
*/
public static final String EDITOR_TEXT_HOVER_MODIFIERS= "hoverModifiers"; //$NON-NLS-1$
/**
* A named preference that defines the key for the hover modifier state masks.
* The value is only used if the value of <code>EDITOR_TEXT_HOVER_MODIFIERS</code>
* cannot be resolved to valid SWT modifier bits.
*
* @see JavaUI
* @see #EDITOR_TEXT_HOVER_MODIFIERS
* @since 2.1.1
*/
public static final String EDITOR_TEXT_HOVER_MODIFIER_MASKS= "hoverModifierMasks"; //$NON-NLS-1$
/**
* The id of the best match hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_BESTMATCH_HOVER= "org.eclipse.jdt.ui.BestMatchHover"; //$NON-NLS-1$
/**
* The id of the source code hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_SOURCE_HOVER= "org.eclipse.jdt.ui.JavaSourceHover"; //$NON-NLS-1$
/**
* The id of the javadoc hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_JAVADOC_HOVER= "org.eclipse.jdt.ui.JavadocHover"; //$NON-NLS-1$
/**
* The id of the problem hover contributed for extension point
* <code>javaEditorTextHovers</code>.
*
* @since 2.1
*/
public static String ID_PROBLEM_HOVER= "org.eclipse.jdt.ui.ProblemHover"; //$NON-NLS-1$
/**
* A named preference that controls whether bracket matching highlighting is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_MATCHING_BRACKETS= "matchingBrackets"; //$NON-NLS-1$
/**
* A named preference that holds the color used to highlight matching brackets.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_MATCHING_BRACKETS_COLOR= "matchingBracketsColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the current line highlighting is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_CURRENT_LINE= "currentLine"; //$NON-NLS-1$
/**
* A named preference that holds the color used to highlight the current line.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_CURRENT_LINE_COLOR= "currentLineColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the print margin is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_PRINT_MARGIN= "printMargin"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render the print margin.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_PRINT_MARGIN_COLOR= "printMarginColor"; //$NON-NLS-1$
/**
* Print margin column. Int value.
*/
public final static String EDITOR_PRINT_MARGIN_COLUMN= "printMarginColumn"; //$NON-NLS-1$
/**
* A named preference that holds the color used for the find/replace scope.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_FIND_SCOPE_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FIND_SCOPE;
/**
* A named preference that specifies if the editor uses spaces for tabs.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code>spaces instead of tabs are used
* in the editor. If <code>false</code> the editor inserts a tab character when pressing the tab
* key.
* </p>
*/
public final static String EDITOR_SPACES_FOR_TABS= "spacesForTabs"; //$NON-NLS-1$
/**
* A named preference that holds the number of spaces used per tab in the editor.
* <p>
* Value is of type <code>Int</code>: positive int value specifying the number of
* spaces per tab.
* </p>
*/
public final static String EDITOR_TAB_WIDTH= "org.eclipse.jdt.ui.editor.tab.width"; //$NON-NLS-1$
/**
* A named preference that controls whether the outline view selection
* should stay in sync with with the element at the current cursor position.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE= "JavaEditor.SyncOutlineOnCursorMove"; //$NON-NLS-1$
/**
* A named preference that controls if correction indicators are shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_CORRECTION_INDICATION= "JavaEditor.ShowTemporaryProblem"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows problem indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_PROBLEM_INDICATION= "problemIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render problem indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_PROBLEM_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_PROBLEM_INDICATION_COLOR= "problemIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows warning indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION= "warningIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render warning indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_WARNING_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION_COLOR= "warningIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows task indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION= "taskIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render task indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_TASK_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION_COLOR= "taskIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows bookmark
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION= "bookmarkIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render bookmark indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_BOOKMARK_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION_COLOR= "bookmarkIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows search
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION= "searchResultIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render search indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_SEARCH_RESULT_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION_COLOR= "searchResultIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the editor shows unknown
* indicators in text (squiggly lines).
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION= "othersIndication"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render unknown
* indicators.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see #EDITOR_UNKNOWN_INDICATION
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION_COLOR= "othersIndicationColor"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows error
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER= "errorIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows warning
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER= "warningIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows task
* indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER= "taskIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* bookmark indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER= "bookmarkIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* search result indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER= "searchResultIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the overview ruler shows
* unknown indicators.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER= "othersIndicationInOverviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close strings' feature
* is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_STRINGS= "closeStrings"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'wrap strings' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_WRAP_STRINGS= "wrapStrings"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close brackets' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_BRACKETS= "closeBrackets"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close braces' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_BRACES= "closeBraces"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'close java docs' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_CLOSE_JAVADOCS= "closeJavaDocs"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'add JavaDoc tags' feature
* is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_ADD_JAVADOC_TAGS= "addJavaDocTags"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'format Javadoc tags'
* feature is enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_FORMAT_JAVADOCS= "autoFormatJavaDocs"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'smart paste' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SMART_PASTE= "smartPaste"; //$NON-NLS-1$
/**
* A named preference that controls whether the 'smart home-end' feature is
* enabled.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_SMART_HOME_END= AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END;
/**
* A named preference that controls if temporary problems are evaluated and shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_EVALUTE_TEMPORARY_PROBLEMS= "handleTemporaryProblems"; //$NON-NLS-1$
/**
* A named preference that controls if the overview ruler is shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_OVERVIEW_RULER= "overviewRuler"; //$NON-NLS-1$
/**
* A named preference that controls if the line number ruler is shown in the UI.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_LINE_NUMBER_RULER= "lineNumberRuler"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render line numbers inside the line number ruler.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @see #EDITOR_LINE_NUMBER_RULER
*/
public final static String EDITOR_LINE_NUMBER_RULER_COLOR= "lineNumberColor"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render linked positions inside code templates.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_LINKED_POSITION_COLOR= "linkedPositionColor"; //$NON-NLS-1$
/**
* A named preference that holds the color used as the text foreground.
* This value has not effect if the system default color is used.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_FOREGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND;
/**
* A named preference that describes if the system default foreground color
* is used as the text foreground.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_FOREGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT;
/**
* A named preference that holds the color used as the text background.
* This value has not effect if the system default color is used.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_BACKGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND;
/**
* A named preference that describes if the system default background color
* is used as the text background.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_BACKGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT;
/**
* Preference key suffix for bold text style preference keys.
*
* @since 2.1
*/
public static final String EDITOR_BOLD_SUFFIX= "_bold"; //$NON-NLS-1$
/**
* A named preference that holds the color used to render multi line comments.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_MULTI_LINE_COMMENT_COLOR= IJavaColorConstants.JAVA_MULTI_LINE_COMMENT;
/**
* The symbolic font name for the Java editor text font
* (value <code>"org.eclipse.jdt.ui.editors.textfont"</code>).
*
* @since 2.1
*/
public final static String EDITOR_TEXT_FONT= "org.eclipse.jdt.ui.editors.textfont"; //$NON-NLS-1$
/**
* A named preference that controls whether multi line comments are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> multi line comments are rendered
* in bold. If <code>false</code> the are rendered using no font style attribute.
* </p>
*/
public final static String EDITOR_MULTI_LINE_COMMENT_BOLD= IJavaColorConstants.JAVA_MULTI_LINE_COMMENT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render single line comments.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_SINGLE_LINE_COMMENT_COLOR= IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT;
/**
* A named preference that controls whether sinle line comments are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> single line comments are rendered
* in bold. If <code>false</code> the are rendered using no font style attribute.
* </p>
*/
public final static String EDITOR_SINGLE_LINE_COMMENT_BOLD= IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render java keywords.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVA_KEYWORD_COLOR= IJavaColorConstants.JAVA_KEYWORD;
/**
* A named preference that controls whether keywords are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVA_KEYWORD_BOLD= IJavaColorConstants.JAVA_KEYWORD + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render string constants.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_STRING_COLOR= IJavaColorConstants.JAVA_STRING;
/**
* A named preference that controls whether string constants are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_STRING_BOLD= IJavaColorConstants.JAVA_STRING + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render java default text.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVA_DEFAULT_COLOR= IJavaColorConstants.JAVA_DEFAULT;
/**
* A named preference that controls whether Java default text is rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVA_DEFAULT_BOLD= IJavaColorConstants.JAVA_DEFAULT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render task tags.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_TASK_TAG_COLOR= IJavaColorConstants.TASK_TAG;
/**
* A named preference that controls whether task tags are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String EDITOR_TASK_TAG_BOLD= IJavaColorConstants.TASK_TAG + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc keywords.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_KEYWORD_COLOR= IJavaColorConstants.JAVADOC_KEYWORD;
/**
* A named preference that controls whether javadoc keywords are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_KEYWORD_BOLD= IJavaColorConstants.JAVADOC_KEYWORD + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc tags.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_TAG_COLOR= IJavaColorConstants.JAVADOC_TAG;
/**
* A named preference that controls whether javadoc tags are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_TAG_BOLD= IJavaColorConstants.JAVADOC_TAG + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc links.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_LINKS_COLOR= IJavaColorConstants.JAVADOC_LINK;
/**
* A named preference that controls whether javadoc links are rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_LINKS_BOLD= IJavaColorConstants.JAVADOC_LINK + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used to render javadoc default text.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String EDITOR_JAVADOC_DEFAULT_COLOR= IJavaColorConstants.JAVADOC_DEFAULT;
/**
* A named preference that controls whether javadoc default text is rendered in bold.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String EDITOR_JAVADOC_DEFAULT_BOLD= IJavaColorConstants.JAVADOC_DEFAULT + EDITOR_BOLD_SUFFIX;
/**
* A named preference that holds the color used for 'linked-mode' underline.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String EDITOR_LINK_COLOR= "linkColor"; //$NON-NLS-1$
/**
* A named preference that controls whether hover tooltips in the editor are turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String EDITOR_SHOW_HOVER= "org.eclipse.jdt.ui.editor.showHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when no control key is
* pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a hover
* contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_NONE_HOVER= "noneHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_CTRL_HOVER= "ctrlHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>SHIFT</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_SHIFT_HOVER= "shiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + ALT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
*/
public static final String EDITOR_CTRL_ALT_HOVER= "ctrlAltHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + ALT + SHIFT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
*/
public static final String EDITOR_CTRL_ALT_SHIFT_HOVER= "ctrlAltShiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>CTRL + SHIFT</code> modifier keys is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @since 2.1
* @deprecated Will be removed in one of the next builds.
*/
public static final String EDITOR_CTRL_SHIFT_HOVER= "ctrlShiftHover"; //$NON-NLS-1$
/**
* A named preference that defines the hover shown when the
* <code>ALT</code> modifier key is pressed.
* <p>Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code>,
* <code>EDITOR_DEFAULT_HOVER_CONFIGURED_ID</code> or the hover id of a
* hover contributed as <code>javaEditorTextHovers</code>.
* </p>
* @see #EDITOR_NO_HOVER_CONFIGURED_ID
* @see #EDITOR_DEFAULT_HOVER_CONFIGURED_ID
* @see JavaUI ID_*_HOVER
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
* @since 2.1
*/
public static final String EDITOR_ALT_SHIFT_HOVER= "altShiftHover"; //$NON-NLS-1$
/**
* A string value used by the named preferences for hover configuration to
* descibe that no hover should be shown for the given key modifiers.
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
* @since 2.1
*/
public static final String EDITOR_NO_HOVER_CONFIGURED_ID= "noHoverConfiguredId"; //$NON-NLS-1$
/**
* A string value used by the named preferences for hover configuration to
* descibe that the default hover should be shown for the given key
* modifiers. The default hover is described by the
* <code>EDITOR_DEFAULT_HOVER</code> property.
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_DEFAULT_HOVER_CONFIGURED_ID= "defaultHoverConfiguredId"; //$NON-NLS-1$
/**
* A named preference that defines the hover named the 'default hover'.
* Value is of type <code>String</code>: possible values are <code>
* EDITOR_NO_HOVER_CONFIGURED_ID</code> or <code> the hover id of a hover
* contributed as <code>javaEditorTextHovers</code>.
* </p>
* @since 2.1
* @deprecated Will soon be removed - replaced by {@link #EDITOR_TEXT_HOVER_MODIFIERS}
*/
public static final String EDITOR_DEFAULT_HOVER= "defaultHover"; //$NON-NLS-1$
/**
* A named preference that controls if segmented view (show selected element only) is turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String EDITOR_SHOW_SEGMENTS= "org.eclipse.jdt.ui.editor.showSegments"; //$NON-NLS-1$
/**
* A named preference that controls if browser like links are turned on or off.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 2.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS= "browserLikeLinks"; //$NON-NLS-1$
/**
* A named preference that controls the key modifier for browser like links.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @since 2.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER= "browserLikeLinksKeyModifier"; //$NON-NLS-1$
/**
* A named preference that controls the key modifier mask for browser like links.
* The value is only used if the value of <code>EDITOR_BROWSER_LIKE_LINKS</code>
* cannot be resolved to valid SWT modifier bits.
* <p>
* Value is of type <code>String</code>.
* </p>
*
* @see #EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER
* @since 2.1.1
*/
public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK= "browserLikeLinksKeyModifierMask"; //$NON-NLS-1$
/**
* A named preference that controls disabling of the overwrite mode.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_DISABLE_OVERWRITE_MODE= "disable_overwrite_mode"; //$NON-NLS-1$
/**
* A named preference that controls the "smart semicolon" smart typing handler
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_SMART_SEMICOLON= "smart_semicolon"; //$NON-NLS-1$
/**
* A named preference that controls the "smart opening brace" smart typing handler
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.0
*/
public static final String EDITOR_SMART_OPENING_BRACE= "smart_opening_brace"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist gets auto activated.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION= "content_assist_autoactivation"; //$NON-NLS-1$
/**
* A name preference that holds the auto activation delay time in milli seconds.
* <p>
* Value is of type <code>Int</code>.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_DELAY= "content_assist_autoactivation_delay"; //$NON-NLS-1$
/**
* A named preference that controls if code assist contains only visible proposals.
* <p>
* Value is of type <code>Boolean</code>. if <code>true<code> code assist only contains visible members. If
* <code>false</code> all members are included.
* </p>
*/
public final static String CODEASSIST_SHOW_VISIBLE_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist inserts a
* proposal automatically if only one proposal is available.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_AUTOINSERT= "content_assist_autoinsert"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist adds import
* statements.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_ADDIMPORT= "content_assist_add_import"; //$NON-NLS-1$
/**
* A named preference that controls if the Java code assist only inserts
* completions. If set to false the proposals can also _replace_ code.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_INSERT_COMPLETION= "content_assist_insert_completion"; //$NON-NLS-1$
/**
* A named preference that controls whether code assist proposals filtering is case sensitive or not.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_CASE_SENSITIVITY= "content_assist_case_sensitivity"; //$NON-NLS-1$
/**
* A named preference that defines if code assist proposals are sorted in alphabetical order.
* <p>
* Value is of type <code>Boolean</code>. If <code>true</code> that are sorted in alphabetical
* order. If <code>false</code> that are unsorted.
* </p>
*/
public final static String CODEASSIST_ORDER_PROPOSALS= "content_assist_order_proposals"; //$NON-NLS-1$
/**
* A named preference that controls if argument names are filled in when a method is selected from as list
* of code assist proposal.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public final static String CODEASSIST_FILL_ARGUMENT_NAMES= "content_assist_fill_method_arguments"; //$NON-NLS-1$
/**
* A named preference that controls if method arguments are guessed when a
* method is selected from as list of code assist proposal.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
* @since 2.1
*/
public final static String CODEASSIST_GUESS_METHOD_ARGUMENTS= "content_assist_guess_method_arguments"; //$NON-NLS-1$
/**
* A named preference that holds the characters that auto activate code assist in Java code.
* <p>
* Value is of type <code>Sring</code>. All characters that trigger auto code assist in Java code.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA= "content_assist_autoactivation_triggers_java"; //$NON-NLS-1$
/**
* A named preference that holds the characters that auto activate code assist in Javadoc.
* <p>
* Value is of type <code>Sring</code>. All characters that trigger auto code assist in Javadoc.
* </p>
*/
public final static String CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC= "content_assist_autoactivation_triggers_javadoc"; //$NON-NLS-1$
/**
* A named preference that holds the background color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PROPOSALS_BACKGROUND= "content_assist_proposals_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PROPOSALS_FOREGROUND= "content_assist_proposals_foreground"; //$NON-NLS-1$
/**
* A named preference that holds the background color used for parameter hints.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PARAMETERS_BACKGROUND= "content_assist_parameters_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code assist selection dialog.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
*/
public final static String CODEASSIST_PARAMETERS_FOREGROUND= "content_assist_parameters_foreground"; //$NON-NLS-1$
/**
* A named preference that holds the background color used in the code
* assist selection dialog to mark replaced code.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String CODEASSIST_REPLACEMENT_BACKGROUND= "content_assist_completion_replacement_background"; //$NON-NLS-1$
/**
* A named preference that holds the foreground color used in the code
* assist selection dialog to mark replaced code.
* <p>
* Value is of type <code>String</code>. A RGB color value encoded as a string
* using class <code>PreferenceConverter</code>
* </p>
*
* @see org.eclipse.jface.resource.StringConverter
* @see org.eclipse.jface.preference.PreferenceConverter
* @since 2.1
*/
public final static String CODEASSIST_REPLACEMENT_FOREGROUND= "content_assist_completion_replacement_foreground"; //$NON-NLS-1$
/**
* A named preference that controls the behaviour of the refactoring wizard for showing the error page.
* <p>
* Value is of type <code>String</code>. Valid values are:
* <code>REFACTOR_FATAL_SEVERITY</code>,
* <code>REFACTOR_ERROR_SEVERITY</code>,
* <code>REFACTOR_WARNING_SEVERITY</code>
* <code>REFACTOR_INFO_SEVERITY</code>,
* <code>REFACTOR_OK_SEVERITY</code>.
* </p>
*
* @see #REFACTOR_FATAL_SEVERITY
* @see #REFACTOR_ERROR_SEVERITY
* @see #REFACTOR_WARNING_SEVERITY
* @see #REFACTOR_INFO_SEVERITY
* @see #REFACTOR_OK_SEVERITY
*/
public static final String REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD= "Refactoring.ErrorPage.severityThreshold"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_FATAL_SEVERITY= "4"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_ERROR_SEVERITY= "3"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_WARNING_SEVERITY= "2"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_INFO_SEVERITY= "1"; //$NON-NLS-1$
/**
* A string value used by the named preference <code>REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD</code>.
*
* @see #REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD
*/
public static final String REFACTOR_OK_SEVERITY= "0"; //$NON-NLS-1$
/**
* A named preference thet controls whether all dirty editors are automatically saved before a refactoring is
* executed.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String REFACTOR_SAVE_ALL_EDITORS= "Refactoring.savealleditors"; //$NON-NLS-1$
/**
* A named preference that controls if the Java Browsing views are linked to the active editor.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @see #LINK_PACKAGES_TO_EDITOR
*/
public static final String BROWSING_LINK_VIEW_TO_EDITOR= "org.eclipse.jdt.ui.browsing.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls the layout of the Java Browsing views vertically. Boolean value.
* <p>
* Value is of type <code>Boolean</code>. If <code>true<code> the views are stacked vertical.
* If <code>false</code> they are stacked horizontal.
* </p>
*/
public static final String BROWSING_STACK_VERTICALLY= "org.eclipse.jdt.ui.browsing.stackVertically"; //$NON-NLS-1$
/**
* A named preference that controls if templates are formatted when applied.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 2.1
*/
public static final String TEMPLATES_USE_CODEFORMATTER= "org.eclipse.jdt.ui.template.format"; //$NON-NLS-1$
/**
* Initializes the given preference store with the default values.
*
* @param store the preference store to be initialized
*
* @since 2.1
*/
public static void initializeDefaultValues(IPreferenceStore store) {
store.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false);
// JavaBasePreferencePage
store.setDefault(PreferenceConstants.LINK_PACKAGES_TO_EDITOR, false);
store.setDefault(PreferenceConstants.LINK_TYPEHIERARCHY_TO_EDITOR, false);
store.setDefault(PreferenceConstants.OPEN_TYPE_HIERARCHY, PreferenceConstants.OPEN_TYPE_HIERARCHY_IN_VIEW_PART);
store.setDefault(PreferenceConstants.DOUBLE_CLICK, PreferenceConstants.DOUBLE_CLICK_EXPANDS);
store.setDefault(PreferenceConstants.UPDATE_JAVA_VIEWS, PreferenceConstants.UPDATE_WHILE_EDITING);
store.setDefault(PreferenceConstants.LINK_BROWSING_PROJECTS_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_PACKAGES_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_TYPES_TO_EDITOR, true);
store.setDefault(PreferenceConstants.LINK_BROWSING_MEMBERS_TO_EDITOR, true);
// AppearancePreferencePage
store.setDefault(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES, false);
store.setDefault(PreferenceConstants.APPEARANCE_METHOD_RETURNTYPE, false);
store.setDefault(PreferenceConstants.SHOW_CU_CHILDREN, true);
store.setDefault(PreferenceConstants.APPEARANCE_OVERRIDE_INDICATOR, true);
store.setDefault(PreferenceConstants.BROWSING_STACK_VERTICALLY, false);
store.setDefault(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW, ""); //$NON-NLS-1$
store.setDefault(PreferenceConstants.APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER, true);
// ImportOrganizePreferencePage
store.setDefault(PreferenceConstants.ORGIMPORTS_IMPORTORDER, "java;javax;org;com"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD, 99);
store.setDefault(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE, true);
// ClasspathVariablesPreferencePage
// CodeFormatterPreferencePage
// CompilerPreferencePage
// no initialization needed
// RefactoringPreferencePage
store.setDefault(PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD, PreferenceConstants.REFACTOR_ERROR_SEVERITY);
store.setDefault(PreferenceConstants.REFACTOR_SAVE_ALL_EDITORS, false);
// TemplatePreferencePage
store.setDefault(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER, true);
// CodeGenerationPreferencePage
// compatibility code
if (store.getBoolean(PreferenceConstants.CODEGEN_USE_GETTERSETTER_PREFIX)) {
String prefix= store.getString(PreferenceConstants.CODEGEN_GETTERSETTER_PREFIX);
if (prefix.length() > 0) {
JavaCore.getPlugin().getPluginPreferences().setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, prefix);
store.setToDefault(PreferenceConstants.CODEGEN_USE_GETTERSETTER_PREFIX);
store.setToDefault(PreferenceConstants.CODEGEN_GETTERSETTER_PREFIX);
}
}
if (store.getBoolean(PreferenceConstants.CODEGEN_USE_GETTERSETTER_SUFFIX)) {
String suffix= store.getString(PreferenceConstants.CODEGEN_GETTERSETTER_SUFFIX);
if (suffix.length() > 0) {
JavaCore.getPlugin().getPluginPreferences().setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, suffix);
store.setToDefault(PreferenceConstants.CODEGEN_USE_GETTERSETTER_SUFFIX);
store.setToDefault(PreferenceConstants.CODEGEN_GETTERSETTER_SUFFIX);
}
}
store.setDefault(PreferenceConstants.CODEGEN_KEYWORD_THIS, false);
store.setDefault(PreferenceConstants.CODEGEN_ADD_COMMENTS, true);
// MembersOrderPreferencePage
store.setDefault(PreferenceConstants.APPEARANCE_MEMBER_SORT_ORDER, "T,SI,SF,SM,I,F,C,M"); //$NON-NLS-1$
// must add here to guarantee that it is the first in the listener list
store.addPropertyChangeListener(JavaPlugin.getDefault().getMemberOrderPreferenceCache());
// JavaEditorPreferencePage
store.setDefault(PreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR, new RGB(192, 192,192));
store.setDefault(PreferenceConstants.EDITOR_CURRENT_LINE, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_CURRENT_LINE_COLOR, new RGB(225, 235, 224));
store.setDefault(PreferenceConstants.EDITOR_PRINT_MARGIN, false);
store.setDefault(PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 80);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, new RGB(176, 180 , 185));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_FIND_SCOPE_COLOR, new RGB(185, 176 , 180));
store.setDefault(PreferenceConstants.EDITOR_PROBLEM_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_PROBLEM_INDICATION_COLOR, new RGB(255, 0 , 128));
store.setDefault(PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_WARNING_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR, new RGB(244, 200 , 45));
store.setDefault(PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_TASK_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_TASK_INDICATION_COLOR, new RGB(0, 128, 255));
store.setDefault(PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_BOOKMARK_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR, new RGB(34, 164, 99));
store.setDefault(PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR, new RGB(192, 192, 192));
store.setDefault(PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_UNKNOWN_INDICATION, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR, new RGB(0, 0, 0));
store.setDefault(PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER, false);
store.setDefault(PreferenceConstants.EDITOR_CORRECTION_INDICATION, true);
store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true);
store.setDefault(PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, true);
store.setDefault(PreferenceConstants.EDITOR_OVERVIEW_RULER, true);
store.setDefault(PreferenceConstants.EDITOR_LINE_NUMBER_RULER, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINKED_POSITION_COLOR, new RGB(0, 200 , 100));
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_LINK_COLOR, new RGB(0, 0, 255));
store.setDefault(PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR, true);
store.setDefault(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR, true);
store.setDefault(PreferenceConstants.EDITOR_TAB_WIDTH, 4);
store.setDefault(PreferenceConstants.EDITOR_SPACES_FOR_TABS, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR, new RGB(63, 127, 95));
store.setDefault(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR, new RGB(63, 127, 95));
store.setDefault(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR, new RGB(127, 0, 85));
store.setDefault(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_STRING_COLOR, new RGB(42, 0, 255));
store.setDefault(PreferenceConstants.EDITOR_STRING_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR, new RGB(0, 0, 0));
store.setDefault(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_TASK_TAG_COLOR, new RGB(127, 159, 191));
store.setDefault(PreferenceConstants.EDITOR_TASK_TAG_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR, new RGB(127, 159, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_KEYWORD_BOLD, true);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR, new RGB(127, 127, 159));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR, new RGB(63, 63, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD, false);
PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR, new RGB(63, 95, 191));
store.setDefault(PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD, false);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION, true);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY, 500);
store.setDefault(PreferenceConstants.CODEASSIST_AUTOINSERT, true);
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, new RGB(254, 241, 233));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND, new RGB(254, 241, 233));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND, new RGB(0, 0, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, new RGB(255, 255, 0));
PreferenceConverter.setDefault(store, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, new RGB(255, 0, 0));
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA, "."); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC, "@"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS, true);
store.setDefault(PreferenceConstants.CODEASSIST_CASE_SENSITIVITY, false);
store.setDefault(PreferenceConstants.CODEASSIST_ORDER_PROPOSALS, false);
store.setDefault(PreferenceConstants.CODEASSIST_ADDIMPORT, true);
store.setDefault(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, true);
store.setDefault(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, false);
store.setDefault(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, true);
store.setDefault(PreferenceConstants.EDITOR_SMART_HOME_END, true);
store.setDefault(PreferenceConstants.EDITOR_SMART_PASTE, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_STRINGS, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACKETS, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACES, true);
store.setDefault(PreferenceConstants.EDITOR_CLOSE_JAVADOCS, true);
store.setDefault(PreferenceConstants.EDITOR_WRAP_STRINGS, true);
store.setDefault(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, true);
store.setDefault(PreferenceConstants.EDITOR_FORMAT_JAVADOCS, false);
String ctrl= Action.findModifierString(SWT.CTRL);
store.setDefault(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS, "org.eclipse.jdt.ui.BestMatchHover;0;org.eclipse.jdt.ui.JavaSourceHover;" + ctrl); //$NON-NLS-1$
store.setDefault(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS, "org.eclipse.jdt.ui.BestMatchHover;0;org.eclipse.jdt.ui.JavaSourceHover;" + SWT.CTRL); //$NON-NLS-1$
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, true);
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, ctrl);
store.setDefault(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK, SWT.CTRL);
// work in progress
store.setDefault(PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE, false);
store.setDefault(PreferenceConstants.EDITOR_SMART_SEMICOLON, false);
store.setDefault(PreferenceConstants.EDITOR_SMART_OPENING_BRACE, false);
// do more complicated stuff
NewJavaProjectPreferencePage.initDefaults(store);
}
/**
* Returns the JDT-UI preference store.
*
* @return the JDT-UI preference store
*/
public static IPreferenceStore getPreferenceStore() {
return JavaPlugin.getDefault().getPreferenceStore();
}
/**
* Encodes a JRE library to be used in the named preference <code>NEWPROJECT_JRELIBRARY_LIST</code>.
*
* @param description a string value describing the JRE library. The description is used
* to indentify the JDR library in the UI
* @param entries an array of classpath entries to be encoded
*
* @return the encoded string.
*/
public static String encodeJRELibrary(String description, IClasspathEntry[] entries) {
return NewJavaProjectPreferencePage.encodeJRELibrary(description, entries);
}
/**
* Decodes an encoded JRE library and returns its description string.
*
* @return the description of an encoded JRE library
*
* @see #encodeJRELibrary(String, IClasspathEntry[])
*/
public static String decodeJRELibraryDescription(String encodedLibrary) {
return NewJavaProjectPreferencePage.decodeJRELibraryDescription(encodedLibrary);
}
/**
* Decodes an encoded JRE library and returns its classpath entries.
*
* @return the array of classpath entries of an encoded JRE library.
*
* @see #encodeJRELibrary(String, IClasspathEntry[])
*/
public static IClasspathEntry[] decodeJRELibraryClasspathEntries(String encodedLibrary) {
return NewJavaProjectPreferencePage.decodeJRELibraryClasspathEntries(encodedLibrary);
}
/**
* Returns the current configuration for the JRE to be used as default in new Java projects.
* This is a convenience method to access the named preference <code>NEWPROJECT_JRELIBRARY_LIST
* </code> with the index defined by <code> NEWPROJECT_JRELIBRARY_INDEX</code>.
*
* @return the current default set of classpath entries
*
* @see #NEWPROJECT_JRELIBRARY_LIST
* @see #NEWPROJECT_JRELIBRARY_INDEX
*/
public static IClasspathEntry[] getDefaultJRELibrary() {
return NewJavaProjectPreferencePage.getDefaultJRELibrary();
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddDelegateMethodsAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2002 International Business Machines Corp. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Martin Moebius
* *****************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddDelegateMethodsOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.AddDelegateMethodsOperation.Methods2Field;
import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
/**
* Creates delegate methods for a type's fields. Opens a dialog with a list of
* fields for which delegate methods can be generated. User is able to check or
* uncheck items before methods are generated.
* <p>
* Will open the parent compilation unit in a Java editor. The result is
* unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IField</code> or <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* Contributors:
* Martin Moebius: [email protected] - bug: 28793
* @since 2.1
*/
public class AddDelegateMethodsAction extends SelectionDispatchAction {
private static final String DIALOG_TITLE = ActionMessages.getString("AddDelegateMethodsAction.error.title"); //$NON-NLS-1$
private CompilationUnitEditor fEditor;
/**
* Creates a new <code>AddDelegateMethodsAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddDelegateMethodsAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddDelegateMethodsAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddDelegateMethodsAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddDelegateMethodsAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_DELEGATE_METHODS_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddDelegateMethodsAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor = editor;
setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null);
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if (getSelectedFields(selection) != null)
return true;
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
try {
IField[] selectedFields = getSelectedFields(selection);
if (canRunOn(selectedFields)) {
run(selectedFields[0].getDeclaringType(), selectedFields, false);
return;
}
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IType)
run((IType) firstElement, new IField[0], false);
else if (firstElement instanceof ICompilationUnit)
run(JavaElementUtil.getMainType((ICompilationUnit) firstElement), new IField[0], false);
else
MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.error.actionfailed")); //$NON-NLS-1$
}
}
private static boolean canRunOn(IType type) throws JavaModelException {
if (type == null || type.getCompilationUnit() == null || type.isInterface())
return false;
return canRunOn(type.getFields());
}
private static boolean canRunOn(IField[] fields) throws JavaModelException {
if (fields == null) {
return false;
}
int count = 0;
for (int i = 0; i < fields.length; i++) {
if (!hasPrimitiveType(fields[i]) || isArray(fields[i])) {
count++;
}
}
return (count > 0);
}
/*
* Returns fields in the selection or <code>null</code> if the selection is
* empty or not valid.
*/
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements = selection.toList();
int nElements = elements.size();
if (nElements > 0) {
IField[] res = new IField[nElements];
ICompilationUnit cu = null;
for (int i = 0; i < nElements; i++) {
Object curr = elements.get(i);
if (curr instanceof IField) {
IField fld = (IField) curr;
if (i == 0) {
// remember the cu of the first element
cu = fld.getCompilationUnit();
if (cu == null) {
return null;
}
} else if (!cu.equals(fld.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
if (fld.getDeclaringType().isInterface()) {
// no delegates for fields in interfaces or fields with
return null;
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
return null;
}
res[i] = fld;
} else {
return null;
}
}
return res;
}
return null;
}
private void run(IType type, IField[] preselected, boolean editor) throws CoreException {
if (!ElementValidator.check(type, getShell(), DIALOG_TITLE, editor))
return;
if (!ActionUtil.isProcessable(getShell(), type))
return;
if(!canRunOn(type)){
MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.not_applicable")); //$NON-NLS-1$
return;
}
showUI(type, preselected);
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
try {
IJavaElement input= SelectionConverter.getInput(fEditor);
if (!ActionUtil.isProcessable(getShell(), input))
return;
IJavaElement[] elements = SelectionConverter.codeResolve(fEditor);
if (elements.length == 1 && (elements[0] instanceof IField)) {
IField field = (IField) elements[0];
run(field.getDeclaringType(), new IField[] { field }, true);
return;
}
IJavaElement element = SelectionConverter.getElementAtOffset(fEditor);
if (element != null) {
IType type = (IType) element.getAncestor(IJavaElement.TYPE);
if (type != null) {
if (type.getFields().length > 0) {
run(type, new IField[0], true);
return;
}
}
}
MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.error.actionfailed")); //$NON-NLS-1$
}
}
//---- Helpers -------------------------------------------------------------------
private static class AddDelegateMethodsActionStatusValidator implements ISelectionStatusValidator {
private static int fEntries;
AddDelegateMethodsActionStatusValidator(int entries) {
fEntries= entries;
}
public IStatus validate(Object[] selection) {
StatusInfo state = new StatusInfo();
if (selection != null && selection.length > 0) {
HashSet map = new HashSet(selection.length);
int count = 0;
for (int i = 0; i < selection.length; i++) {
Object key = selection[i];
if (selection[i] instanceof Methods2Field) {
count++;
try {
key = createSignatureKey(((Methods2Field) selection[i]).fMethod);
} catch (JavaModelException e) {
return new StatusInfo(StatusInfo.ERROR, e.toString());
}
}
if (!map.add(key)) { //$NON-NLS-1$
state = new StatusInfo(IStatus.ERROR, ActionMessages.getString("AddDelegateMethodsAction.duplicate_methods")); //$NON-NLS-1$
break;
} else {
String message;
message = ActionMessages.getFormattedString("AddDelegateMethodsAction.selectioninfo.more", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
state = new StatusInfo(IStatus.INFO, message);
}
}
}
else
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
return state;
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddDelegateMethodsActionStatusValidator validator= new AddDelegateMethodsActionStatusValidator(entries);
return validator;
}
private void showUI(IType type, IField[] preselected) {
try {
AddDelegateMethodsContentProvider provider = new AddDelegateMethodsContentProvider(type);
Methods2FieldLabelProvider methodLabel = new Methods2FieldLabelProvider();
SourceActionDialog dialog = new SourceActionDialog(getShell(), methodLabel, provider, fEditor, type);
dialog.setValidator(createValidator(provider.getNumEntries()));
Methods2FieldSorter sorter= new Methods2FieldSorter();
dialog.setSorter(sorter);
dialog.setInput(new Object());
dialog.setContainerMode(true);
dialog.setMessage(ActionMessages.getString("AddDelegateMethodsAction.message")); //$NON-NLS-1$
dialog.setTitle(ActionMessages.getString("AddDelegateMethodsAction.title")); //$NON-NLS-1$
Object[] elements= provider.getElements(null);
sorter.sort(null, elements);
Object[] expand= {elements[0]};
dialog.setExpandedElements(expand);
dialog.setInitialSelections(preselected);
dialog.setSize(60, 18);
int result = dialog.open();
if (result == Window.OK) {
Object[] o = dialog.getResult();
if (o == null)
return;
ArrayList methods = new ArrayList(o.length);
for (int i = 0; i < o.length; i++) {
if (o[i] instanceof Methods2Field)
methods.add(o[i]);
}
IEditorPart part = EditorUtility.openInEditor(type);
type = (IType) JavaModelUtil.toWorkingCopy(type);
IRewriteTarget target= (IRewriteTarget) part.getAdapter(IRewriteTarget.class);
IMethod[] createdMethods= null;
try {
if (target != null) {
target.beginCompoundChange();
}
// pass dialog based information to the operation
IJavaElement elementPosition= dialog.getElementPosition();
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= dialog.getGenerateComment();
createdMethods= processResults(methods, type, elementPosition, settings);
} finally {
if (target != null) {
target.endCompoundChange();
}
}
if (createdMethods != null && createdMethods.length > 0) {
type.getCompilationUnit().reconcile();
EditorUtility.revealInEditor(part, createdMethods[0]);
}
}
} catch (CoreException e) {
ExceptionHandler.handle(e, DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.error.actionfailed")); //$NON-NLS-1$
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, DIALOG_TITLE, ActionMessages.getString("AddDelegateMethodsAction.error.actionfailed")); //$NON-NLS-1$
}
}
/**creates methods in class*/
private IMethod[] processResults(List list, IType type, IJavaElement elementPosition, CodeGenerationSettings settings) throws InvocationTargetException {
if (list.size() == 0)
return null;
AddDelegateMethodsOperation op = new AddDelegateMethodsOperation(list, settings, type, elementPosition);
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
try {
context.run(false, true, new WorkbenchRunnableAdapter(op));
} catch (InterruptedException e) {
// cancel pressed
return null;
}
return op.getCreatedMethods();
}
/** The model (content provider) for the field-methods tree */
private static class AddDelegateMethodsContentProvider implements ISourceActionContentProvider {
private Map fTreeMap= null;
private Map fFieldMap= null;
private Map fFilter= null;
private int fNumEntries;
/**
* Method FieldContentProvider.
* @param type outer type to insert in (hide final methods in tree))
*/
AddDelegateMethodsContentProvider(IType type) throws JavaModelException {
fFilter= new HashMap(); //hiding final methods
fTreeMap= new TreeMap(); //mapping name to methods
fFieldMap= new HashMap(); //mapping name to field
fNumEntries= buildModel(type);
}
public int getNumEntries() {
return fNumEntries;
}
/* Builds the entry list for the tree, and returns the number of entries in it */
private int buildModel(IType type) throws JavaModelException {
int numEntries= 0;
IField[] fields = type.getFields();
//build map to filter against
IMethod[] finMeths = resolveFinalMethods(type);
for (int i = 0; i < finMeths.length; i++) {
fFilter.put(createSignatureKey(finMeths[i]), finMeths[i]);
}
IMethod[] filter = type.getMethods();
for (int i = 0; i < filter.length; i++) {
fFilter.put(createSignatureKey(filter[i]), filter[i]);
}
for (int i = 0; i < fields.length; i++) {
IType fieldType = resolveTypeOfField(fields[i]);
if (fieldType == null)
continue;
IMethod[] methods = resolveMethodsHierarchy(fieldType);
List accessMethods = new ArrayList();
//show public methods; hide constructors + final methods
for (int j = 0; j < methods.length; j++) {
boolean publicField = JdtFlags.isPublic(methods[j]);
boolean constructor = methods[j].isConstructor();
boolean finalExist = fFilter.get(createSignatureKey(methods[j])) != null;
if (publicField && !constructor && !finalExist) {
accessMethods.add(new Methods2Field(methods[j], fields[i]));
numEntries++;
}
}
Object[] m = accessMethods.toArray();
Methods2Field[] mf = new Methods2Field[m.length];
for (int j = 0; j < m.length; j++) {
mf[j] = (Methods2Field) m[j];
}
fTreeMap.put(fields[i].getElementName(), mf);
fFieldMap.put(fields[i].getElementName(), fields[i]);
}
return numEntries;
}
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IField) {
return (Object[]) fTreeMap.get(((IField) parentElement).getElementName());
}
return null;
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return element instanceof IField;
}
public Object[] getElements(Object inputElement) {
Object[] o = fTreeMap.keySet().toArray();
Object[] fields = new Object[o.length];
for (int i = 0; i < o.length; i++) {
fields[i] = fFieldMap.get(o[i]);
}
return fields;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public int getInsertPosition() {
return 0;
}
public void setInsertPosition(int insert) {
}
}
/**just to wrap JavaElementLabelProvider using my Methods2Field*/
private static class Methods2FieldLabelProvider implements ILabelProvider {
/**Delegate to forward calls*/
JavaElementLabelProvider fMethodLabel = null;
public Methods2FieldLabelProvider() {
fMethodLabel = new JavaElementLabelProvider();
fMethodLabel.turnOn(JavaElementLabelProvider.SHOW_TYPE);
}
public Image getImage(Object element) {
if (element instanceof Methods2Field) {
Methods2Field wrapper = (Methods2Field) element;
return fMethodLabel.getImage(wrapper.fMethod);
} else if (element instanceof IJavaElement) {
return fMethodLabel.getImage(element);
}
return null;
}
public String getText(Object element) {
if (element instanceof Methods2Field) {
Methods2Field wrapper = (Methods2Field) element;
return fMethodLabel.getText(wrapper.fMethod);
} else if (element instanceof IJavaElement) {
return fMethodLabel.getText(element);
}
return null;
}
public void addListener(ILabelProviderListener listener) {
fMethodLabel.addListener(listener);
}
public void dispose() {
fMethodLabel.dispose();
}
public boolean isLabelProperty(Object element, String property) {
return fMethodLabel.isLabelProperty(element, property);
}
public void removeListener(ILabelProviderListener listener) {
fMethodLabel.removeListener(listener);
}
}
/** and a delegate for the sorter*/
private static class Methods2FieldSorter extends ViewerSorter {
JavaElementSorter fSorter = new JavaElementSorter();
public int category(Object element) {
if (element instanceof Methods2Field)
element = ((Methods2Field) element).fMethod;
return fSorter.category(element);
}
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof Methods2Field)
e1 = ((Methods2Field) e1).fMethod;
if (e2 instanceof Methods2Field)
e2 = ((Methods2Field) e2).fMethod;
return fSorter.compare(viewer, e1, e2);
}
public Collator getCollator() {
return fSorter.getCollator();
}
}
/**return all methods of all super types, minus dups*/
private static IMethod[] resolveMethodsHierarchy(IType type) throws JavaModelException {
Map map = new HashMap();
IType[] superTypes = JavaModelUtil.getAllSuperTypes(type, new NullProgressMonitor());
addMethodsToMapping(map, type);
for (int i = 0; i < superTypes.length; i++) {
addMethodsToMapping(map, superTypes[i]);
}
return (IMethod[]) map.values().toArray(new IMethod[map.values().size()]);
}
private static void addMethodsToMapping(Map map, IType type) throws JavaModelException {
IMethod[] methods = type.getMethods();
for (int i = 0; i < methods.length; i++) {
map.put(createSignatureKey(methods[i]), methods[i]);
}
}
/**returns a non null array of final methods of the type*/
private static IMethod[] resolveFinalMethods(IType type) throws JavaModelException {
//Interfaces are java.lang.Objects
if (type.isInterface()) {
type = getJavaLangObject(type.getJavaProject());//$NON-NLS-1$
}
IMethod[] methods = resolveMethodsHierarchy(type);
List list = new ArrayList(methods.length);
for (int i = 0; i < methods.length; i++) {
boolean isFinal = Flags.isFinal(methods[i].getFlags());
if (isFinal)
list.add(methods[i]);
}
return (IMethod[]) list.toArray(new IMethod[list.size()]);
}
/**creates a key used for hashmaps for a method signature (name+arguments(fqn))*/
private static String createSignatureKey(IMethod method) throws JavaModelException {
StringBuffer buffer = new StringBuffer();
buffer.append(method.getElementName());
String[] args = method.getParameterTypes();
for (int i = 0; i < args.length; i++) {
String signature;
if (isUnresolved(args[i])) {
int acount = Signature.getArrayCount(args[i]);
if (acount > 0) {
String arg = args[i];
int index = arg.lastIndexOf(Signature.C_ARRAY);
arg = arg.substring(index + 1);
signature = Signature.toString(arg);
} else {
signature = Signature.toString(args[i]);
}
String[][] fqn = method.getDeclaringType().resolveType(signature);
if (fqn != null) {
buffer.append(fqn[0][0]).append('.').append(fqn[0][1]);
//TODO check for [][]
for (int j = 0; j < acount; j++) {
buffer.append("[]"); //$NON-NLS-1$
}
}
}else{
signature=Signature.toString(args[i]);
buffer.append(signature);
}
}
return buffer.toString();
}
private static boolean isUnresolved(String signature) {
boolean flag = false;
char c=Signature.getElementType(signature).charAt(0);
boolean primitive=(c!= Signature.C_RESOLVED && c != Signature.C_UNRESOLVED);
if(primitive)
return flag;
int acount = Signature.getArrayCount(signature);
if (acount > 0) {
int index = signature.lastIndexOf(Signature.C_ARRAY);
c = signature.charAt(index + 1);
} else {
c = signature.charAt(0);
}
switch (c) {
case Signature.C_RESOLVED :
flag=false;
break;
case Signature.C_UNRESOLVED :
flag=true;
break;
default :
throw new IllegalArgumentException();
}
return flag;
}
private static boolean hasPrimitiveType(IField field) throws JavaModelException {
String signature = field.getTypeSignature();
char first = Signature.getElementType(signature).charAt(0);
return (first != Signature.C_RESOLVED && first != Signature.C_UNRESOLVED);
}
/**
* returns Type of field.
*
* if field is primitve null is returned.
* if field is array java.lang.Object is returned.
**/
private static IType resolveTypeOfField(IField field) throws JavaModelException {
boolean isPrimitive = hasPrimitiveType(field);
boolean isArray = isArray(field);
if (!isPrimitive && !isArray) {
String typeName = JavaModelUtil.getResolvedTypeName(field.getTypeSignature(), field.getDeclaringType());
//if the cu has errors its possible no type name is resolved
return typeName != null ? field.getJavaProject().findType(typeName) : null;
} else if (isArray) {
return getJavaLangObject(field.getJavaProject());
}
return null;
}
private static IType getJavaLangObject(IJavaProject project) throws JavaModelException {
return JavaModelUtil.findType(project, "java.lang.Object");//$NON-NLS-1$
}
private static boolean isArray(IField field) throws JavaModelException {
return Signature.getArrayCount(field.getTypeSignature()) > 0;
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.ui.JavaElementImageDescriptor;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil;
import org.eclipse.jdt.internal.corext.codemanipulation.IRequestQuery;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.refactoring.IVisibilityChangeListener;
import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* Creates getter and setter methods for a type's fields. Opens a dialog
* with a list of fields for which a setter or getter can be generated.
* User is able to check or uncheck items before setters or getters
* are generated.
* <p>
* Will open the parent compilation unit in a Java editor. The result is
* unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IField</code> or <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class AddGetterSetterAction extends SelectionDispatchAction {
private boolean fSort;
private boolean fSynchronized;
private boolean fFinal;
private int fVisibility;
private boolean fGenerateComment;
private int fNumEntries;
private CompilationUnitEditor fEditor;
private static final String dialogTitle= ActionMessages.getString("AddGetterSetterAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>AddGetterSetterAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddGetterSetterAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddGetterSetterAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddGetterSetterAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddGetterSetterAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.GETTERSETTER_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddGetterSetterAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null);
fEditor.getEditorSite();
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
try {
IField[] selectedFields= getSelectedFields(selection);
if (canRunOn(selectedFields)){
run(selectedFields[0].getDeclaringType(), selectedFields, false);
return;
}
Object firstElement= selection.getFirstElement();
if (firstElement instanceof IType)
run((IType)firstElement, new IField[0], false);
else if (firstElement instanceof ICompilationUnit) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38500
IType type= ((ICompilationUnit) firstElement).findPrimaryType();
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
else
run(((ICompilationUnit) firstElement).findPrimaryType(), new IField[0], false);
}
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if (getSelectedFields(selection) != null)
return true;
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
private static boolean canRunOn(IField[] fields) throws JavaModelException {
return fields != null && fields.length > 0;
}
private void resetNumEntries() {
fNumEntries= 0;
}
private void incNumEntries() {
fNumEntries++;
}
private void run(IType type, IField[] preselected, boolean editor) throws CoreException {
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
if (!ElementValidator.check(type, getShell(), dialogTitle, editor))
return;
if (!ActionUtil.isProcessable(getShell(), type))
return;
ILabelProvider lp= new AddGetterSetterLabelProvider();
resetNumEntries();
Map entries= createGetterSetterMapping(type);
if (entries.isEmpty()){
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGettSetterAction.typeContainsNoFields.message")); //$NON-NLS-1$
return;
}
AddGetterSetterContentProvider cp= new AddGetterSetterContentProvider(entries);
GetterSetterTreeSelectionDialog dialog= new GetterSetterTreeSelectionDialog(getShell(), lp, cp, fEditor, type);
dialog.setSorter(new JavaElementSorter());
dialog.setTitle(dialogTitle);
String message= ActionMessages.getString("AddGetterSetterAction.dialog.label");//$NON-NLS-1$
dialog.setMessage(message);
dialog.setValidator(createValidator(fNumEntries));
dialog.setContainerMode(true);
dialog.setSize(60, 18);
dialog.setInput(type);
if (preselected.length > 0) {
dialog.setInitialSelections(preselected);
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
cp.setPreselected(preselected[0]);
}
int dialogResult= dialog.open();
if (dialogResult == Window.OK) {
Object[] result= dialog.getResult();
if (result == null)
return;
fSort= dialog.getSort();
fSynchronized= dialog.getSynchronized();
fFinal= dialog.getFinal();
fVisibility= dialog.getVisibility();
fGenerateComment= dialog.getGenerateComment();
IField[] getterFields, setterFields, getterSetterFields;
if (fSort) {
getterFields= getGetterFields(result);
setterFields= getSetterFields(result);
getterSetterFields= new IField[0];
}
else {
getterFields= getGetterOnlyFields(result);
setterFields= getSetterOnlyFields(result);
getterSetterFields= getGetterSetterFields(result);
}
IJavaElement elementPosition= dialog.getElementPosition();
generate(getterFields, setterFields, getterSetterFields, elementPosition);
}
}
private static class AddGetterSetterSelectionStatusValidator implements ISelectionStatusValidator {
private static int fEntries;
AddGetterSetterSelectionStatusValidator(int entries) {
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedMethods(selection);
if (count == 0)
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
String message= ActionMessages.getFormattedString("AddGetterSetterAction.methods_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedMethods(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof GetterSetterEntry)
count++;
}
return count;
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddGetterSetterSelectionStatusValidator validator= new AddGetterSetterSelectionStatusValidator(entries);
return validator;
}
// returns a list of fields with setter entries checked
private static IField[] getSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (! entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with getter entries checked
private static IField[] getGetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only getter entires checked
private static IField[] getGetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.remove(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only setter entries checked
private static IField[] getSetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet != true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with both entries checked
private static IField[] getGetterSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
private void generate(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) throws CoreException{
if (getterFields.length == 0 && setterFields.length == 0 && getterSetterFields.length == 0)
return;
ICompilationUnit cu= null;
if (getterFields.length != 0)
cu= getterFields[0].getCompilationUnit();
else if (setterFields.length != 0)
cu= setterFields[0].getCompilationUnit();
else
cu= getterSetterFields[0].getCompilationUnit();
//open the editor, forces the creation of a working copy
IEditorPart editor= EditorUtility.openInEditor(cu);
IField[] workingCopyGetterFields= getWorkingCopyFields(getterFields);
IField[] workingCopySetterFields= getWorkingCopyFields(setterFields);
IField[] workingCopyGetterSetterFields= getWorkingCopyFields(getterSetterFields);
IJavaElement workingCopyElementPosition= getWorkingCopy(elementPosition);
if (workingCopyGetterFields != null && workingCopySetterFields != null && workingCopyGetterSetterFields != null)
run(workingCopyGetterFields, workingCopySetterFields, workingCopyGetterSetterFields, editor, workingCopyElementPosition);
}
private static IJavaElement getWorkingCopy(IJavaElement elementPosition) {
if(elementPosition instanceof IMember)
return JavaModelUtil.toWorkingCopy((IMember)elementPosition);
return elementPosition;
}
private IField[] getWorkingCopyFields(IField[] fields) throws CoreException{
if (fields.length == 0)
return new IField[0];
ICompilationUnit cu= fields[0].getCompilationUnit();
ICompilationUnit workingCopyCU;
IField[] workingCopyFields;
if (cu.isWorkingCopy()) {
workingCopyCU= cu;
workingCopyFields= fields;
} else {
workingCopyCU= EditorUtility.getWorkingCopy(cu);
if (workingCopyCU == null) {
showError(ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
return null;
}
workingCopyFields= new IField[fields.length];
for (int i= 0; i < fields.length; i++) {
IField field= fields[i];
IField workingCopyField= (IField) JavaModelUtil.findMemberInCompilationUnit(workingCopyCU, field);
if (workingCopyField == null) {
showError(ActionMessages.getFormattedString("AddGetterSetterAction.error.fieldNotExisting", field.getElementName())); //$NON-NLS-1$
return null;
}
workingCopyFields[i]= workingCopyField;
}
}
return workingCopyFields;
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
try {
IJavaElement input= SelectionConverter.getInput(fEditor);
if (!ActionUtil.isProcessable(getShell(), input))
return;
IJavaElement[] elements= SelectionConverter.codeResolve(fEditor);
if (elements.length == 1 && (elements[0] instanceof IField)) {
IField field= (IField)elements[0];
run(field.getDeclaringType(), new IField[] {field}, true);
return;
}
IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
if (element != null){
IType type= (IType)element.getAncestor(IJavaElement.TYPE);
if (type != null) {
if (type.getFields().length > 0){
run(type, new IField[0], true);
return;
}
}
}
MessageDialog.openInformation(getShell(), dialogTitle,
ActionMessages.getString("AddGetterSetterAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
//---- Helpers -------------------------------------------------------------------
private void run(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IEditorPart editor, IJavaElement elementPosition) {
IRewriteTarget target= (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
}
try {
AddGetterSetterOperation op= createAddGetterSetterOperation(getterFields, setterFields, getterSetterFields, elementPosition);
setOperationStatusFields(op);
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod[] createdMethods= op.getCreatedAccessors();
if (createdMethods.length > 0) {
EditorUtility.revealInEditor(editor, createdMethods[0]);
}
} catch (InvocationTargetException e) {
String message= ActionMessages.getString("AddGetterSetterAction.error.actionfailed"); //$NON-NLS-1$
ExceptionHandler.handle(e, getShell(), dialogTitle, message);
} catch (InterruptedException e) {
// operation cancelled
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
private void setOperationStatusFields(AddGetterSetterOperation op) {
// Set the status fields corresponding to the visibility and modifiers set
op.setSort(fSort);
op.setVisibility(fVisibility);
op.setSynchronized(fSynchronized);
op.setFinal(fFinal);
}
private AddGetterSetterOperation createAddGetterSetterOperation(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) {
IRequestQuery skipSetterForFinalQuery= skipSetterForFinalQuery();
IRequestQuery skipReplaceQuery= skipReplaceQuery();
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= fGenerateComment;
return new AddGetterSetterOperation(getterFields, setterFields, getterSetterFields, settings, skipSetterForFinalQuery, skipReplaceQuery, elementPosition);
}
private IRequestQuery skipSetterForFinalQuery() {
return new IRequestQuery() {
public int doQuery(IMember field) {
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19367
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.YES_ALL, IRequestQuery.NO, IRequestQuery.CANCEL};
String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
String fieldName= JavaElementLabels.getElementLabel(field, 0);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipSetterForFinalDialog.message", fieldName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private IRequestQuery skipReplaceQuery() {
return new IRequestQuery() {
public int doQuery(IMember method) {
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.NO, IRequestQuery.YES_ALL, IRequestQuery.CANCEL};
String skipLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skip.label"); //$NON-NLS-1$
String replaceLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.replace.label"); //$NON-NLS-1$
String skipAllLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skipAll.label"); //$NON-NLS-1$
String[] options= { skipLabel, replaceLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL};
String methodName= JavaElementLabels.getElementLabel(method, JavaElementLabels.M_PARAMETER_TYPES);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipExistingDialog.message", methodName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) {
final Shell shell= getShell();
if (shell == null) {
JavaPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$
return IRequestQuery.CANCEL;
}
final int[] result= { MessageDialog.CANCEL };
shell.getDisplay().syncExec(new Runnable() {
public void run() {
String title= ActionMessages.getString("AddGetterSetterAction.QueryDialog.title"); //$NON-NLS-1$
MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0);
result[0]= dialog.open();
}
});
int returnVal= result[0];
return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal];
}
private void showError(String message) {
MessageDialog.openError(getShell(), dialogTitle, message);
}
/*
* Returns fields in the selection or <code>null</code> if the selection is
* empty or not valid.
*/
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements= selection.toList();
int nElements= elements.size();
if (nElements > 0) {
IField[] res= new IField[nElements];
ICompilationUnit cu= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (curr instanceof IField) {
IField fld= (IField)curr;
if (i == 0) {
// remember the cu of the first element
cu= fld.getCompilationUnit();
if (cu == null) {
return null;
}
} else if (!cu.equals(fld.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
if (fld.getDeclaringType().isInterface()) {
// no setters/getters for interfaces
return null;
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
return null;
}
res[i]= fld;
} else {
return null;
}
}
return res;
}
return null;
}
private static class AddGetterSetterLabelProvider extends JavaElementLabelProvider {
AddGetterSetterLabelProvider() {
}
/*
* @see ILabelProvider#getText(Object)
*/
public String getText(Object element) {
if (element instanceof GetterSetterEntry) {
GetterSetterEntry entry= (GetterSetterEntry) element;
try {
if (entry.fGetterEntry) {
return GetterSetterUtil.getGetterName(entry.fField, null) + "()"; //$NON-NLS-1$
} else {
return GetterSetterUtil.getSetterName(entry.fField, null) + '(' + Signature.getSimpleName(Signature.toString(entry.fField.getTypeSignature())) + ')';
}
} catch (JavaModelException e) {
return ""; //$NON-NLS-1$
}
}
return super.getText(element);
}
/*
* @see ILabelProvider#getImage(Object)
*/
public Image getImage(Object element) {
if (element instanceof GetterSetterEntry) {
int flags= 0;
try {
flags= ((GetterSetterEntry) element).fField.getFlags();
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
ImageDescriptor desc= JavaElementImageProvider.getFieldImageDescriptor(false, Flags.AccPublic);
int adornmentFlags= Flags.isStatic(flags) ? JavaElementImageDescriptor.STATIC : 0;
desc= new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
return JavaPlugin.getImageDescriptorRegistry().get(desc);
}
return super.getImage(element);
}
}
/**
* @return map IField -> GetterSetterEntry[]
*/
private Map createGetterSetterMapping(IType type) throws JavaModelException{
IField[] fields= type.getFields();
Map result= new HashMap();
for (int i= 0; i < fields.length; i++) {
List l= new ArrayList(2);
if (GetterSetterUtil.getGetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], true));
incNumEntries();
}
if (GetterSetterUtil.getSetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], false));
incNumEntries();
}
if (! l.isEmpty())
result.put(fields[i], (GetterSetterEntry[]) l.toArray(new GetterSetterEntry[l.size()]));
}
return result;
}
private static class AddGetterSetterContentProvider implements ISourceActionContentProvider {
private final String SETTINGS_SECTION= "AddGetterSetterDialog"; //$NON-NLS-1$
private final String VISIBILITY_MODIFIER= "VisibilityModifier"; //$NON-NLS-1$
private final String FINAL_MODIFIER= "FinalModifier"; //$NON-NLS-1$
private final String SYNCHRONIZED_MODIFIER= "SynchronizedModifier"; //$NON-NLS-1$
private final String SORT_ORDER= "SortOrdering"; //$NON-NLS-1$
private static final Object[] EMPTY= new Object[0];
private Viewer fViewer;
private Map fGetterSetterEntries; //IField -> Object[] (with 0 to 2 elements of type GetterSetterEntry)
private IField fPreselected;
private IDialogSettings fSettings;
private int fInsertPosition;
private int fVisibilityModifier;
private boolean fFinal;
private boolean fSynchronized;
private boolean fSortOrder;
public AddGetterSetterContentProvider(Map entries) throws JavaModelException {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
fSettings= dialogSettings.getSection(SETTINGS_SECTION);
if (fSettings == null) {
fSettings= dialogSettings.addNewSection(SETTINGS_SECTION);
fSettings.put(SETTINGS_INSERTPOSITION, 0); //$NON-NLS-1$
fSettings.put(VISIBILITY_MODIFIER, Modifier.PUBLIC); //$NON-NLS-1$
fSettings.put(FINAL_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SYNCHRONIZED_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SORT_ORDER, false); //$NON-NLS-1$
}
fInsertPosition= fSettings.getInt(SETTINGS_INSERTPOSITION);
fVisibilityModifier= fSettings.getInt(VISIBILITY_MODIFIER);
fFinal= fSettings.getBoolean(FINAL_MODIFIER);
fSynchronized= fSettings.getBoolean(SYNCHRONIZED_MODIFIER);
fSortOrder= fSettings.getBoolean(SORT_ORDER);
fGetterSetterEntries= entries;
}
public boolean isFinal() {
return fFinal;
}
/***
* Returns 0 for the first method, 1 for the last method, > 1 for all else.
*/
public int getInsertPosition() {
return fInsertPosition;
}
public boolean isSynchronized() {
return fSynchronized;
}
public int getVisibilityModifier() {
return fVisibilityModifier;
}
public boolean getSortOrder() {
return fSortOrder;
}
/***
* Set insert position valid input is 0 for the first position, 1 for the last position, > 1 for all else.
*/
public void setInsertPosition(int insert) {
if (fInsertPosition != insert) {
fInsertPosition= insert;
fSettings.put(SETTINGS_INSERTPOSITION, insert);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setVisibility(int visibility) {
if (fVisibilityModifier != visibility) {
fVisibilityModifier= visibility;
fSettings.put(VISIBILITY_MODIFIER, visibility);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setFinal(boolean value) {
if (fFinal != value) {
fFinal= value;
fSettings.put(FINAL_MODIFIER, value);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setSynchronized(boolean value) {
if (fSynchronized != value) {
fSynchronized= value;
fSettings.put(SYNCHRONIZED_MODIFIER, value);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public void setSort(boolean sort) {
if (fSortOrder != sort) {
fSortOrder= sort;
fSettings.put(SORT_ORDER, sort);
if (fViewer != null) {
fViewer.refresh();
}
}
}
public IField getPreselected() {
return fPreselected;
}
public void setPreselected(IField preselected) {
fPreselected= preselected;
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
fViewer= viewer;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IField)
return (Object[])fGetterSetterEntries.get(parentElement);
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
if (element instanceof IMember)
return ((IMember)element).getDeclaringType();
if (element instanceof GetterSetterEntry)
return ((GetterSetterEntry)element).fField;
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fGetterSetterEntries.keySet().toArray();
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
fGetterSetterEntries.clear();
fGetterSetterEntries= null;
}
}
private static class GetterSetterTreeSelectionDialog extends SourceActionDialog {
private int fVisibility;
private boolean fFinal;
private boolean fSynchronized;
private boolean fSort;
private IType fType;
private AddGetterSetterContentProvider fContentProvider;
private static final int SELECT_GETTERS_ID= IDialogConstants.CLIENT_ID + 1;
private static final int SELECT_SETTERS_ID= IDialogConstants.CLIENT_ID + 2;
public GetterSetterTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, AddGetterSetterContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider, editor, type);
fContentProvider= contentProvider;
fSynchronized= fContentProvider.isSynchronized();
fFinal= fContentProvider.isFinal();
fVisibility= fContentProvider.getVisibilityModifier();
fSort= fContentProvider.getSortOrder();
fType= type;
}
public int getVisibility() {
return fVisibility;
}
public boolean getSort() {
return fSort;
}
public boolean getFinal() {
return fFinal;
}
public boolean getSynchronized() {
return fSynchronized;
}
protected void createGetterSetterButtons(Composite buttonComposite) {
createButton(buttonComposite, SELECT_GETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_getters"), false); //$NON-NLS-1$
createButton(buttonComposite, SELECT_SETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_setters"), false); //$NON-NLS-1$
}
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
switch(buttonId) {
case SELECT_GETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(true));
updateOKStatus();
break;
}
case SELECT_SETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(false));
updateOKStatus();
break;
}
}
}
protected Composite createEntryPtCombo(Composite composite) {
Composite entryComposite= super.createEntryPtCombo(composite);
addSortOrder(entryComposite);
addVisibilityAndModifiersChoices(entryComposite);
return entryComposite;
}
private Composite addSortOrder(Composite composite) {
Label label= new Label(composite, SWT.NONE);
label.setText(ActionMessages.getString("GetterSetterTreeSelectionDialog.sort_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
label.setLayoutData(gd);
final Combo combo= new Combo(composite, SWT.READ_ONLY);
combo.setItems(new String[]{ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_pair_sort"), //$NON-NLS-1$
ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_method_sort")}); //$NON-NLS-1$
final int methodIndex= 1; // Hard-coded. Change this if the list gets more complicated.
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int sort= fContentProvider.getSortOrder() ? 1 : 0;
combo.setText(combo.getItem(sort));
gd= new GridData(GridData.FILL_BOTH);
combo.setLayoutData(gd);
combo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
fSort= (combo.getSelectionIndex() == methodIndex);
fContentProvider.setSort(fSort);
}
});
return composite;
}
private Composite addVisibilityAndModifiersChoices(Composite buttonComposite) {
// Add visibility and modifiers buttons: http://bugs.eclipse.org/bugs/show_bug.cgi?id=35870
// Add persistence of options: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
IVisibilityChangeListener visibilityChangeListener = new IVisibilityChangeListener(){
public void visibilityChanged(int newVisibility) {
fVisibility= newVisibility;
fContentProvider.setVisibility(fVisibility);
}
public void modifierChanged(int modifier, boolean isChecked) {
switch (modifier) {
case Modifier.FINAL: {
fFinal= isChecked;
fContentProvider.setFinal(fFinal) ;
return;
}
case Modifier.SYNCHRONIZED: {
fSynchronized= isChecked;
fContentProvider.setSynchronized(fSynchronized);
return;
}
default: return;
}
}
};
int initialVisibility= fContentProvider.getVisibilityModifier();
int[] availableVisibilities= new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE, Modifier.NONE};
Composite visibilityComposite= createVisibilityControlAndModifiers(buttonComposite, visibilityChangeListener, availableVisibilities, initialVisibility);
return visibilityComposite;
}
private List convertToIntegerList(int[] array) {
List result= new ArrayList(array.length);
for (int i= 0; i < array.length; i++) {
result.add(new Integer(array[i]));
}
return result;
}
private Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
List allowedVisibilities= convertToIntegerList(availableVisibilities);
if (allowedVisibilities.size() == 1)
return null;
Group group= new Group(parent, SWT.NONE);
group.setText(RefactoringMessages.getString("VisibilityControlUtil.Access_modifier")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
GridLayout layout= new GridLayout();
layout.makeColumnsEqualWidth= true;
layout.numColumns= 4;
group.setLayout(layout);
String[] labels= new String[] {
"&public", //$NON-NLS-1$
"pro&tected", //$NON-NLS-1$
RefactoringMessages.getString("VisibilityControlUtil.defa&ult_4"), //$NON-NLS-1$
"pri&vate" //$NON-NLS-1$
};
Integer[] data= new Integer[] {
new Integer(Modifier.PUBLIC),
new Integer(Modifier.PROTECTED),
new Integer(Modifier.NONE),
new Integer(Modifier.PRIVATE)};
Integer initialVisibility= new Integer(correctVisibility);
for (int i= 0; i < labels.length; i++) {
Button radio= new Button(group, SWT.RADIO);
Integer visibilityCode= data[i];
radio.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
radio.setText(labels[i]);
radio.setData(visibilityCode);
radio.setSelection(visibilityCode.equals(initialVisibility));
radio.setEnabled(allowedVisibilities.contains(visibilityCode));
radio.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.visibilityChanged(((Integer)event.widget.getData()).intValue());
}
});
}
return group;
}
private Composite createVisibilityControlAndModifiers(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
Composite visibilityComposite= createVisibilityControl(parent, visibilityChangeListener, availableVisibilities, correctVisibility);
Button finalCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
finalCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.final")); //$NON-NLS-1$
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
finalCheckboxButton.setLayoutData(gd);
finalCheckboxButton.setData(new Integer(Modifier.FINAL));
finalCheckboxButton.setEnabled(true);
finalCheckboxButton.setSelection(fContentProvider.isFinal());
finalCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
Button syncCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
syncCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.synchronized")); //$NON-NLS-1$
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
syncCheckboxButton.setLayoutData(gd);
syncCheckboxButton.setData(new Integer(Modifier.SYNCHRONIZED));
syncCheckboxButton.setEnabled(true);
syncCheckboxButton.setSelection(fContentProvider.isSynchronized());
syncCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
return visibilityComposite;
}
private Object[] getGetterSetterElements(boolean isGetter){
Object[] allFields= fContentProvider.getElements(null);
Set result= new HashSet();
for (int i = 0; i < allFields.length; i++) {
IField field= (IField)allFields[i];
GetterSetterEntry[] entries= getEntries(field);
for (int j = 0; j < entries.length; j++) {
AddGetterSetterAction.GetterSetterEntry entry= entries[j];
if (entry.fGetterEntry == isGetter)
result.add(entry);
}
}
return result.toArray();
}
private GetterSetterEntry[] getEntries(IField field) {
List result= Arrays.asList(fContentProvider.getChildren(field));
return (GetterSetterEntry[]) result.toArray(new GetterSetterEntry[result.size()]);
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
createGetterSetterButtons(buttonComposite);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
Control control= super.createDialogArea(parent);
try {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getTreeViewer().setExpandedElements(fType.getFields());
getTreeViewer().reveal(fContentProvider.getPreselected());
getTreeViewer().refresh();
} catch (JavaModelException e) {
}
return control;
}
}
private static class GetterSetterEntry {
public final IField fField;
public final boolean fGetterEntry;
GetterSetterEntry(IField field, boolean isGetterEntry){
fField= field;
fGetterEntry= isGetterEntry;
}
}
}
|
39,044 |
Bug 39044 Add preference for "get" prefix instead of "is" prefix in getter generation
|
From the ng: "In Menu Source->Generate Getter and Setter how can I make Eclipse recognize getX() as a valid getter for booleans and not to prompt me to generate isX()?" Propose to add a preference to the code gen settings which allow customization. Either that or we figure out a way to put it in the getter template.
|
resolved fixed
|
b4da61a
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-20T13:34:18Z | 2003-06-17T22:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddUnimplementedConstructorsAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
/**
* Creates unimplemented constructors for a type.
* <p>
* Will open the parent compilation unit in a Java editor. Opens a dialog
* with a list of constructors from the super class which can be generated.
* User is able to check or uncheck items before constructors are generated.
* The result is unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class AddUnimplementedConstructorsAction extends SelectionDispatchAction {
private CompilationUnitEditor fEditor;
private static final String dialogTitle= ActionMessages.getString("AddUnimplementedConstructorsAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>AddUnimplementedConstructorsAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddUnimplementedConstructorsAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddUnimplementedConstructorsAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddUnimplementedConstructorsAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddUnimplementedConstructorsAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_UNIMPLEMENTED_CONSTRUCTORS_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddUnimplementedConstructorsAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(checkEnabledEditor());
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
Shell shell= getShell();
try {
IType type= getSelectedType(selection);
if (type == null) {
MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.not_applicable")); //$NON-NLS-1$
return;
}
// open an editor and work on a working copy
IEditorPart editor= EditorUtility.openInEditor(type);
type= (IType)EditorUtility.getWorkingCopy(type);
if (type == null) {
MessageDialog.openError(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.type_removed_in_editor")); //$NON-NLS-1$
return;
}
run(shell, type, editor, false);
} catch (CoreException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
}
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
protected void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
Shell shell= getShell();
try {
IType type= SelectionConverter.getTypeAtOffset(fEditor);
if (type != null)
run(shell, type, fEditor, true);
else
MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.not_applicable")); //$NON-NLS-1$
} catch (JavaModelException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
}
}
private boolean checkEnabledEditor() {
return fEditor != null && SelectionConverter.canOperateOn(fEditor);
}
//---- Helpers -------------------------------------------------------------------
private void run(Shell shell, IType type, IEditorPart editor, boolean activatedFromEditor) throws CoreException {
if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) {
return;
}
if (!ActionUtil.isProcessable(getShell(), type)) {
return;
}
IMethod[] constructorMethods= StubUtility.getOverridableConstructors(type);
if (constructorMethods.length == 0) {
MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.nothing_found")); //$NON-NLS-1$
return;
}
JavaElementLabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
AddUnimplementedConstructorsContentProvider contentProvider = new AddUnimplementedConstructorsContentProvider(constructorMethods);
SourceActionDialog dialog= new SourceActionDialog(shell, labelProvider, contentProvider, fEditor, type);
dialog.setCommentString(ActionMessages.getString("SourceActionDialog.createConstructorComment")); //$NON-NLS-1$
dialog.setTitle(getDialogTitle());
dialog.setInitialSelections(constructorMethods);
dialog.setContainerMode(true);
dialog.setSorter(new JavaElementSorter());
dialog.setSize(60, 18);
dialog.setInput(new Object());
dialog.setMessage(ActionMessages.getString("AddUnimplementedConstructorsAction.dialog.label")); //$NON-NLS-1$
dialog.setValidator(createValidator(constructorMethods.length));
IMethod[] selected= null;
int dialogResult = dialog.open();
if (dialogResult == Window.OK) {
Object[] checkedElements = dialog.getResult();
if (checkedElements == null)
return;
ArrayList result= new ArrayList(checkedElements.length);
for (int i= 0; i < checkedElements.length; i++) {
Object curr= checkedElements[i];
if (curr instanceof IMethod) {
result.add(curr);
}
}
selected= (IMethod[]) result.toArray(new IMethod[result.size()]);
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= dialog.getGenerateComment();
IJavaElement elementPosition= dialog.getElementPosition();
AddUnimplementedMethodsOperation op= new AddUnimplementedMethodsOperation(type, settings, selected, false, elementPosition);
IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null;
if (target != null) {
target.beginCompoundChange();
}
try {
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod[] res= op.getCreatedMethods();
if (res == null || res.length == 0) {
MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.getString("AddUnimplementedConstructorsAction.error.nothing_found")); //$NON-NLS-1$
} else if (editor != null) {
if (res[0].getCompilationUnit().isWorkingCopy()) {
synchronized(res[0].getCompilationUnit()) {
res[0].getCompilationUnit().reconcile();
}
}
EditorUtility.revealInEditor(editor, res[0]);
}
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, shell, getDialogTitle(), null);
} catch (InterruptedException e) {
// Do nothing. Operation has been canceled by user.
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddUnimplementedConstructorsValidator validator= new AddUnimplementedConstructorsValidator(entries);
return validator;
}
private IType getSelectedType(IStructuredSelection selection) throws JavaModelException {
Object[] elements= selection.toArray();
if (elements.length == 1 && (elements[0] instanceof IType)) {
IType type= (IType) elements[0];
if (type.getCompilationUnit() != null && type.isClass()) {
return type;
}
}
else if (elements[0] instanceof ICompilationUnit) {
ICompilationUnit cu= (ICompilationUnit) elements[0];
IType type= cu.findPrimaryType();
if (type != null && !type.isInterface())
return type;
}
return null;
}
private String getDialogTitle() {
return dialogTitle;
}
private static class AddUnimplementedConstructorsContentProvider implements ISourceActionContentProvider {
private IMethod[] fMethodsList;
private static final Object[] EMPTY= new Object[0];
public AddUnimplementedConstructorsContentProvider(IMethod[] methodList) {
fMethodsList= methodList;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fMethodsList;
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider#getInsertPosition()
*/
public int getInsertPosition() {
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.dialogs.ISourceActionContentProvider#setInsertPosition(int)
*/
public void setInsertPosition(int insert) {
}
}
private static class AddUnimplementedConstructorsValidator implements ISelectionStatusValidator {
private static int fEntries;
AddUnimplementedConstructorsValidator(int entries) {
super();
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedMethods(selection);
if (count == 0)
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
String message= ActionMessages.getFormattedString("AddUnimplementedConstructorsAction.methods_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedMethods(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof IMethod)
count++;
}
return count;
}
}
}
|
38,478 |
Bug 38478 getters/setters: no warning of duplicate methods
|
20030604 in 'add delegate method' i get an error if duplicate method are selected in generate getter/setter i do not try this (with 'f' set as a field prefix): String fFoo; String foo; you get 2 getFoo's and no error or warning
|
resolved fixed
|
8b505bf
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-23T14:42:56Z | 2003-06-05T10:46:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.ui.JavaElementImageDescriptor;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil;
import org.eclipse.jdt.internal.corext.codemanipulation.IRequestQuery;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.refactoring.IVisibilityChangeListener;
import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* Creates getter and setter methods for a type's fields. Opens a dialog
* with a list of fields for which a setter or getter can be generated.
* User is able to check or uncheck items before setters or getters
* are generated.
* <p>
* Will open the parent compilation unit in a Java editor. The result is
* unsaved, so the user can decide if the changes are acceptable.
* <p>
* The action is applicable to structured selections containing elements
* of type <code>IField</code> or <code>IType</code>.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class AddGetterSetterAction extends SelectionDispatchAction {
private boolean fSort;
private boolean fSynchronized;
private boolean fFinal;
private int fVisibility;
private boolean fGenerateComment;
private int fNumEntries;
private CompilationUnitEditor fEditor;
private static final String dialogTitle= ActionMessages.getString("AddGetterSetterAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>AddGetterSetterAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public AddGetterSetterAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("AddGetterSetterAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("AddGetterSetterAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("AddGetterSetterAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.GETTERSETTER_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public AddGetterSetterAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(SelectionConverter.getInputAsCompilationUnit(editor) != null);
fEditor.getEditorSite();
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
try {
IField[] selectedFields= getSelectedFields(selection);
if (canRunOn(selectedFields)){
run(selectedFields[0].getDeclaringType(), selectedFields, false);
return;
}
Object firstElement= selection.getFirstElement();
if (firstElement instanceof IType)
run((IType)firstElement, new IField[0], false);
else if (firstElement instanceof ICompilationUnit) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38500
IType type= ((ICompilationUnit) firstElement).findPrimaryType();
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
else
run(((ICompilationUnit) firstElement).findPrimaryType(), new IField[0], false);
}
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if (getSelectedFields(selection) != null)
return true;
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
private static boolean canRunOn(IField[] fields) throws JavaModelException {
return fields != null && fields.length > 0;
}
private void resetNumEntries() {
fNumEntries= 0;
}
private void incNumEntries() {
fNumEntries++;
}
private void run(IType type, IField[] preselected, boolean editor) throws CoreException {
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
if (!ElementValidator.check(type, getShell(), dialogTitle, editor))
return;
if (!ActionUtil.isProcessable(getShell(), type))
return;
ILabelProvider lp= new AddGetterSetterLabelProvider();
resetNumEntries();
Map entries= createGetterSetterMapping(type);
if (entries.isEmpty()){
MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGettSetterAction.typeContainsNoFields.message")); //$NON-NLS-1$
return;
}
AddGetterSetterContentProvider cp= new AddGetterSetterContentProvider(entries);
GetterSetterTreeSelectionDialog dialog= new GetterSetterTreeSelectionDialog(getShell(), lp, cp, fEditor, type);
dialog.setSorter(new JavaElementSorter());
dialog.setTitle(dialogTitle);
String message= ActionMessages.getString("AddGetterSetterAction.dialog.label");//$NON-NLS-1$
dialog.setMessage(message);
dialog.setValidator(createValidator(fNumEntries));
dialog.setContainerMode(true);
dialog.setSize(60, 18);
dialog.setInput(type);
if (preselected.length > 0) {
dialog.setInitialSelections(preselected);
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
cp.setPreselected(preselected[0]);
}
int dialogResult= dialog.open();
if (dialogResult == Window.OK) {
Object[] result= dialog.getResult();
if (result == null)
return;
fSort= dialog.getSortOrder();
fSynchronized= dialog.getSynchronized();
fFinal= dialog.getFinal();
fVisibility= dialog.getVisibilityModifier();
fGenerateComment= dialog.getGenerateComment();
IField[] getterFields, setterFields, getterSetterFields;
if (fSort) {
getterFields= getGetterFields(result);
setterFields= getSetterFields(result);
getterSetterFields= new IField[0];
}
else {
getterFields= getGetterOnlyFields(result);
setterFields= getSetterOnlyFields(result);
getterSetterFields= getGetterSetterFields(result);
}
IJavaElement elementPosition= dialog.getElementPosition();
generate(getterFields, setterFields, getterSetterFields, elementPosition);
}
}
private static class AddGetterSetterSelectionStatusValidator implements ISelectionStatusValidator {
private static int fEntries;
AddGetterSetterSelectionStatusValidator(int entries) {
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedMethods(selection);
if (count == 0)
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
String message= ActionMessages.getFormattedString("AddGetterSetterAction.methods_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedMethods(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof GetterSetterEntry)
count++;
}
return count;
}
}
private static ISelectionStatusValidator createValidator(int entries) {
AddGetterSetterSelectionStatusValidator validator= new AddGetterSetterSelectionStatusValidator(entries);
return validator;
}
// returns a list of fields with setter entries checked
private static IField[] getSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (! entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with getter entries checked
private static IField[] getGetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
}
}
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only getter entires checked
private static IField[] getGetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
list.add(entry.fField);
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.remove(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with only setter entries checked
private static IField[] getSetterOnlyFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet != true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
// returns a list of fields with both entries checked
private static IField[] getGetterSetterFields(Object[] result){
Collection list= new ArrayList(0);
Object each= null;
GetterSetterEntry entry= null;
boolean getterSet= false;
for (int i = 0; i < result.length; i++) {
each= result[i];
if ((each instanceof GetterSetterEntry)){
entry= (GetterSetterEntry)each;
if (entry.fGetterEntry) {
getterSet= true;
}
if ((! entry.fGetterEntry) && (getterSet == true)) {
list.add(entry.fField);
getterSet= false;
}
}
else
getterSet= false;
}
return (IField[]) list.toArray(new IField[list.size()]);
}
private void generate(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) throws CoreException{
if (getterFields.length == 0 && setterFields.length == 0 && getterSetterFields.length == 0)
return;
ICompilationUnit cu= null;
if (getterFields.length != 0)
cu= getterFields[0].getCompilationUnit();
else if (setterFields.length != 0)
cu= setterFields[0].getCompilationUnit();
else
cu= getterSetterFields[0].getCompilationUnit();
//open the editor, forces the creation of a working copy
IEditorPart editor= EditorUtility.openInEditor(cu);
IField[] workingCopyGetterFields= getWorkingCopyFields(getterFields);
IField[] workingCopySetterFields= getWorkingCopyFields(setterFields);
IField[] workingCopyGetterSetterFields= getWorkingCopyFields(getterSetterFields);
IJavaElement workingCopyElementPosition= getWorkingCopy(elementPosition);
if (workingCopyGetterFields != null && workingCopySetterFields != null && workingCopyGetterSetterFields != null)
run(workingCopyGetterFields, workingCopySetterFields, workingCopyGetterSetterFields, editor, workingCopyElementPosition);
}
private static IJavaElement getWorkingCopy(IJavaElement elementPosition) {
if(elementPosition instanceof IMember)
return JavaModelUtil.toWorkingCopy((IMember)elementPosition);
return elementPosition;
}
private IField[] getWorkingCopyFields(IField[] fields) throws CoreException{
if (fields.length == 0)
return new IField[0];
ICompilationUnit cu= fields[0].getCompilationUnit();
ICompilationUnit workingCopyCU;
IField[] workingCopyFields;
if (cu.isWorkingCopy()) {
workingCopyCU= cu;
workingCopyFields= fields;
} else {
workingCopyCU= EditorUtility.getWorkingCopy(cu);
if (workingCopyCU == null) {
showError(ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
return null;
}
workingCopyFields= new IField[fields.length];
for (int i= 0; i < fields.length; i++) {
IField field= fields[i];
IField workingCopyField= (IField) JavaModelUtil.findMemberInCompilationUnit(workingCopyCU, field);
if (workingCopyField == null) {
showError(ActionMessages.getFormattedString("AddGetterSetterAction.error.fieldNotExisting", field.getElementName())); //$NON-NLS-1$
return null;
}
workingCopyFields[i]= workingCopyField;
}
}
return workingCopyFields;
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
try {
IJavaElement input= SelectionConverter.getInput(fEditor);
if (!ActionUtil.isProcessable(getShell(), input))
return;
IJavaElement[] elements= SelectionConverter.codeResolve(fEditor);
if (elements.length == 1 && (elements[0] instanceof IField)) {
IField field= (IField)elements[0];
run(field.getDeclaringType(), new IField[] {field}, true);
return;
}
IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
if (element != null){
IType type= (IType)element.getAncestor(IJavaElement.TYPE);
if (type != null) {
if (type.getFields().length > 0){
run(type, new IField[0], true);
return;
}
}
}
MessageDialog.openInformation(getShell(), dialogTitle,
ActionMessages.getString("AddGetterSetterAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), dialogTitle, ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); //$NON-NLS-1$
}
}
//---- Helpers -------------------------------------------------------------------
private void run(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IEditorPart editor, IJavaElement elementPosition) {
IRewriteTarget target= (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
if (target != null) {
target.beginCompoundChange();
}
try {
AddGetterSetterOperation op= createAddGetterSetterOperation(getterFields, setterFields, getterSetterFields, elementPosition);
setOperationStatusFields(op);
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod[] createdMethods= op.getCreatedAccessors();
if (createdMethods.length > 0) {
EditorUtility.revealInEditor(editor, createdMethods[0]);
}
} catch (InvocationTargetException e) {
String message= ActionMessages.getString("AddGetterSetterAction.error.actionfailed"); //$NON-NLS-1$
ExceptionHandler.handle(e, getShell(), dialogTitle, message);
} catch (InterruptedException e) {
// operation cancelled
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
private void setOperationStatusFields(AddGetterSetterOperation op) {
// Set the status fields corresponding to the visibility and modifiers set
op.setSort(fSort);
op.setVisibility(fVisibility);
op.setSynchronized(fSynchronized);
op.setFinal(fFinal);
}
private AddGetterSetterOperation createAddGetterSetterOperation(IField[] getterFields, IField[] setterFields, IField[] getterSetterFields, IJavaElement elementPosition) {
IRequestQuery skipSetterForFinalQuery= skipSetterForFinalQuery();
IRequestQuery skipReplaceQuery= skipReplaceQuery();
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= fGenerateComment;
return new AddGetterSetterOperation(getterFields, setterFields, getterSetterFields, settings, skipSetterForFinalQuery, skipReplaceQuery, elementPosition);
}
private IRequestQuery skipSetterForFinalQuery() {
return new IRequestQuery() {
public int doQuery(IMember field) {
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19367
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.YES_ALL, IRequestQuery.NO, IRequestQuery.CANCEL};
String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
String fieldName= JavaElementLabels.getElementLabel(field, 0);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipSetterForFinalDialog.message", fieldName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private IRequestQuery skipReplaceQuery() {
return new IRequestQuery() {
public int doQuery(IMember method) {
int[] returnCodes= {IRequestQuery.YES, IRequestQuery.NO, IRequestQuery.YES_ALL, IRequestQuery.CANCEL};
String skipLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skip.label"); //$NON-NLS-1$
String replaceLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.replace.label"); //$NON-NLS-1$
String skipAllLabel= ActionMessages.getString("AddGetterSetterAction.SkipExistingDialog.skipAll.label"); //$NON-NLS-1$
String[] options= { skipLabel, replaceLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL};
String methodName= JavaElementLabels.getElementLabel(method, JavaElementLabels.M_PARAMETER_TYPES);
String formattedMessage= ActionMessages.getFormattedString("AddGetterSetterAction.SkipExistingDialog.message", methodName); //$NON-NLS-1$
return showQueryDialog(formattedMessage, options, returnCodes);
}
};
}
private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) {
final Shell shell= getShell();
if (shell == null) {
JavaPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$
return IRequestQuery.CANCEL;
}
final int[] result= { MessageDialog.CANCEL };
shell.getDisplay().syncExec(new Runnable() {
public void run() {
String title= ActionMessages.getString("AddGetterSetterAction.QueryDialog.title"); //$NON-NLS-1$
MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0);
result[0]= dialog.open();
}
});
int returnVal= result[0];
return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal];
}
private void showError(String message) {
MessageDialog.openError(getShell(), dialogTitle, message);
}
/*
* Returns fields in the selection or <code>null</code> if the selection is
* empty or not valid.
*/
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements= selection.toList();
int nElements= elements.size();
if (nElements > 0) {
IField[] res= new IField[nElements];
ICompilationUnit cu= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (curr instanceof IField) {
IField fld= (IField)curr;
if (i == 0) {
// remember the cu of the first element
cu= fld.getCompilationUnit();
if (cu == null) {
return null;
}
} else if (!cu.equals(fld.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
if (fld.getDeclaringType().isInterface()) {
// no setters/getters for interfaces
return null;
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
return null;
}
res[i]= fld;
} else {
return null;
}
}
return res;
}
return null;
}
private static class AddGetterSetterLabelProvider extends JavaElementLabelProvider {
AddGetterSetterLabelProvider() {
}
/*
* @see ILabelProvider#getText(Object)
*/
public String getText(Object element) {
if (element instanceof GetterSetterEntry) {
GetterSetterEntry entry= (GetterSetterEntry) element;
try {
if (entry.fGetterEntry) {
return GetterSetterUtil.getGetterName(entry.fField, null) + "()"; //$NON-NLS-1$
} else {
return GetterSetterUtil.getSetterName(entry.fField, null) + '(' + Signature.getSimpleName(Signature.toString(entry.fField.getTypeSignature())) + ')';
}
} catch (JavaModelException e) {
return ""; //$NON-NLS-1$
}
}
return super.getText(element);
}
/*
* @see ILabelProvider#getImage(Object)
*/
public Image getImage(Object element) {
if (element instanceof GetterSetterEntry) {
int flags= 0;
try {
flags= ((GetterSetterEntry) element).fField.getFlags();
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
ImageDescriptor desc= JavaElementImageProvider.getFieldImageDescriptor(false, Flags.AccPublic);
int adornmentFlags= Flags.isStatic(flags) ? JavaElementImageDescriptor.STATIC : 0;
desc= new JavaElementImageDescriptor(desc, adornmentFlags, JavaElementImageProvider.BIG_SIZE);
return JavaPlugin.getImageDescriptorRegistry().get(desc);
}
return super.getImage(element);
}
}
/**
* @return map IField -> GetterSetterEntry[]
*/
private Map createGetterSetterMapping(IType type) throws JavaModelException{
IField[] fields= type.getFields();
Map result= new HashMap();
for (int i= 0; i < fields.length; i++) {
List l= new ArrayList(2);
if (GetterSetterUtil.getGetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], true));
incNumEntries();
}
if (GetterSetterUtil.getSetter(fields[i]) == null) {
l.add(new GetterSetterEntry(fields[i], false));
incNumEntries();
}
if (! l.isEmpty())
result.put(fields[i], (GetterSetterEntry[]) l.toArray(new GetterSetterEntry[l.size()]));
}
return result;
}
private static class AddGetterSetterContentProvider implements ITreeContentProvider {
private static final Object[] EMPTY= new Object[0];
private Viewer fViewer;
private Map fGetterSetterEntries; //IField -> Object[] (with 0 to 2 elements of type GetterSetterEntry)
private IField fPreselected;
public AddGetterSetterContentProvider(Map entries) throws JavaModelException {
fGetterSetterEntries= entries;
}
public IField getPreselected() {
return fPreselected;
}
public void setPreselected(IField preselected) {
fPreselected= preselected;
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
fViewer= viewer;
}
public Viewer getViewer() {
return fViewer;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IField)
return (Object[])fGetterSetterEntries.get(parentElement);
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
if (element instanceof IMember)
return ((IMember)element).getDeclaringType();
if (element instanceof GetterSetterEntry)
return ((GetterSetterEntry)element).fField;
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fGetterSetterEntries.keySet().toArray();
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
fGetterSetterEntries.clear();
fGetterSetterEntries= null;
}
}
private static class GetterSetterTreeSelectionDialog extends SourceActionDialog {
private IType fType;
private AddGetterSetterContentProvider fContentProvider;
private static final int SELECT_GETTERS_ID= IDialogConstants.CLIENT_ID + 1;
private static final int SELECT_SETTERS_ID= IDialogConstants.CLIENT_ID + 2;
private IDialogSettings fSettings;
private int fVisibilityModifier;
private boolean fFinal;
private boolean fSynchronized;
private boolean fSortOrder;
private final String SETTINGS_SECTION= "AddGetterSetterDialog"; //$NON-NLS-1$
private final String VISIBILITY_MODIFIER= "VisibilityModifier"; //$NON-NLS-1$
private final String FINAL_MODIFIER= "FinalModifier"; //$NON-NLS-1$
private final String SYNCHRONIZED_MODIFIER= "SynchronizedModifier"; //$NON-NLS-1$
private final String SORT_ORDER= "SortOrdering"; //$NON-NLS-1$
public GetterSetterTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, AddGetterSetterContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider, editor, type);
fContentProvider= contentProvider;
fType= type;
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
fSettings= dialogSettings.getSection(SETTINGS_SECTION);
if (fSettings == null) {
fSettings= dialogSettings.addNewSection(SETTINGS_SECTION);
fSettings.put(VISIBILITY_MODIFIER, Modifier.PUBLIC); //$NON-NLS-1$
fSettings.put(FINAL_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SYNCHRONIZED_MODIFIER, false); //$NON-NLS-1$
fSettings.put(SORT_ORDER, false); //$NON-NLS-1$
}
fVisibilityModifier= fSettings.getInt(VISIBILITY_MODIFIER);
fFinal= fSettings.getBoolean(FINAL_MODIFIER);
fSynchronized= fSettings.getBoolean(SYNCHRONIZED_MODIFIER);
fSortOrder= fSettings.getBoolean(SORT_ORDER);
}
public boolean isFinal() {
return fFinal;
}
public boolean isSynchronized() {
return fSynchronized;
}
public int getVisibilityModifier() {
return fVisibilityModifier;
}
public boolean getSortOrder() {
return fSortOrder;
}
public boolean getFinal() {
return fFinal;
}
public boolean getSynchronized() {
return fSynchronized;
}
public void setVisibility(int visibility) {
if (fVisibilityModifier != visibility) {
fVisibilityModifier= visibility;
fSettings.put(VISIBILITY_MODIFIER, visibility);
if (fContentProvider.fViewer != null) {
fContentProvider.fViewer.refresh();
}
}
}
public void setFinal(boolean value) {
if (fFinal != value) {
fFinal= value;
fSettings.put(FINAL_MODIFIER, value);
if (fContentProvider.fViewer != null) {
fContentProvider.fViewer.refresh();
}
}
}
public void setSynchronized(boolean value) {
if (fSynchronized != value) {
fSynchronized= value;
fSettings.put(SYNCHRONIZED_MODIFIER, value);
if (fContentProvider.fViewer != null) {
fContentProvider.fViewer.refresh();
}
}
}
public void setSortOrder(boolean sort) {
if (fSortOrder != sort) {
fSortOrder= sort;
fSettings.put(SORT_ORDER, sort);
if (fContentProvider.fViewer != null) {
fContentProvider.fViewer.refresh();
}
}
}
protected void createGetterSetterButtons(Composite buttonComposite) {
createButton(buttonComposite, SELECT_GETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_getters"), false); //$NON-NLS-1$
createButton(buttonComposite, SELECT_SETTERS_ID, ActionMessages.getString("GetterSetterTreeSelectionDialog.select_setters"), false); //$NON-NLS-1$
}
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
switch(buttonId) {
case SELECT_GETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(true));
updateOKStatus();
break;
}
case SELECT_SETTERS_ID: {
getTreeViewer().setCheckedElements(getGetterSetterElements(false));
updateOKStatus();
break;
}
}
}
protected Composite createEntryPtCombo(Composite composite) {
Composite entryComposite= super.createEntryPtCombo(composite);
addSortOrder(entryComposite);
addVisibilityAndModifiersChoices(entryComposite);
return entryComposite;
}
private Composite addSortOrder(Composite composite) {
Label label= new Label(composite, SWT.NONE);
label.setText(ActionMessages.getString("GetterSetterTreeSelectionDialog.sort_label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
label.setLayoutData(gd);
final Combo combo= new Combo(composite, SWT.READ_ONLY);
combo.setItems(new String[]{ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_pair_sort"), //$NON-NLS-1$
ActionMessages.getString("GetterSetterTreeSelectionDialog.alpha_method_sort")}); //$NON-NLS-1$
final int methodIndex= 1; // Hard-coded. Change this if the list gets more complicated.
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
int sort= getSortOrder() ? 1 : 0;
combo.setText(combo.getItem(sort));
gd= new GridData(GridData.FILL_BOTH);
combo.setLayoutData(gd);
combo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
setSortOrder(combo.getSelectionIndex() == methodIndex);
}
});
return composite;
}
private Composite addVisibilityAndModifiersChoices(Composite buttonComposite) {
// Add visibility and modifiers buttons: http://bugs.eclipse.org/bugs/show_bug.cgi?id=35870
// Add persistence of options: http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
IVisibilityChangeListener visibilityChangeListener = new IVisibilityChangeListener(){
public void visibilityChanged(int newVisibility) {
setVisibility(newVisibility);
}
public void modifierChanged(int modifier, boolean isChecked) {
switch (modifier) {
case Modifier.FINAL: {
setFinal(isChecked);
return;
}
case Modifier.SYNCHRONIZED: {
setSynchronized(isChecked);
return;
}
default: return;
}
}
};
int initialVisibility= getVisibilityModifier();
int[] availableVisibilities= new int[]{Modifier.PUBLIC, Modifier.PROTECTED, Modifier.PRIVATE, Modifier.NONE};
Composite visibilityComposite= createVisibilityControlAndModifiers(buttonComposite, visibilityChangeListener, availableVisibilities, initialVisibility);
return visibilityComposite;
}
private List convertToIntegerList(int[] array) {
List result= new ArrayList(array.length);
for (int i= 0; i < array.length; i++) {
result.add(new Integer(array[i]));
}
return result;
}
private Composite createVisibilityControl(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
List allowedVisibilities= convertToIntegerList(availableVisibilities);
if (allowedVisibilities.size() == 1)
return null;
Group group= new Group(parent, SWT.NONE);
group.setText(RefactoringMessages.getString("VisibilityControlUtil.Access_modifier")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
GridLayout layout= new GridLayout();
layout.makeColumnsEqualWidth= true;
layout.numColumns= 4;
group.setLayout(layout);
String[] labels= new String[] {
"&public", //$NON-NLS-1$
"pro&tected", //$NON-NLS-1$
RefactoringMessages.getString("VisibilityControlUtil.defa&ult_4"), //$NON-NLS-1$
"pri&vate" //$NON-NLS-1$
};
Integer[] data= new Integer[] {
new Integer(Modifier.PUBLIC),
new Integer(Modifier.PROTECTED),
new Integer(Modifier.NONE),
new Integer(Modifier.PRIVATE)};
Integer initialVisibility= new Integer(correctVisibility);
for (int i= 0; i < labels.length; i++) {
Button radio= new Button(group, SWT.RADIO);
Integer visibilityCode= data[i];
radio.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
radio.setText(labels[i]);
radio.setData(visibilityCode);
radio.setSelection(visibilityCode.equals(initialVisibility));
radio.setEnabled(allowedVisibilities.contains(visibilityCode));
radio.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.visibilityChanged(((Integer)event.widget.getData()).intValue());
}
});
}
return group;
}
private Composite createVisibilityControlAndModifiers(Composite parent, final IVisibilityChangeListener visibilityChangeListener, int[] availableVisibilities, int correctVisibility) {
Composite visibilityComposite= createVisibilityControl(parent, visibilityChangeListener, availableVisibilities, correctVisibility);
Button finalCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
finalCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.final")); //$NON-NLS-1$
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
finalCheckboxButton.setLayoutData(gd);
finalCheckboxButton.setData(new Integer(Modifier.FINAL));
finalCheckboxButton.setEnabled(true);
finalCheckboxButton.setSelection(isFinal());
finalCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
Button syncCheckboxButton= new Button(visibilityComposite, SWT.CHECK);
syncCheckboxButton.setText(RefactoringMessages.getString("VisibilityControlUtil.synchronized")); //$NON-NLS-1$
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
syncCheckboxButton.setLayoutData(gd);
syncCheckboxButton.setData(new Integer(Modifier.SYNCHRONIZED));
syncCheckboxButton.setEnabled(true);
syncCheckboxButton.setSelection(isSynchronized());
syncCheckboxButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
visibilityChangeListener.modifierChanged(((Integer)event.widget.getData()).intValue(), ((Button) event.widget).getSelection());
}
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
});
return visibilityComposite;
}
private Object[] getGetterSetterElements(boolean isGetter){
Object[] allFields= fContentProvider.getElements(null);
Set result= new HashSet();
for (int i = 0; i < allFields.length; i++) {
IField field= (IField)allFields[i];
GetterSetterEntry[] entries= getEntries(field);
for (int j = 0; j < entries.length; j++) {
AddGetterSetterAction.GetterSetterEntry entry= entries[j];
if (entry.fGetterEntry == isGetter)
result.add(entry);
}
}
return result.toArray();
}
private GetterSetterEntry[] getEntries(IField field) {
List result= Arrays.asList(fContentProvider.getChildren(field));
return (GetterSetterEntry[]) result.toArray(new GetterSetterEntry[result.size()]);
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
createGetterSetterButtons(buttonComposite);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
/*
* @see Dialog#createDialogArea(Composite)
*/
protected Control createDialogArea(Composite parent) {
Control control= super.createDialogArea(parent);
try {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=38400
getTreeViewer().setExpandedElements(fType.getFields());
getTreeViewer().reveal(fContentProvider.getPreselected());
getTreeViewer().refresh();
} catch (JavaModelException e) {
}
return control;
}
}
private static class GetterSetterEntry {
public final IField fField;
public final boolean fGetterEntry;
GetterSetterEntry(IField field, boolean isGetterEntry){
fField= field;
fGetterEntry= isGetterEntry;
}
}
}
|
39,227 |
Bug 39227 Text edits: Failure in when delting move source
|
20030623 Added testMoveWithSourceDelete2. Difference to testMoveWithSourceDelete1 is that the taget position is greater than the source position
|
resolved fixed
|
51a979d
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-23T15:00:21Z | 2003-06-23T14:53:20Z |
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/TextBufferTest.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.tests.core;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.internal.corext.textmanipulation.CopySourceEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.CopyTargetEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MoveSourceEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MoveTargetEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MultiTextEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.RangeMarker;
import org.eclipse.jdt.internal.corext.textmanipulation.SimpleTextEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.TextBuffer;
import org.eclipse.jdt.internal.corext.textmanipulation.TextBufferEditor;
import org.eclipse.jdt.internal.corext.textmanipulation.TextRange;
import org.eclipse.jdt.internal.corext.textmanipulation.UndoMemento;
public class TextBufferTest extends TestCase {
private static final Class THIS= TextBufferTest.class;
private TextBuffer fBuffer;
private TextBufferEditor fEditor;
public TextBufferTest(String name) {
super(name);
}
public static Test allTests() {
return new TestSuite(THIS);
}
public static Test suite() {
TestSuite result= new TestSuite(THIS);
if (false) { // For hot code replace when debugging test cases
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
}
return result;
}
protected void setUp() throws Exception {
fBuffer= TextBuffer.create("0123456789");
fEditor= new TextBufferEditor(fBuffer);
}
protected void tearDown() throws Exception {
fEditor= null;
}
public void testOverlap1() throws Exception {
// [ [ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(1, 2, "12"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap2() throws Exception {
// [[ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(0, 1, "0"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap3() throws Exception {
// [ [ ]]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(1, 1, "1"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap4() throws Exception {
// [ [ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createReplace(1, 1, "1"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap5() throws Exception {
// [ [] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createInsert(1, "xx"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap6() throws Exception {
// [ [] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createInsert(2, "xx"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap7() throws Exception {
MoveSourceEdit source= new MoveSourceEdit(2, 5);
MoveTargetEdit target= new MoveTargetEdit(3, source);
fEditor.add(source);
fEditor.add(target);
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap8() throws Exception {
MoveSourceEdit source= new MoveSourceEdit(2, 5);
MoveTargetEdit target= new MoveTargetEdit(6, source);
fEditor.add(source);
fEditor.add(target);
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap9() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(3, 1);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
MoveSourceEdit s2= new MoveSourceEdit(2, 3);
MoveTargetEdit t2= new MoveTargetEdit(8, s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(s2);
fEditor.add(t2);
assertFalse(fEditor.canPerformEdits());
}
public void testInsert1() throws Exception {
// [][ ]
SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy");
SimpleTextEdit e2= SimpleTextEdit.createReplace(2, 3, "3456");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 4, 4);
assertEquals("Buffer content", "01yy345656789", fBuffer.getContent());
doUndoRedo(undo, "01yy345656789");
}
public void testInsert2() throws Exception {
// [][]
SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 4, 2);
assertEquals("Buffer content", "01yyxx23456789", fBuffer.getContent());
doUndoRedo(undo, "01yyxx23456789");
}
public void testInsert3() throws Exception {
// [ ][][ ]
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 2, "011");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
SimpleTextEdit e3= SimpleTextEdit.createReplace(2, 2, "2");
fEditor.add(e1);
fEditor.add(e2);
fEditor.add(e3);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 0, 3);
assertEquals(e2.getTextRange(), 3, 2);
assertEquals(e3.getTextRange(), 5, 1);
assertEquals("Buffer content", "011xx2456789", fBuffer.getContent());
doUndoRedo(undo, "011xx2456789");
}
public void testInsert4() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(0, "xx");
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assertEquals(e1.getTextRange(), 0, 2);
assertEquals("Buffer content", "xx0123456789", fBuffer.getContent());
doUndoRedo(undo, "xx0123456789");
}
public void testInsert5() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(10, "xx");
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assertEquals(e1.getTextRange(), 10, 2);
assertEquals("Buffer content", "0123456789xx", fBuffer.getContent());
doUndoRedo(undo, "0123456789xx");
}
public void testInsertReplace1() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createReplace(2, 1, "y");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 4, 1);
assertEquals(e2.getTextRange(), 2, 2);
assertEquals("Buffer content", "01xxy3456789", fBuffer.getContent());
doUndoRedo(undo, "01xxy3456789");
}
public void testDelete1() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(3, 1);
fEditor.add(e1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 0);
assertEquals("Buffer content", "012456789", fBuffer.getContent());
doUndoRedo(undo, "012456789");
}
public void testDelete2() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(4, 1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1);
SimpleTextEdit e3= SimpleTextEdit.createDelete(5, 1);
fEditor.add(e1);
fEditor.add(e2);
fEditor.add(e3);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 0);
assertEquals(e2.getTextRange(), 3, 0);
assertEquals(e3.getTextRange(), 3, 0);
assertEquals("Buffer content", "0126789", fBuffer.getContent());
doUndoRedo(undo, "0126789");
}
public void testDelete3() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(3, "x");
SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1);
fEditor.add(e1);
fEditor.add(e2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 1);
assertEquals(e2.getTextRange(), 4, 0);
assertEquals("Buffer content", "012x456789", fBuffer.getContent());
doUndoRedo(undo, "012x456789");
}
public void testDeleteWithChildren() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(2, 6);
MultiTextEdit e2= new MultiTextEdit();
e1.add(e2);
SimpleTextEdit e3= SimpleTextEdit.createReplace(3,1,"xx");
SimpleTextEdit e4= SimpleTextEdit.createReplace(5,1,"yy");
e2.add(e3);
e2.add(e4);
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0189", fBuffer.getContent());
assertTrue(e2.getTextRange().isDeleted());
assertTrue(e3.getTextRange().isDeleted());
assertTrue(e4.getTextRange().isDeleted());
doUndoRedo(undo, "0189");
}
public void testMove1() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0142356789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 3, 2);
doUndoRedo(undo, "0142356789");
}
public void testMove2() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0156234789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 7, 0);
assertEquals(t1.getTextRange(), 2, 2);
doUndoRedo(undo, "0156234789");
}
public void testMove3() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(4, 1, "x");
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01x5623789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 5, 2);
assertEquals(e2.getTextRange(), 2, 1);
doUndoRedo(undo, "01x5623789");
}
public void testMove4() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(7, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(5, 1, "x");
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0178234x69", fBuffer.getContent());
assertEquals(s1.getTextRange(), 9, 0);
assertEquals(t1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 7, 1);
doUndoRedo(undo, "0178234x69");
}
public void testMove5() throws Exception {
// Move onto itself
MoveSourceEdit s1= new MoveSourceEdit(2, 1);
MoveTargetEdit t1= new MoveTargetEdit(3, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 2, 1);
assertEquals(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndoRedo(undo, "01x3456789");
}
public void testMove6() throws Exception {
// Move onto itself
MoveSourceEdit s1= new MoveSourceEdit(2, 1);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 3, 0);
assertEquals(t1.getTextRange(), 2, 1);
assertEquals(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndoRedo(undo,"01x3456789");
}
public void testMove7() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 3);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(3, 1, "x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01562x4789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 4, 3);
assertEquals(e2.getTextRange(), 5, 1);
doUndoRedo(undo, "01562x4789");
}
public void testMove8() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 3);
MoveTargetEdit t1= new MoveTargetEdit(1, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(6, 1, "x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "05x7123489", fBuffer.getContent());
assertEquals(s1.getTextRange(), 8, 0);
assertEquals(t1.getTextRange(), 1, 3);
assertEquals(e2.getTextRange(), 2, 1);
doUndoRedo(undo, "05x7123489");
}
public void testMove9() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(1, 3);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
MoveSourceEdit s2= new MoveSourceEdit(1, 1);
MoveTargetEdit t2= new MoveTargetEdit(3, s2);
s1.add(s2);
s1.add(t2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 1, 0);
assertEquals(t1.getTextRange(), 2, 3);
assertEquals(s2.getTextRange(), 2, 0);
assertEquals(t2.getTextRange(), 3, 1);
assertEquals("Buffer content", "0421356789", fBuffer.getContent());
doUndoRedo(undo, "0421356789");
}
public void testMove10() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(8, s1);
MoveSourceEdit s2= new MoveSourceEdit(5, 2);
MoveTargetEdit t2= new MoveTargetEdit(1, s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(s2);
fEditor.add(t2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 4, 0);
assertEquals(t1.getTextRange(), 6, 2);
assertEquals(s2.getTextRange(), 5, 0);
assertEquals(t2.getTextRange(), 1, 2);
assertEquals("Buffer content", "0561472389", fBuffer.getContent());
doUndoRedo(undo, "0561472389");
}
public void testMoveWithTargetDelete() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 3);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(6, 2);
e2.add(t1);
fEditor.add(s1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01589", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertTrue(t1.getTextRange().isDeleted());
assertEquals(e2.getTextRange(), 3, 0);
doUndoRedo(undo, "01589");
}
public void testMoveWithSourceDelete() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 2);
MoveTargetEdit t1= new MoveTargetEdit(1, s1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(5, 2);
e2.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0561234789", fBuffer.getContent());
assertTrue(s1.getTextRange().isDeleted());
assertEquals(t1.getTextRange(), 1, 2);
assertEquals(e2.getTextRange(), 7, 0);
doUndoRedo(undo, "0561234789");
}
public void testMoveUpWithInnerMark() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(7, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit m= SimpleTextEdit.createReplace(4, 1, "yy");
fEditor.add(t1);
fEditor.add(m);
fEditor.add(s1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "017823yy569", fBuffer.getContent());
assertEquals(s1.getTextRange(), 10, 0);
assertEquals(t1.getTextRange(), 2, 2);
assertEquals(m.getTextRange(), 6, 2);
doUndoRedo(undo, "017823yy569");
}
public void testMoveDownWithInnerMark() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit m= SimpleTextEdit.createReplace(4, 1, "yy");
fEditor.add(t1);
fEditor.add(m);
fEditor.add(s1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01yy5623789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 6, 2);
assertEquals(m.getTextRange(), 2, 2);
doUndoRedo(undo, "01yy5623789");
}
public void testMoveUpWithParentMark() throws Exception {
RangeMarker m= new RangeMarker(2, 6);
MoveSourceEdit s1= new MoveSourceEdit(4, 2);
MoveTargetEdit t1= new MoveTargetEdit(3, s1);
m.add(s1);
m.add(t1);
fEditor.add(m);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0124536789", fBuffer.getContent());
assertEquals(m.getTextRange(), 2, 6);
assertEquals(t1.getTextRange(), 3, 2);
assertEquals(s1.getTextRange(), 6, 0);
doUndoRedo(undo, "0124536789");
}
public void testMoveDownWithParentMark() throws Exception {
RangeMarker m= new RangeMarker(2, 6);
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
m.add(s1);
m.add(t1);
fEditor.add(m);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0142356789", fBuffer.getContent());
assertEquals(m.getTextRange(), 2, 6);
assertEquals(t1.getTextRange(), 3, 2);
assertEquals(s1.getTextRange(), 2, 0);
doUndoRedo(undo, "0142356789");
}
public void testCopyDown() throws Exception {
CopySourceEdit s1= new CopySourceEdit(2, 3);
CopyTargetEdit t1= new CopyTargetEdit(8, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 2, 3);
assertEquals(t1.getTextRange(), 8, 3);
String result= "0123456723489";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testCopyUp() throws Exception {
CopySourceEdit s1= new CopySourceEdit(7, 2);
CopyTargetEdit t1= new CopyTargetEdit(3, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 9, 2);
assertEquals(t1.getTextRange(), 3, 2);
String result= "012783456789";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testDoubleCopy() throws Exception {
CopySourceEdit s1= new CopySourceEdit(5, 2);
CopyTargetEdit t1= new CopyTargetEdit(8, s1);
CopySourceEdit s2= new CopySourceEdit(5, 2);
CopyTargetEdit t2= new CopyTargetEdit(2, s2);
s1.add(s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(t2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 7, 2);
assertEquals(t1.getTextRange(), 10, 2);
assertEquals(s2.getTextRange(), 7, 2);
assertEquals(t2.getTextRange(), 2, 2);
String result= "01562345675689";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testSwap1() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
MultiTextEdit root= new MultiTextEdit();
{
CopySourceEdit innerRoot= new CopySourceEdit(0, 9);
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 9, "");
e1.add(innerRoot);
CopyTargetEdit t1= new CopyTargetEdit(11, innerRoot);
SimpleTextEdit e2= SimpleTextEdit.createReplace(11, 1, "");
CopySourceEdit s2= new CopySourceEdit(11, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(0, s2);
root.add(e1);
root.add(t2);
root.add(e2);
root.add(t1);
editor.add(root);
}
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "3, foo(1, 2)";
assertEquals("Buffer content", result, buffer.getContent());
}
public void testSwap2() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
MultiTextEdit innerRoot= new MultiTextEdit();
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(4, 1, "");
CopySourceEdit s1= new CopySourceEdit(4, 1);
e1.add(s1);
CopyTargetEdit t1= new CopyTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(7, 1, "");
CopySourceEdit s2= new CopySourceEdit(7, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(4, s2);
innerRoot.add(e1);
innerRoot.add(t2);
innerRoot.add(e2);
innerRoot.add(t1);
}
editor.add(innerRoot);
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "foo(2, 1), 3";
assertEquals("Buffer content", result, buffer.getContent());
}
public void testSwap2InSwap1() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
CopySourceEdit innerRoot= new CopySourceEdit(0, 9);
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(4, 1, "");
CopySourceEdit s1= new CopySourceEdit(4, 1);
e1.add(s1);
CopyTargetEdit t1= new CopyTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(7, 1, "");
CopySourceEdit s2= new CopySourceEdit(7, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(4, s2);
innerRoot.add(e1);
innerRoot.add(t2);
innerRoot.add(e2);
innerRoot.add(t1);
}
MultiTextEdit root= new MultiTextEdit();
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 9, "");
e1.add(innerRoot);
CopyTargetEdit t1= new CopyTargetEdit(11, innerRoot);
SimpleTextEdit e2= SimpleTextEdit.createReplace(11, 1, "");
CopySourceEdit s2= new CopySourceEdit(11, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(0, s2);
root.add(e1);
root.add(t2);
root.add(e2);
root.add(t1);
editor.add(root);
}
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "3, foo(2, 1)";
assertEquals("Buffer content", result, buffer.getContent());
}
private void doUndoRedo(UndoMemento undo, String redoResult) throws Exception {
fEditor.add(undo);
UndoMemento redo= fEditor.performEdits(null);
assertBufferContent();
fEditor.add(redo);
undo= fEditor.performEdits(null);
assertEquals("Buffer content redo", redoResult, fBuffer.getContent());
fEditor.add(undo);
fEditor.performEdits(null);
assertBufferContent();
}
private void assertEquals(TextRange r, int offset, int length) {
assertEquals("Offset", offset, r.getOffset());
assertEquals("Length", length, r.getLength());
}
private void assertBufferContent() {
assertEquals("Buffer content restored", "0123456789", fBuffer.getContent());
}
private void assertTrue(IStatus status) {
assertTrue(status.isOK());
}
private void assertTrue(String message, IStatus status) {
assertTrue(message, status.isOK());
}
private void assertFalse(IStatus status) {
assertTrue(!status.isOK());
}
}
|
39,244 |
Bug 39244 modifiersChanged() hook not called in NewTypeWizardPage [code manipulation]
|
The modifiersChanged() hook in NewTypeWizardPage is not being called when a modifier radio-button is selected (public/default/private/protected), it is only being called if a check box is selected (abstract/final/static). I suspect a missing "else if" clause in typePageDialogFieldChanged() in NewTypeWizardPage is the culprit. As such am unable to extend NewTypeWizardPage and validate modifier settings (working on custom "class" wizard extension).
|
resolved fixed
|
c2e23e6
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-24T09:16:34Z | 2003-06-23T20:26:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.compiler.IScanner;
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.CodeGeneration;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure;
import org.eclipse.jdt.internal.corext.codemanipulation.ImportsStructure;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.dom.TokenScanner;
import org.eclipse.jdt.internal.corext.template.Template;
import org.eclipse.jdt.internal.corext.template.Templates;
import org.eclipse.jdt.internal.corext.template.java.JavaContext;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.SWTUtil;
import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.wizards.SuperInterfaceSelectionDialog;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.Separator;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonStatusDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
/**
* The class <code>NewTypeWizardPage</code> contains controls and validation routines
* for a 'New Type WizardPage'. Implementors decide which components to add and to enable.
* Implementors can also customize the validation code. <code>NewTypeWizardPage</code>
* is intended to serve as base class of all wizards that create types like applets, servlets, classes,
* interfaces, etc.
* <p>
* See <code>NewClassWizardPage</code> or <code>NewInterfaceWizardPage</code> for an
* example usage of <code>NewTypeWizardPage</code>.
* </p>
*
* @see org.eclipse.jdt.ui.wizards.NewClassWizardPage
* @see org.eclipse.jdt.ui.wizards.NewInterfaceWizardPage
*
* @since 2.0
*/
public abstract class NewTypeWizardPage extends NewContainerWizardPage {
/**
* Class used in stub creation routines to add needed imports to a
* compilation unit.
*/
public static class ImportsManager {
private IImportsStructure fImportsStructure;
/* package */ ImportsManager(IImportsStructure structure) {
fImportsStructure= structure;
}
/* package */ IImportsStructure getImportsStructure() {
return fImportsStructure;
}
/**
* Adds a new import declaration that is sorted in the existing imports.
* If an import already exists or the import would conflict with another import
* of an other type with the same simple name the import is not added.
*
* @param qualifiedTypeName The fully qualified name of the type to import
* (dot separated)
* @return Returns the simple type name that can be used in the code or the
* fully qualified type name if an import conflict prevented the import
*/
public String addImport(String qualifiedTypeName) {
return fImportsStructure.addImport(qualifiedTypeName);
}
}
/** Public access flag. See The Java Virtual Machine Specification for more details. */
public int F_PUBLIC = Flags.AccPublic;
/** Private access flag. See The Java Virtual Machine Specification for more details. */
public int F_PRIVATE = Flags.AccPrivate;
/** Protected access flag. See The Java Virtual Machine Specification for more details. */
public int F_PROTECTED = Flags.AccProtected;
/** Static access flag. See The Java Virtual Machine Specification for more details. */
public int F_STATIC = Flags.AccStatic;
/** Final access flag. See The Java Virtual Machine Specification for more details. */
public int F_FINAL = Flags.AccFinal;
/** Abstract property flag. See The Java Virtual Machine Specification for more details. */
public int F_ABSTRACT = Flags.AccAbstract;
private final static String PAGE_NAME= "NewTypeWizardPage"; //$NON-NLS-1$
/** Field ID of the package input field */
protected final static String PACKAGE= PAGE_NAME + ".package"; //$NON-NLS-1$
/** Field ID of the eclosing type input field */
protected final static String ENCLOSING= PAGE_NAME + ".enclosing"; //$NON-NLS-1$
/** Field ID of the enclosing type checkbox */
protected final static String ENCLOSINGSELECTION= ENCLOSING + ".selection"; //$NON-NLS-1$
/** Field ID of the type name input field */
protected final static String TYPENAME= PAGE_NAME + ".typename"; //$NON-NLS-1$
/** Field ID of the super type input field */
protected final static String SUPER= PAGE_NAME + ".superclass"; //$NON-NLS-1$
/** Field ID of the super interfaces input field */
protected final static String INTERFACES= PAGE_NAME + ".interfaces"; //$NON-NLS-1$
/** Field ID of the modifier checkboxes */
protected final static String MODIFIERS= PAGE_NAME + ".modifiers"; //$NON-NLS-1$
/** Field ID of the method stubs checkboxes */
protected final static String METHODS= PAGE_NAME + ".methods"; //$NON-NLS-1$
private class InterfacesListLabelProvider extends LabelProvider {
private Image fInterfaceImage;
public InterfacesListLabelProvider() {
super();
fInterfaceImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE);
}
public Image getImage(Object element) {
return fInterfaceImage;
}
}
private StringButtonStatusDialogField fPackageDialogField;
private SelectionButtonDialogField fEnclosingTypeSelection;
private StringButtonDialogField fEnclosingTypeDialogField;
private boolean fCanModifyPackage;
private boolean fCanModifyEnclosingType;
private IPackageFragment fCurrPackage;
private IType fCurrEnclosingType;
private StringDialogField fTypeNameDialogField;
private StringButtonDialogField fSuperClassDialogField;
private ListDialogField fSuperInterfacesDialogField;
private IType fSuperClass;
private SelectionButtonDialogFieldGroup fAccMdfButtons;
private SelectionButtonDialogFieldGroup fOtherMdfButtons;
private IType fCreatedType;
protected IStatus fEnclosingTypeStatus;
protected IStatus fPackageStatus;
protected IStatus fTypeNameStatus;
protected IStatus fSuperClassStatus;
protected IStatus fModifierStatus;
protected IStatus fSuperInterfacesStatus;
private boolean fIsClass;
private int fStaticMdfIndex;
private final int PUBLIC_INDEX= 0, DEFAULT_INDEX= 1, PRIVATE_INDEX= 2, PROTECTED_INDEX= 3;
private final int ABSTRACT_INDEX= 0, FINAL_INDEX= 1;
/**
* Creates a new <code>NewTypeWizardPage</code>
*
* @param isClass <code>true</code> if a new class is to be created; otherwise
* an interface is to be created
* @param pageName the wizard page's name
*/
public NewTypeWizardPage(boolean isClass, String pageName) {
super(pageName);
fCreatedType= null;
fIsClass= isClass;
TypeFieldsAdapter adapter= new TypeFieldsAdapter();
fPackageDialogField= new StringButtonStatusDialogField(adapter);
fPackageDialogField.setDialogFieldListener(adapter);
fPackageDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.package.label")); //$NON-NLS-1$
fPackageDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.package.button")); //$NON-NLS-1$
fPackageDialogField.setStatusWidthHint(NewWizardMessages.getString("NewTypeWizardPage.default")); //$NON-NLS-1$
fEnclosingTypeSelection= new SelectionButtonDialogField(SWT.CHECK);
fEnclosingTypeSelection.setDialogFieldListener(adapter);
fEnclosingTypeSelection.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.enclosing.selection.label")); //$NON-NLS-1$
fEnclosingTypeDialogField= new StringButtonDialogField(adapter);
fEnclosingTypeDialogField.setDialogFieldListener(adapter);
fEnclosingTypeDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.enclosing.button")); //$NON-NLS-1$
fTypeNameDialogField= new StringDialogField();
fTypeNameDialogField.setDialogFieldListener(adapter);
fTypeNameDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.typename.label")); //$NON-NLS-1$
fSuperClassDialogField= new StringButtonDialogField(adapter);
fSuperClassDialogField.setDialogFieldListener(adapter);
fSuperClassDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.superclass.label")); //$NON-NLS-1$
fSuperClassDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.superclass.button")); //$NON-NLS-1$
String[] addButtons= new String[] {
/* 0 */ NewWizardMessages.getString("NewTypeWizardPage.interfaces.add"), //$NON-NLS-1$
/* 1 */ null,
/* 2 */ NewWizardMessages.getString("NewTypeWizardPage.interfaces.remove") //$NON-NLS-1$
};
fSuperInterfacesDialogField= new ListDialogField(adapter, addButtons, new InterfacesListLabelProvider());
fSuperInterfacesDialogField.setDialogFieldListener(adapter);
String interfaceLabel= fIsClass ? NewWizardMessages.getString("NewTypeWizardPage.interfaces.class.label") : NewWizardMessages.getString("NewTypeWizardPage.interfaces.ifc.label"); //$NON-NLS-1$ //$NON-NLS-2$
fSuperInterfacesDialogField.setLabelText(interfaceLabel);
fSuperInterfacesDialogField.setRemoveButtonIndex(2);
String[] buttonNames1= new String[] {
/* 0 == PUBLIC_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.public"), //$NON-NLS-1$
/* 1 == DEFAULT_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.default"), //$NON-NLS-1$
/* 2 == PRIVATE_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.private"), //$NON-NLS-1$
/* 3 == PROTECTED_INDEX*/ NewWizardMessages.getString("NewTypeWizardPage.modifiers.protected") //$NON-NLS-1$
};
fAccMdfButtons= new SelectionButtonDialogFieldGroup(SWT.RADIO, buttonNames1, 4);
fAccMdfButtons.setDialogFieldListener(adapter);
fAccMdfButtons.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.modifiers.acc.label")); //$NON-NLS-1$
fAccMdfButtons.setSelection(0, true);
String[] buttonNames2;
if (fIsClass) {
buttonNames2= new String[] {
/* 0 == ABSTRACT_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.abstract"), //$NON-NLS-1$
/* 1 == FINAL_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.final"), //$NON-NLS-1$
/* 2 */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
};
fStaticMdfIndex= 2; // index of the static checkbox is 2
} else {
buttonNames2= new String[] {
NewWizardMessages.getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
};
fStaticMdfIndex= 0; // index of the static checkbox is 0
}
fOtherMdfButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 4);
fOtherMdfButtons.setDialogFieldListener(adapter);
fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, false);
fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX, false);
fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex, false);
fPackageStatus= new StatusInfo();
fEnclosingTypeStatus= new StatusInfo();
fCanModifyPackage= true;
fCanModifyEnclosingType= true;
updateEnableState();
fTypeNameStatus= new StatusInfo();
fSuperClassStatus= new StatusInfo();
fSuperInterfacesStatus= new StatusInfo();
fModifierStatus= new StatusInfo();
}
/**
* Initializes all fields provided by the page with a given selection.
*
* @param elem the selection used to intialize this page or <code>
* null</code> if no selection was available
*/
protected void initTypePage(IJavaElement elem) {
String initSuperclass= "java.lang.Object"; //$NON-NLS-1$
ArrayList initSuperinterfaces= new ArrayList(5);
IPackageFragment pack= null;
IType enclosingType= null;
if (elem != null) {
// evaluate the enclosing type
pack= (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
IType typeInCU= (IType) elem.getAncestor(IJavaElement.TYPE);
if (typeInCU != null) {
if (typeInCU.getCompilationUnit() != null) {
enclosingType= typeInCU;
}
} else {
ICompilationUnit cu= (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
if (cu != null) {
enclosingType= cu.findPrimaryType();
}
}
try {
IType type= null;
if (elem.getElementType() == IJavaElement.TYPE) {
type= (IType)elem;
if (type.exists()) {
String superName= JavaModelUtil.getFullyQualifiedName(type);
if (type.isInterface()) {
initSuperinterfaces.add(superName);
} else {
initSuperclass= superName;
}
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// ignore this exception now
}
}
setPackageFragment(pack, true);
setEnclosingType(enclosingType, true);
setEnclosingTypeSelection(false, true);
setTypeName("", true); //$NON-NLS-1$
setSuperClass(initSuperclass, true);
setSuperInterfaces(initSuperinterfaces, true);
}
// -------- UI Creation ---------
/**
* Creates a separator line. Expects a <code>GridLayout</code> with at least 1 column.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSeparator(Composite composite, int nColumns) {
(new Separator(SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(composite, nColumns, convertHeightInCharsToPixels(1));
}
/**
* Creates the controls for the package name field. Expects a <code>GridLayout</code> with at
* least 4 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createPackageControls(Composite composite, int nColumns) {
fPackageDialogField.doFillIntoGrid(composite, nColumns);
LayoutUtil.setWidthHint(fPackageDialogField.getTextControl(null), getMaxFieldWidth());
LayoutUtil.setHorizontalGrabbing(fPackageDialogField.getTextControl(null));
}
/**
* Creates the controls for the enclosing type name field. Expects a <code>GridLayout</code> with at
* least 4 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createEnclosingTypeControls(Composite composite, int nColumns) {
// #6891
Composite tabGroup= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.marginWidth= 0;
layout.marginHeight= 0;
tabGroup.setLayout(layout);
fEnclosingTypeSelection.doFillIntoGrid(tabGroup, 1);
Control c= fEnclosingTypeDialogField.getTextControl(composite);
GridData gd= new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint= getMaxFieldWidth();
gd.horizontalSpan= 2;
c.setLayoutData(gd);
Button button= fEnclosingTypeDialogField.getChangeControl(composite);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.heightHint = SWTUtil.getButtonHeigthHint(button);
gd.widthHint = SWTUtil.getButtonWidthHint(button);
button.setLayoutData(gd);
}
/**
* Creates the controls for the type name field. Expects a <code>GridLayout</code> with at
* least 2 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createTypeNameControls(Composite composite, int nColumns) {
fTypeNameDialogField.doFillIntoGrid(composite, nColumns - 1);
DialogField.createEmptySpace(composite);
LayoutUtil.setWidthHint(fTypeNameDialogField.getTextControl(null), getMaxFieldWidth());
}
/**
* Creates the controls for the modifiers radio/ceckbox buttons. Expects a
* <code>GridLayout</code> with at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createModifierControls(Composite composite, int nColumns) {
LayoutUtil.setHorizontalSpan(fAccMdfButtons.getLabelControl(composite), 1);
Control control= fAccMdfButtons.getSelectionButtonsGroup(composite);
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= nColumns - 2;
control.setLayoutData(gd);
DialogField.createEmptySpace(composite);
DialogField.createEmptySpace(composite);
control= fOtherMdfButtons.getSelectionButtonsGroup(composite);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= nColumns - 2;
control.setLayoutData(gd);
DialogField.createEmptySpace(composite);
}
/**
* Creates the controls for the superclass name field. Expects a <code>GridLayout</code>
* with at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSuperClassControls(Composite composite, int nColumns) {
fSuperClassDialogField.doFillIntoGrid(composite, nColumns);
LayoutUtil.setWidthHint(fSuperClassDialogField.getTextControl(null), getMaxFieldWidth());
}
/**
* Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with
* at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSuperInterfacesControls(Composite composite, int nColumns) {
fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
GridData gd= (GridData)fSuperInterfacesDialogField.getListControl(null).getLayoutData();
if (fIsClass) {
gd.heightHint= convertHeightInCharsToPixels(3);
} else {
gd.heightHint= convertHeightInCharsToPixels(6);
}
gd.grabExcessVerticalSpace= false;
gd.widthHint= getMaxFieldWidth();
}
/**
* Sets the focus on the type name input field.
*/
protected void setFocus() {
fTypeNameDialogField.setFocus();
}
// -------- TypeFieldsAdapter --------
private class TypeFieldsAdapter implements IStringButtonAdapter, IDialogFieldListener, IListAdapter {
// -------- IStringButtonAdapter
public void changeControlPressed(DialogField field) {
typePageChangeControlPressed(field);
}
// -------- IListAdapter
public void customButtonPressed(ListDialogField field, int index) {
typePageCustomButtonPressed(field, index);
}
public void selectionChanged(ListDialogField field) {}
// -------- IDialogFieldListener
public void dialogFieldChanged(DialogField field) {
typePageDialogFieldChanged(field);
}
public void doubleClicked(ListDialogField field) {
}
}
private void typePageChangeControlPressed(DialogField field) {
if (field == fPackageDialogField) {
IPackageFragment pack= choosePackage();
if (pack != null) {
fPackageDialogField.setText(pack.getElementName());
}
} else if (field == fEnclosingTypeDialogField) {
IType type= chooseEnclosingType();
if (type != null) {
fEnclosingTypeDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
}
} else if (field == fSuperClassDialogField) {
IType type= chooseSuperType();
if (type != null) {
fSuperClassDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
}
}
}
private void typePageCustomButtonPressed(DialogField field, int index) {
if (field == fSuperInterfacesDialogField) {
chooseSuperInterfaces();
}
}
/*
* A field on the type has changed. The fields' status and all dependend
* status are updated.
*/
private void typePageDialogFieldChanged(DialogField field) {
String fieldName= null;
if (field == fPackageDialogField) {
fPackageStatus= packageChanged();
updatePackageStatusLabel();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= PACKAGE;
} else if (field == fEnclosingTypeDialogField) {
fEnclosingTypeStatus= enclosingTypeChanged();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= ENCLOSING;
} else if (field == fEnclosingTypeSelection) {
updateEnableState();
boolean isEnclosedType= isEnclosingTypeSelected();
if (!isEnclosedType) {
if (fAccMdfButtons.isSelected(PRIVATE_INDEX) || fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
fAccMdfButtons.setSelection(PRIVATE_INDEX, false);
fAccMdfButtons.setSelection(PROTECTED_INDEX, false);
fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
}
if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
fOtherMdfButtons.setSelection(fStaticMdfIndex, false);
}
}
fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, isEnclosedType && fIsClass);
fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX, isEnclosedType && fIsClass);
fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex, isEnclosedType);
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= ENCLOSINGSELECTION;
} else if (field == fTypeNameDialogField) {
fTypeNameStatus= typeNameChanged();
fieldName= TYPENAME;
} else if (field == fSuperClassDialogField) {
fSuperClassStatus= superClassChanged();
fieldName= SUPER;
} else if (field == fSuperInterfacesDialogField) {
fSuperInterfacesStatus= superInterfacesChanged();
fieldName= INTERFACES;
} else if (field == fOtherMdfButtons) {
fModifierStatus= modifiersChanged();
fieldName= MODIFIERS;
} else {
fieldName= METHODS;
}
// tell all others
handleFieldChanged(fieldName);
}
// -------- update message ----------------
/*
* @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#handleFieldChanged(String)
*/
protected void handleFieldChanged(String fieldName) {
super.handleFieldChanged(fieldName);
if (fieldName == CONTAINER) {
fPackageStatus= packageChanged();
fEnclosingTypeStatus= enclosingTypeChanged();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fSuperInterfacesStatus= superInterfacesChanged();
}
}
// ---- set / get ----------------
/**
* Returns the text of the package input field.
*
* @return the text of the package input field
*/
public String getPackageText() {
return fPackageDialogField.getText();
}
/**
* Returns the text of the enclosing type input field.
*
* @return the text of the enclosing type input field
*/
public String getEnclosingTypeText() {
return fEnclosingTypeDialogField.getText();
}
/**
* Returns the package fragment corresponding to the current input.
*
* @return a package fragement or <code>null</code> if the input
* could not be resolved.
*/
public IPackageFragment getPackageFragment() {
if (!isEnclosingTypeSelected()) {
return fCurrPackage;
} else {
if (fCurrEnclosingType != null) {
return fCurrEnclosingType.getPackageFragment();
}
}
return null;
}
/**
* Sets the package fragment to the given value. The method updates the model
* and the text of the control.
*
* @param pack the package fragement to be set
* @param canBeModified if <code>true</code> the package fragment is
* editable; otherwise it is read-only.
*/
public void setPackageFragment(IPackageFragment pack, boolean canBeModified) {
fCurrPackage= pack;
fCanModifyPackage= canBeModified;
String str= (pack == null) ? "" : pack.getElementName(); //$NON-NLS-1$
fPackageDialogField.setText(str);
updateEnableState();
}
/**
* Returns the enclosing type corresponding to the current input.
*
* @return the enclosing type or <code>null</code> if the enclosing type is
* not selected or the input could not be resolved
*/
public IType getEnclosingType() {
if (isEnclosingTypeSelected()) {
return fCurrEnclosingType;
}
return null;
}
/**
* Sets the enclosing type. The method updates the underlying model
* and the text of the control.
*
* @param type the enclosing type
* @param canBeModified if <code>true</code> the enclosing type field is
* editable; otherwise it is read-only.
*/
public void setEnclosingType(IType type, boolean canBeModified) {
fCurrEnclosingType= type;
fCanModifyEnclosingType= canBeModified;
String str= (type == null) ? "" : JavaModelUtil.getFullyQualifiedName(type); //$NON-NLS-1$
fEnclosingTypeDialogField.setText(str);
updateEnableState();
}
/**
* Returns the selection state of the enclosing type checkbox.
*
* @return the seleciton state of the enclosing type checkbox
*/
public boolean isEnclosingTypeSelected() {
return fEnclosingTypeSelection.isSelected();
}
/**
* Sets the enclosing type checkbox's selection state.
*
* @param isSelected the checkbox's selection state
* @param canBeModified if <code>true</code> the enclosing type checkbox is
* modifiable; otherwise it is read-only.
*/
public void setEnclosingTypeSelection(boolean isSelected, boolean canBeModified) {
fEnclosingTypeSelection.setSelection(isSelected);
fEnclosingTypeSelection.setEnabled(canBeModified);
updateEnableState();
}
/**
* Returns the type name entered into the type input field.
*
* @return the type name
*/
public String getTypeName() {
return fTypeNameDialogField.getText();
}
/**
* Sets the type name input field's text to the given value. Method doesn't update
* the model.
*
* @param name the new type name
* @param canBeModified if <code>true</code> the enclosing type name field is
* editable; otherwise it is read-only.
*/
public void setTypeName(String name, boolean canBeModified) {
fTypeNameDialogField.setText(name);
fTypeNameDialogField.setEnabled(canBeModified);
}
/**
* Returns the selected modifiers.
*
* @return the selected modifiers
* @see Flags
*/
public int getModifiers() {
int mdf= 0;
if (fAccMdfButtons.isSelected(PUBLIC_INDEX)) {
mdf+= F_PUBLIC;
} else if (fAccMdfButtons.isSelected(PRIVATE_INDEX)) {
mdf+= F_PRIVATE;
} else if (fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
mdf+= F_PROTECTED;
}
if (fOtherMdfButtons.isSelected(ABSTRACT_INDEX) && (fStaticMdfIndex != 0)) {
mdf+= F_ABSTRACT;
}
if (fOtherMdfButtons.isSelected(FINAL_INDEX)) {
mdf+= F_FINAL;
}
if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
mdf+= F_STATIC;
}
return mdf;
}
/**
* Sets the modifiers.
*
* @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
* <code>F_PROTECTED</code>, <code>F_ABSTRACT, F_FINAL</code>
* or <code>F_STATIC</code> or, a valid combination.
* @param canBeModified if <code>true</code> the modifier fields are
* editable; otherwise they are read-only
* @see Flags
*/
public void setModifiers(int modifiers, boolean canBeModified) {
if (Flags.isPublic(modifiers)) {
fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
} else if (Flags.isPrivate(modifiers)) {
fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
} else if (Flags.isProtected(modifiers)) {
fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
} else {
fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
}
if (Flags.isAbstract(modifiers)) {
fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
}
if (Flags.isFinal(modifiers)) {
fOtherMdfButtons.setSelection(FINAL_INDEX, true);
}
if (Flags.isStatic(modifiers)) {
fOtherMdfButtons.setSelection(fStaticMdfIndex, true);
}
fAccMdfButtons.setEnabled(canBeModified);
fOtherMdfButtons.setEnabled(canBeModified);
}
/**
* Returns the content of the superclass input field.
*
* @return the superclass name
*/
public String getSuperClass() {
return fSuperClassDialogField.getText();
}
/**
* Sets the super class name.
*
* @param name the new superclass name
* @param canBeModified if <code>true</code> the superclass name field is
* editable; otherwise it is read-only.
*/
public void setSuperClass(String name, boolean canBeModified) {
fSuperClassDialogField.setText(name);
fSuperClassDialogField.setEnabled(canBeModified);
}
/**
* Returns the chosen super interfaces.
*
* @return a list of chosen super interfaces. The list's elements
* are of type <code>String</code>
*/
public List getSuperInterfaces() {
return fSuperInterfacesDialogField.getElements();
}
/**
* Sets the super interfaces.
*
* @param interfacesNames a list of super interface. The method requires that
* the list's elements are of type <code>String</code>
* @param canBeModified if <code>true</code> the super interface field is
* editable; otherwise it is read-only.
*/
public void setSuperInterfaces(List interfacesNames, boolean canBeModified) {
fSuperInterfacesDialogField.setElements(interfacesNames);
fSuperInterfacesDialogField.setEnabled(canBeModified);
}
// ----------- validation ----------
/**
* A hook method that gets called when the package field has changed. The method
* validates the package name and returns the status of the validation. The validation
* also updates the package fragment model.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus packageChanged() {
StatusInfo status= new StatusInfo();
fPackageDialogField.enableButton(getPackageFragmentRoot() != null);
String packName= getPackageText();
if (packName.length() > 0) {
IStatus val= JavaConventions.validatePackageName(packName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidPackageName", val.getMessage())); //$NON-NLS-1$
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.DiscouragedPackageName", val.getMessage())); //$NON-NLS-1$
// continue
}
}
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root != null) {
if (root.getJavaProject().exists() && packName.length() > 0) {
try {
IPath rootPath= root.getPath();
IPath outputPath= root.getJavaProject().getOutputLocation();
if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
// if the bin folder is inside of our root, dont allow to name a package
// like the bin folder
IPath packagePath= rootPath.append(packName.replace('.', '/'));
if (outputPath.isPrefixOf(packagePath)) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ClashOutputLocation")); //$NON-NLS-1$
return status;
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// let pass
}
}
fCurrPackage= root.getPackageFragment(packName);
} else {
status.setError(""); //$NON-NLS-1$
}
return status;
}
/*
* Updates the 'default' label next to the package field.
*/
private void updatePackageStatusLabel() {
String packName= getPackageText();
if (packName.length() == 0) {
fPackageDialogField.setStatus(NewWizardMessages.getString("NewTypeWizardPage.default")); //$NON-NLS-1$
} else {
fPackageDialogField.setStatus(""); //$NON-NLS-1$
}
}
/*
* Updates the enable state of buttons related to the enclosing type selection checkbox.
*/
private void updateEnableState() {
boolean enclosing= isEnclosingTypeSelected();
fPackageDialogField.setEnabled(fCanModifyPackage && !enclosing);
fEnclosingTypeDialogField.setEnabled(fCanModifyEnclosingType && enclosing);
}
/**
* Hook method that gets called when the enclosing type name has changed. The method
* validates the enclosing type and returns the status of the validation. It also updates the
* enclosing type model.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus enclosingTypeChanged() {
StatusInfo status= new StatusInfo();
fCurrEnclosingType= null;
IPackageFragmentRoot root= getPackageFragmentRoot();
fEnclosingTypeDialogField.enableButton(root != null);
if (root == null) {
status.setError(""); //$NON-NLS-1$
return status;
}
String enclName= getEnclosingTypeText();
if (enclName.length() == 0) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeEnterName")); //$NON-NLS-1$
return status;
}
try {
IType type= findType(root.getJavaProject(), enclName);
if (type == null) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists")); //$NON-NLS-1$
return status;
}
if (type.getCompilationUnit() == null) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotInCU")); //$NON-NLS-1$
return status;
}
if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotEditable")); //$NON-NLS-1$
return status;
}
fCurrEnclosingType= type;
IPackageFragmentRoot enclosingRoot= JavaModelUtil.getPackageFragmentRoot(type);
if (!enclosingRoot.equals(root)) {
status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.EnclosingNotInSourceFolder")); //$NON-NLS-1$
}
return status;
} catch (JavaModelException e) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists")); //$NON-NLS-1$
JavaPlugin.log(e);
return status;
}
}
/**
* Hook method that gets called when the type name has changed. The method validates the
* type name and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus typeNameChanged() {
StatusInfo status= new StatusInfo();
String typeName= getTypeName();
// must not be empty
if (typeName.length() == 0) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnterTypeName")); //$NON-NLS-1$
return status;
}
if (typeName.indexOf('.') != -1) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.QualifiedName")); //$NON-NLS-1$
return status;
}
IStatus val= JavaConventions.validateJavaTypeName(typeName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidTypeName", val.getMessage())); //$NON-NLS-1$
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.TypeNameDiscouraged", val.getMessage())); //$NON-NLS-1$
// continue checking
}
// must not exist
if (!isEnclosingTypeSelected()) {
IPackageFragment pack= getPackageFragment();
if (pack != null) {
ICompilationUnit cu= pack.getCompilationUnit(typeName + ".java"); //$NON-NLS-1$
if (cu.getResource().exists()) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
return status;
}
}
} else {
IType type= getEnclosingType();
if (type != null) {
IType member= type.getType(typeName);
if (member.exists()) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
return status;
}
}
}
return status;
}
/**
* Hook method that gets called when the superclass name has changed. The method
* validates the superclass name and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus superClassChanged() {
StatusInfo status= new StatusInfo();
IPackageFragmentRoot root= getPackageFragmentRoot();
fSuperClassDialogField.enableButton(root != null);
fSuperClass= null;
String sclassName= getSuperClass();
if (sclassName.length() == 0) {
// accept the empty field (stands for java.lang.Object)
return status;
}
IStatus val= JavaConventions.validateJavaTypeName(sclassName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName")); //$NON-NLS-1$
return status;
}
if (root != null) {
try {
IType type= resolveSuperTypeName(root.getJavaProject(), sclassName);
if (type == null) {
status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.SuperClassNotExists")); //$NON-NLS-1$
return status;
} else {
if (type.isInterface()) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotClass", sclassName)); //$NON-NLS-1$
return status;
}
int flags= type.getFlags();
if (Flags.isFinal(flags)) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsFinal", sclassName)); //$NON-NLS-1$
return status;
} else if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotVisible", sclassName)); //$NON-NLS-1$
return status;
}
}
fSuperClass= type;
} catch (JavaModelException e) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName")); //$NON-NLS-1$
JavaPlugin.log(e);
}
} else {
status.setError(""); //$NON-NLS-1$
}
return status;
}
private IType resolveSuperTypeName(IJavaProject jproject, String sclassName) throws JavaModelException {
if (!jproject.exists()) {
return null;
}
IType type= null;
if (isEnclosingTypeSelected()) {
// search in the context of the enclosing type
IType enclosingType= getEnclosingType();
if (enclosingType != null) {
String[][] res= enclosingType.resolveType(sclassName);
if (res != null && res.length > 0) {
type= jproject.findType(res[0][0], res[0][1]);
}
}
} else {
IPackageFragment currPack= getPackageFragment();
if (type == null && currPack != null) {
String packName= currPack.getElementName();
// search in own package
if (!currPack.isDefaultPackage()) {
type= jproject.findType(packName, sclassName);
}
// search in java.lang
if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$
type= jproject.findType("java.lang", sclassName); //$NON-NLS-1$
}
}
// search fully qualified
if (type == null) {
type= jproject.findType(sclassName);
}
}
return type;
}
private IType findType(IJavaProject project, String typeName) throws JavaModelException {
if (project.exists()) {
return project.findType(typeName);
}
return null;
}
/**
* Hook method that gets called when the list of super interface has changed. The method
* validates the superinterfaces and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus superInterfacesChanged() {
StatusInfo status= new StatusInfo();
IPackageFragmentRoot root= getPackageFragmentRoot();
fSuperInterfacesDialogField.enableButton(0, root != null);
if (root != null) {
List elements= fSuperInterfacesDialogField.getElements();
int nElements= elements.size();
for (int i= 0; i < nElements; i++) {
String intfname= (String)elements.get(i);
try {
IType type= findType(root.getJavaProject(), intfname);
if (type == null) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceNotExists", intfname)); //$NON-NLS-1$
return status;
} else {
if (type.isClass()) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotInterface", intfname)); //$NON-NLS-1$
return status;
}
if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotVisible", intfname)); //$NON-NLS-1$
return status;
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// let pass, checking is an extra
}
}
}
return status;
}
/**
* Hook method that gets called when the modifiers have changed. The method validates
* the modifiers and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus modifiersChanged() {
StatusInfo status= new StatusInfo();
int modifiers= getModifiers();
if (Flags.isFinal(modifiers) && Flags.isAbstract(modifiers)) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ModifiersFinalAndAbstract")); //$NON-NLS-1$
}
return status;
}
// selection dialogs
private IPackageFragment choosePackage() {
IPackageFragmentRoot froot= getPackageFragmentRoot();
IJavaElement[] packages= null;
try {
if (froot != null && froot.exists()) {
packages= froot.getChildren();
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
if (packages == null) {
packages= new IJavaElement[0];
}
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
dialog.setIgnoreCase(false);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.description")); //$NON-NLS-1$
dialog.setEmptyListMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.empty")); //$NON-NLS-1$
dialog.setElements(packages);
IPackageFragment pack= getPackageFragment();
if (pack != null) {
dialog.setInitialSelections(new Object[] { pack });
}
if (dialog.open() == ElementListSelectionDialog.OK) {
return (IPackageFragment) dialog.getFirstResult();
}
return null;
}
private IType chooseEnclosingType() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return null;
}
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { root });
TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(), getWizard().getContainer(), IJavaSearchConstants.TYPE, scope);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.description")); //$NON-NLS-1$
dialog.setFilter(Signature.getSimpleName(getEnclosingTypeText()));
if (dialog.open() == TypeSelectionDialog.OK) {
return (IType) dialog.getFirstResult();
}
return null;
}
private IType chooseSuperType() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return null;
}
IJavaElement[] elements= new IJavaElement[] { root.getJavaProject() };
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);
TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(), getWizard().getContainer(), IJavaSearchConstants.CLASS, scope);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.message")); //$NON-NLS-1$
dialog.setFilter(getSuperClass());
if (dialog.open() == TypeSelectionDialog.OK) {
return (IType) dialog.getFirstResult();
}
return null;
}
private void chooseSuperInterfaces() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return;
}
IJavaProject project= root.getJavaProject();
SuperInterfaceSelectionDialog dialog= new SuperInterfaceSelectionDialog(getShell(), getWizard().getContainer(), fSuperInterfacesDialogField, project);
dialog.setTitle(fIsClass ? NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.class.title") : NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.interface.title")); //$NON-NLS-1$ //$NON-NLS-2$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.message")); //$NON-NLS-1$
dialog.open();
return;
}
// ---- creation ----------------
/**
* Creates the new type using the entered field values.
*
* @param monitor a progress monitor to report progress.
*/
public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
monitor.beginTask(NewWizardMessages.getString("NewTypeWizardPage.operationdesc"), 10); //$NON-NLS-1$
ICompilationUnit createdWorkingCopy= null;
try {
IPackageFragmentRoot root= getPackageFragmentRoot();
IPackageFragment pack= getPackageFragment();
if (pack == null) {
pack= root.getPackageFragment(""); //$NON-NLS-1$
}
if (!pack.exists()) {
String packName= pack.getElementName();
pack= root.createPackageFragment(packName, true, null);
}
monitor.worked(1);
String clName= getTypeName();
boolean isInnerClass= isEnclosingTypeSelected();
IType createdType;
ImportsStructure imports;
int indent= 0;
IPreferenceStore store= PreferenceConstants.getPreferenceStore();
String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store);
int threshold= JavaPreferencesSettings.getImportNumberThreshold(store);
String lineDelimiter= null;
if (!isInnerClass) {
lineDelimiter= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
ICompilationUnit parentCU= pack.createCompilationUnit(clName + ".java", "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$ //$NON-NLS-2$
createdWorkingCopy= (ICompilationUnit) parentCU.getSharedWorkingCopy(null, JavaUI.getBufferFactory(), null);
imports= new ImportsStructure(createdWorkingCopy, prefOrder, threshold, false);
// add an import that will be removed again. Having this import solves 14661
imports.addImport(pack.getElementName(), getTypeName());
String typeContent= constructTypeStub(new ImportsManager(imports), lineDelimiter);
String cuContent= constructCUContent(parentCU, typeContent, lineDelimiter);
createdWorkingCopy.getBuffer().setContents(cuContent);
createdType= createdWorkingCopy.getType(clName);
} else {
IType enclosingType= getEnclosingType();
// if we are working on a enclosed type that is open in an editor,
// then replace the enclosing type with its working copy
IType workingCopy= (IType) EditorUtility.getWorkingCopy(enclosingType);
if (workingCopy != null) {
enclosingType= workingCopy;
}
ICompilationUnit parentCU= enclosingType.getCompilationUnit();
imports= new ImportsStructure(parentCU, prefOrder, threshold, true);
// add imports that will be removed again. Having the imports solves 14661
IType[] topLevelTypes= parentCU.getTypes();
for (int i= 0; i < topLevelTypes.length; i++) {
imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
}
lineDelimiter= StubUtility.getLineDelimiterUsed(enclosingType);
StringBuffer content= new StringBuffer();
String comment= getTypeComment(parentCU);
if (comment != null) {
content.append(comment);
content.append(lineDelimiter);
}
content.append(constructTypeStub(new ImportsManager(imports), lineDelimiter));
IJavaElement[] elems= enclosingType.getChildren();
IJavaElement sibling= elems.length > 0 ? elems[0] : null;
createdType= enclosingType.createType(content.toString(), sibling, false, new SubProgressMonitor(monitor, 1));
indent= StubUtility.getIndentUsed(enclosingType) + 1;
}
// add imports for superclass/interfaces, so types can be resolved correctly
imports.create(false, new SubProgressMonitor(monitor, 1));
ICompilationUnit cu= createdType.getCompilationUnit();
synchronized(cu) {
cu.reconcile();
}
createTypeMembers(createdType, new ImportsManager(imports), new SubProgressMonitor(monitor, 1));
// add imports
imports.create(false, new SubProgressMonitor(monitor, 1));
synchronized(cu) {
cu.reconcile();
}
ISourceRange range= createdType.getSourceRange();
IBuffer buf= cu.getBuffer();
String originalContent= buf.getText(range.getOffset(), range.getLength());
String formattedContent= StubUtility.codeFormat(originalContent, indent, lineDelimiter);
buf.replace(range.getOffset(), range.getLength(), formattedContent);
if (!isInnerClass) {
String fileComment= getFileComment(cu);
if (fileComment != null && fileComment.length() > 0) {
buf.replace(0, 0, fileComment + lineDelimiter);
}
cu.commit(false, new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
fCreatedType= createdType;
} finally {
if (createdWorkingCopy != null) {
createdWorkingCopy.destroy();
}
monitor.done();
}
}
/**
* Uses the New Java file template from the code template page to generate a
* compilation unit with the given type content.
* @param cu The new created compilation unit
* @param typeContent The content of the type, including signature and type
* body.
* @param lineDelimiter The line delimiter to be used.
* @return String Returns the result of evaluating the new file template
* with the given type content.
* @throws CoreException
* @since 2.1
*/
protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
StringBuffer typeQualifiedName= new StringBuffer();
if (isEnclosingTypeSelected()) {
typeQualifiedName.append(JavaModelUtil.getTypeQualifiedName(getEnclosingType())).append('.');
}
typeQualifiedName.append(getTypeName());
String typeComment= CodeGeneration.getTypeComment(cu, typeQualifiedName.toString(), lineDelimiter);
IPackageFragment pack= (IPackageFragment) cu.getParent();
String content= CodeGeneration.getCompilationUnitContent(cu, typeComment, typeContent, lineDelimiter);
if (content != null) {
CompilationUnit unit= AST.parseCompilationUnit(content.toCharArray());
if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
return content;
}
}
StringBuffer buf= new StringBuffer();
if (!pack.isDefaultPackage()) {
buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
}
buf.append(lineDelimiter).append(lineDelimiter);
if (typeComment != null) {
buf.append(typeComment).append(lineDelimiter);
}
buf.append(typeContent);
return buf.toString();
}
/**
* Returns the created type. The method only returns a valid type
* after <code>createType</code> has been called.
*
* @return the created type
* @see #createType(IProgressMonitor)
*/
public IType getCreatedType() {
return fCreatedType;
}
// ---- construct cu body----------------
private void writeSuperClass(StringBuffer buf, ImportsManager imports) {
String typename= getSuperClass();
if (fIsClass && typename.length() > 0 && !"java.lang.Object".equals(typename)) { //$NON-NLS-1$
buf.append(" extends "); //$NON-NLS-1$
String qualifiedName= fSuperClass != null ? JavaModelUtil.getFullyQualifiedName(fSuperClass) : typename;
buf.append(imports.addImport(qualifiedName));
}
}
private void writeSuperInterfaces(StringBuffer buf, ImportsManager imports) {
List interfaces= getSuperInterfaces();
int last= interfaces.size() - 1;
if (last >= 0) {
if (fIsClass) {
buf.append(" implements "); //$NON-NLS-1$
} else {
buf.append(" extends "); //$NON-NLS-1$
}
for (int i= 0; i <= last; i++) {
String typename= (String) interfaces.get(i);
buf.append(imports.addImport(typename));
if (i < last) {
buf.append(',');
}
}
}
}
/*
* Called from createType to construct the source for this type
*/
private String constructTypeStub(ImportsManager imports, String lineDelimiter) {
StringBuffer buf= new StringBuffer();
int modifiers= getModifiers();
buf.append(Flags.toString(modifiers));
if (modifiers != 0) {
buf.append(' ');
}
buf.append(fIsClass ? "class " : "interface "); //$NON-NLS-2$ //$NON-NLS-1$
buf.append(getTypeName());
writeSuperClass(buf, imports);
writeSuperInterfaces(buf, imports);
buf.append('{');
buf.append(lineDelimiter);
buf.append(lineDelimiter);
buf.append('}');
buf.append(lineDelimiter);
return buf.toString();
}
/**
* @deprecated Overwrite createTypeMembers(IType, IImportsManager, IProgressMonitor) instead
*/
protected void createTypeMembers(IType newType, IImportsStructure imports, IProgressMonitor monitor) throws CoreException {
//deprecated
}
/**
* Hook method that gets called from <code>createType</code> to support adding of
* unanticipated methods, fields, and inner types to the created type.
* <p>
* Implementers can use any methods defined on <code>IType</code> to manipulate the
* new type.
* </p>
* <p>
* The source code of the new type will be formtted using the platform's formatter. Needed
* imports are added by the wizard at the end of the type creation process using the given
* import manager.
* </p>
*
* @param newType the new type created via <code>createType</code>
* @param imports an import manager which can be used to add new imports
* @param monitor a progress monitor to report progress. Must not be <code>null</code>
*
* @see #createType(IProgressMonitor)
*/
protected void createTypeMembers(IType newType, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
// call for compatibility
createTypeMembers(newType, ((ImportsManager)imports).getImportsStructure(), monitor);
// default implementation does nothing
// example would be
// String mainMathod= "public void foo(Vector vec) {}"
// createdType.createMethod(main, null, false, null);
// imports.addImport("java.lang.Vector");
}
/**
* @deprecated Instead of file templates, the new type code template
* specifies the stub for a compilation unit.
*/
protected String getFileComment(ICompilationUnit parentCU) {
return null;
}
private boolean isValidComment(String template) {
IScanner scanner= ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next= scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next= scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
/**
* Hook method that gets called from <code>createType</code> to retrieve
* a type comment. This default implementation returns the content of the
* 'typecomment' template.
*
* @return the type comment or <code>null</code> if a type comment
* is not desired
*/
protected String getTypeComment(ICompilationUnit parentCU) {
if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS)) {
try {
StringBuffer typeName= new StringBuffer();
if (isEnclosingTypeSelected()) {
typeName.append(JavaModelUtil.getTypeQualifiedName(getEnclosingType())).append('.');
}
typeName.append(getTypeName());
String comment= CodeGeneration.getTypeComment(parentCU, typeName.toString(), String.valueOf('\n'));
if (comment != null && isValidComment(comment)) {
return comment;
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
return null;
}
/**
* @deprecated Use getTemplate(String,ICompilationUnit,int)
*/
protected String getTemplate(String name, ICompilationUnit parentCU) {
return getTemplate(name, parentCU, 0);
}
/**
* Returns the string resulting from evaluation the given template in
* the context of the given compilation unit. This accesses the normal
* template page, not the code templates. To use code templates use
* <code>constructCUContent</code> to construct a compilation unit stub or
* getTypeComment for the comment of the type.
*
* @param name the template to be evaluated
* @param parentCU the templates evaluation context
* @param pos a source offset into the parent compilation unit. The
* template is evalutated at the given source offset
*/
protected String getTemplate(String name, ICompilationUnit parentCU, int pos) {
try {
Template[] templates= Templates.getInstance().getTemplates(name);
if (templates.length > 0) {
return JavaContext.evaluateTemplate(templates[0], parentCU, pos);
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
return null;
}
/**
* @deprecated Use createInheritedMethods(IType,boolean,boolean,IImportsManager,IProgressMonitor)
*/
protected IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, IImportsStructure imports, IProgressMonitor monitor) throws CoreException {
return createInheritedMethods(type, doConstructors, doUnimplementedMethods, new ImportsManager(imports), monitor);
}
/**
* Creates the bodies of all unimplemented methods and constructors and adds them to the type.
* Method is typically called by implementers of <code>NewTypeWizardPage</code> to add
* needed method and constructors.
*
* @param type the type for which the new methods and constructor are to be created
* @param doConstructors if <code>true</code> unimplemented constructors are created
* @param doUnimplementedMethods if <code>true</code> unimplemented methods are created
* @param imports an import manager to add all neded import statements
* @param monitor a progress monitor to report progress
*/
protected IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
ArrayList newMethods= new ArrayList();
ITypeHierarchy hierarchy= null;
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
if (doConstructors) {
hierarchy= type.newSupertypeHierarchy(monitor);
IType superclass= hierarchy.getSuperclass(type);
if (superclass != null) {
String[] constructors= StubUtility.evalConstructors(type, superclass, settings, imports.getImportsStructure());
if (constructors != null) {
for (int i= 0; i < constructors.length; i++) {
newMethods.add(constructors[i]);
}
}
}
}
if (doUnimplementedMethods) {
if (hierarchy == null) {
hierarchy= type.newSupertypeHierarchy(monitor);
}
String[] unimplemented= StubUtility.evalUnimplementedMethods(type, hierarchy, false, settings, imports.getImportsStructure());
if (unimplemented != null) {
for (int i= 0; i < unimplemented.length; i++) {
newMethods.add(unimplemented[i]);
}
}
}
IMethod[] createdMethods= new IMethod[newMethods.size()];
for (int i= 0; i < newMethods.size(); i++) {
String content= (String) newMethods.get(i) + '\n'; // content will be formatted, ok to use \n
createdMethods[i]= type.createMethod(content, null, false, null);
}
return createdMethods;
}
// ---- creation ----------------
/**
* Returns the runnable that creates the type using the current settings.
* The returned runnable must be executed in the UI thread.
*
* @return the runnable to create the new type
*/
public IRunnableWithProgress getRunnable() {
return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
createType(monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
}
}
|
39,027 |
Bug 39027 [working sets] Edit active working set prevents removal of closed projects.
|
When editing the "active working set" closed projects cannot be removed from the working set, the project has to be opened so it can be removed. This is a minor usability issue.
|
resolved fixed
|
49372ab
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-24T10:36:43Z | 2003-06-17T17:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPage.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.workingsets;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreeViewerListener;
import org.eclipse.jface.viewers.TreeExpansionEvent;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IWorkingSetPage;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ui.JavaElementSorter;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
/**
* The Java working set page allows the user to create
* and edit a Java working set.
* <p>
* Working set elements are presented as a Java element tree.
* </p>
*
* @since 2.0
*/
public class JavaWorkingSetPage extends WizardPage implements IWorkingSetPage {
final private static String PAGE_TITLE= WorkingSetMessages.getString("JavaWorkingSetPage.title"); //$NON-NLS-1$
final private static String PAGE_ID= "javaWorkingSetPage"; //$NON-NLS-1$
private Text fWorkingSetName;
private CheckboxTreeViewer fTree;
private ITreeContentProvider fTreeContentProvider;
private boolean fFirstCheck;
private IWorkingSet fWorkingSet;
/**
* Default constructor.
*/
public JavaWorkingSetPage() {
super(PAGE_ID, PAGE_TITLE, JavaPluginImages.DESC_WIZBAN_JAVA_WORKINGSET);
setDescription(WorkingSetMessages.getString("JavaWorkingSetPage.workingSet.description")); //$NON-NLS-1$
fFirstCheck= true;
}
/*
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
setControl(composite);
Label label= new Label(composite, SWT.WRAP);
label.setText(WorkingSetMessages.getString("JavaWorkingSetPage.workingSet.name")); //$NON-NLS-1$
GridData gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
label.setLayoutData(gd);
fWorkingSetName= new Text(composite, SWT.SINGLE | SWT.BORDER);
fWorkingSetName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
fWorkingSetName.addModifyListener(
new ModifyListener() {
public void modifyText(ModifyEvent e) {
validateInput();
}
}
);
fWorkingSetName.setFocus();
label= new Label(composite, SWT.WRAP);
label.setText(WorkingSetMessages.getString("JavaWorkingSetPage.workingSet.content")); //$NON-NLS-1$
gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
label.setLayoutData(gd);
fTree= new CheckboxTreeViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
gd= new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
gd.heightHint= convertHeightInCharsToPixels(15);
fTree.getControl().setLayoutData(gd);
fTreeContentProvider= new JavaWorkingSetPageContentProvider();
fTree.setContentProvider(fTreeContentProvider);
AppearanceAwareLabelProvider fJavaElementLabelProvider=
new AppearanceAwareLabelProvider(
AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED,
AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS
);
fTree.setLabelProvider(new DecoratingJavaLabelProvider(fJavaElementLabelProvider));
fTree.setSorter(new JavaElementSorter());
fTree.addFilter(new EmptyInnerPackageFilter());
fTree.setUseHashlookup(true);
fTree.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()));
fTree.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
handleCheckStateChange(event);
}
});
fTree.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
}
public void treeExpanded(TreeExpansionEvent event) {
final Object element= event.getElement();
if (fTree.getGrayed(element) == false)
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
setSubtreeChecked(element, fTree.getChecked(element), false);
}
});
}
});
if (fWorkingSet != null)
fWorkingSetName.setText(fWorkingSet.getName());
initializeCheckedState();
disableClosedProjects();
validateInput();
Dialog.applyDialogFont(composite);
// Set help for the page
JavaUIHelp.setHelp(fTree, IJavaHelpContextIds.JAVA_WORKING_SET_PAGE);
}
/*
* Implements method from IWorkingSetPage
*/
public IWorkingSet getSelection() {
return fWorkingSet;
}
/*
* Implements method from IWorkingSetPage
*/
public void setSelection(IWorkingSet workingSet) {
Assert.isNotNull(workingSet, "Working set must not be null"); //$NON-NLS-1$
fWorkingSet= workingSet;
if (getContainer() != null && getShell() != null && fWorkingSetName != null) {
fFirstCheck= false;
fWorkingSetName.setText(fWorkingSet.getName());
initializeCheckedState();
disableClosedProjects();
validateInput();
}
}
/*
* Implements method from IWorkingSetPage
*/
public void finish() {
String workingSetName= fWorkingSetName.getText();
ArrayList elements= new ArrayList(10);
findCheckedElements(elements, fTree.getInput());
if (fWorkingSet == null) {
IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
fWorkingSet= workingSetManager.createWorkingSet(workingSetName, (IAdaptable[])elements.toArray(new IAdaptable[elements.size()]));
} else {
// Add inaccessible resources
IAdaptable[] oldItems= fWorkingSet.getElements();
for (int i= 0; i < oldItems.length; i++) {
IResource oldResource= null;
if (oldItems[i] instanceof IResource) {
oldResource= (IResource)oldItems[i];
} else {
oldResource= (IResource)oldItems[i].getAdapter(IResource.class);
}
if (oldResource != null && oldResource.isAccessible() == false) {
elements.add(oldResource);
}
}
fWorkingSet.setName(workingSetName);
fWorkingSet.setElements((IAdaptable[]) elements.toArray(new IAdaptable[elements.size()]));
}
}
private void validateInput() {
String errorMessage= null; //$NON-NLS-1$
String newText= fWorkingSetName.getText();
if (newText.equals(newText.trim()) == false)
errorMessage = WorkingSetMessages.getString("JavaWorkingSetPage.warning.nameWhitespace"); //$NON-NLS-1$
if (newText.equals("")) { //$NON-NLS-1$
if (fFirstCheck) {
setPageComplete(false);
fFirstCheck= false;
return;
}
else
errorMessage= WorkingSetMessages.getString("JavaWorkingSetPage.warning.nameMustNotBeEmpty"); //$NON-NLS-1$
}
fFirstCheck= false;
if (errorMessage == null && (fWorkingSet == null || newText.equals(fWorkingSet.getName()) == false)) {
IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
for (int i= 0; i < workingSets.length; i++) {
if (newText.equals(workingSets[i].getName())) {
errorMessage= WorkingSetMessages.getString("JavaWorkingSetPage.warning.workingSetExists"); //$NON-NLS-1$
}
}
}
if (errorMessage == null && !hasCheckedElement())
errorMessage= WorkingSetMessages.getString("JavaWorkingSetPage.warning.resourceMustBeChecked"); //$NON-NLS-1$
setErrorMessage(errorMessage);
setPageComplete(errorMessage == null);
}
private boolean hasCheckedElement() {
TreeItem[] items= fTree.getTree().getItems();
for (int i= 0; i < items.length; i++) {
if (items[i].getChecked())
return true;
}
return false;
}
private void disableClosedProjects() {
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i= 0; i < projects.length; i++) {
if (!projects[i].isOpen())
fTree.setGrayed(projects[i], true);
}
}
private void findCheckedElements(List checkedResources, Object parent) {
Object[] children= fTreeContentProvider.getChildren(parent);
for (int i= 0; i < children.length; i++) {
if (fTree.getGrayed(children[i]))
findCheckedElements(checkedResources, children[i]);
else if (fTree.getChecked(children[i]))
checkedResources.add(children[i]);
}
}
void handleCheckStateChange(final CheckStateChangedEvent event) {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
IAdaptable element= (IAdaptable)event.getElement();
IResource resource= (IResource)element.getAdapter(IResource.class);
if (resource != null && !resource.isAccessible()) {
MessageDialog.openInformation(getShell(), WorkingSetMessages.getString("JavaWorkingSetPage.projectClosedDialog.title"), WorkingSetMessages.getString("JavaWorkingSetPage.projectClosedDialog.message")); //$NON-NLS-2$ //$NON-NLS-1$
fTree.setChecked(element, false);
fTree.setGrayed(element, true);
return;
}
boolean state= event.getChecked();
fTree.setGrayed(element, false);
if (isExpandable(element))
setSubtreeChecked(element, state, state); // only check subtree if state is set to true
updateParentState(element, state);
validateInput();
}
});
}
private void setSubtreeChecked(Object parent, boolean state, boolean checkExpandedState) {
if (!(parent instanceof IAdaptable))
return;
IContainer container= (IContainer)((IAdaptable)parent).getAdapter(IContainer.class);
if ((!fTree.getExpandedState(parent) && checkExpandedState) || (container != null && !container.isAccessible()))
return;
Object[] children= fTreeContentProvider.getChildren(parent);
for (int i= children.length - 1; i >= 0; i--) {
Object element= children[i];
if (state) {
fTree.setChecked(element, true);
fTree.setGrayed(element, false);
}
else
fTree.setGrayChecked(element, false);
if (isExpandable(element))
setSubtreeChecked(element, state, true);
}
}
private void updateParentState(Object child, boolean baseChildState) {
if (child == null)
return;
if (child instanceof IAdaptable) {
IResource resource= (IResource)((IAdaptable)child).getAdapter(IResource.class);
if (resource != null && !resource.isAccessible())
return;
}
Object parent= fTreeContentProvider.getParent(child);
if (parent == null)
return;
boolean allSameState= true;
Object[] children= null;
children= fTreeContentProvider.getChildren(parent);
for (int i= children.length -1; i >= 0; i--) {
if (fTree.getChecked(children[i]) != baseChildState || fTree.getGrayed(children[i])) {
allSameState= false;
break;
}
}
fTree.setGrayed(parent, !allSameState);
fTree.setChecked(parent, !allSameState || baseChildState);
updateParentState(parent, baseChildState);
}
private void initializeCheckedState() {
if (fWorkingSet == null)
return;
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
Object[] elements= fWorkingSet.getElements();
fTree.setCheckedElements(elements);
for (int i= 0; i < elements.length; i++) {
Object element= elements[i];
if (isExpandable(element))
setSubtreeChecked(element, true, true);
updateParentState(element, true);
}
}
});
}
private boolean isExpandable(Object element) {
return (
element instanceof IJavaProject
||
element instanceof IPackageFragmentRoot
||
element instanceof IPackageFragment
||
element instanceof IJavaModel
||
element instanceof IContainer);
}
}
|
39,027 |
Bug 39027 [working sets] Edit active working set prevents removal of closed projects.
|
When editing the "active working set" closed projects cannot be removed from the working set, the project has to be opened so it can be removed. This is a minor usability issue.
|
resolved fixed
|
49372ab
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-24T10:36:43Z | 2003-06-17T17:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPageContentProvider.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.workingsets;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
class JavaWorkingSetPageContentProvider extends StandardJavaElementContentProvider {
public boolean hasChildren(Object element) {
if (element instanceof IPackageFragment) {
IPackageFragment pkg= (IPackageFragment)element;
try {
if (pkg.getKind() == IPackageFragmentRoot.K_BINARY)
return pkg.getChildren().length > 0;
} catch (JavaModelException ex) {
// use super behavior
}
}
return super.hasChildren(element);
}
}
|
35,767 |
Bug 35767 Hook method getTypeComment(ICompilationUnit) is not called [code manipulation]
|
In org.eclipse.jdt.ui.wizards.NewTypeWizardPage the hook method getTypeComment(ICompilationUnit parentCU) should be called from createType(IProgressMonitor monitor). This is true for inner classes; but otherwise only the new type comment template mechanism is used, without giving getTypeComment (and thus overloading sub-classes) a chance to hook in. (I've written a Wizard subclassing NewTypeWizardPage which provides a type comment containing xDoclet Tags. Now only the temlate type comment is inserted in the generated code) Version 2.1, Build id: 200303211418
|
resolved fixed
|
814be07
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-24T16:30:58Z | 2003-03-27T18:33:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.compiler.IScanner;
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.CodeGeneration;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure;
import org.eclipse.jdt.internal.corext.codemanipulation.ImportsStructure;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.dom.TokenScanner;
import org.eclipse.jdt.internal.corext.template.Template;
import org.eclipse.jdt.internal.corext.template.Templates;
import org.eclipse.jdt.internal.corext.template.java.JavaContext;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.SWTUtil;
import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.wizards.SuperInterfaceSelectionDialog;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.Separator;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonStatusDialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
/**
* The class <code>NewTypeWizardPage</code> contains controls and validation routines
* for a 'New Type WizardPage'. Implementors decide which components to add and to enable.
* Implementors can also customize the validation code. <code>NewTypeWizardPage</code>
* is intended to serve as base class of all wizards that create types like applets, servlets, classes,
* interfaces, etc.
* <p>
* See <code>NewClassWizardPage</code> or <code>NewInterfaceWizardPage</code> for an
* example usage of <code>NewTypeWizardPage</code>.
* </p>
*
* @see org.eclipse.jdt.ui.wizards.NewClassWizardPage
* @see org.eclipse.jdt.ui.wizards.NewInterfaceWizardPage
*
* @since 2.0
*/
public abstract class NewTypeWizardPage extends NewContainerWizardPage {
/**
* Class used in stub creation routines to add needed imports to a
* compilation unit.
*/
public static class ImportsManager {
private IImportsStructure fImportsStructure;
/* package */ ImportsManager(IImportsStructure structure) {
fImportsStructure= structure;
}
/* package */ IImportsStructure getImportsStructure() {
return fImportsStructure;
}
/**
* Adds a new import declaration that is sorted in the existing imports.
* If an import already exists or the import would conflict with another import
* of an other type with the same simple name the import is not added.
*
* @param qualifiedTypeName The fully qualified name of the type to import
* (dot separated)
* @return Returns the simple type name that can be used in the code or the
* fully qualified type name if an import conflict prevented the import
*/
public String addImport(String qualifiedTypeName) {
return fImportsStructure.addImport(qualifiedTypeName);
}
}
/** Public access flag. See The Java Virtual Machine Specification for more details. */
public int F_PUBLIC = Flags.AccPublic;
/** Private access flag. See The Java Virtual Machine Specification for more details. */
public int F_PRIVATE = Flags.AccPrivate;
/** Protected access flag. See The Java Virtual Machine Specification for more details. */
public int F_PROTECTED = Flags.AccProtected;
/** Static access flag. See The Java Virtual Machine Specification for more details. */
public int F_STATIC = Flags.AccStatic;
/** Final access flag. See The Java Virtual Machine Specification for more details. */
public int F_FINAL = Flags.AccFinal;
/** Abstract property flag. See The Java Virtual Machine Specification for more details. */
public int F_ABSTRACT = Flags.AccAbstract;
private final static String PAGE_NAME= "NewTypeWizardPage"; //$NON-NLS-1$
/** Field ID of the package input field */
protected final static String PACKAGE= PAGE_NAME + ".package"; //$NON-NLS-1$
/** Field ID of the eclosing type input field */
protected final static String ENCLOSING= PAGE_NAME + ".enclosing"; //$NON-NLS-1$
/** Field ID of the enclosing type checkbox */
protected final static String ENCLOSINGSELECTION= ENCLOSING + ".selection"; //$NON-NLS-1$
/** Field ID of the type name input field */
protected final static String TYPENAME= PAGE_NAME + ".typename"; //$NON-NLS-1$
/** Field ID of the super type input field */
protected final static String SUPER= PAGE_NAME + ".superclass"; //$NON-NLS-1$
/** Field ID of the super interfaces input field */
protected final static String INTERFACES= PAGE_NAME + ".interfaces"; //$NON-NLS-1$
/** Field ID of the modifier checkboxes */
protected final static String MODIFIERS= PAGE_NAME + ".modifiers"; //$NON-NLS-1$
/** Field ID of the method stubs checkboxes */
protected final static String METHODS= PAGE_NAME + ".methods"; //$NON-NLS-1$
private class InterfacesListLabelProvider extends LabelProvider {
private Image fInterfaceImage;
public InterfacesListLabelProvider() {
super();
fInterfaceImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE);
}
public Image getImage(Object element) {
return fInterfaceImage;
}
}
private StringButtonStatusDialogField fPackageDialogField;
private SelectionButtonDialogField fEnclosingTypeSelection;
private StringButtonDialogField fEnclosingTypeDialogField;
private boolean fCanModifyPackage;
private boolean fCanModifyEnclosingType;
private IPackageFragment fCurrPackage;
private IType fCurrEnclosingType;
private StringDialogField fTypeNameDialogField;
private StringButtonDialogField fSuperClassDialogField;
private ListDialogField fSuperInterfacesDialogField;
private IType fSuperClass;
private SelectionButtonDialogFieldGroup fAccMdfButtons;
private SelectionButtonDialogFieldGroup fOtherMdfButtons;
private IType fCreatedType;
protected IStatus fEnclosingTypeStatus;
protected IStatus fPackageStatus;
protected IStatus fTypeNameStatus;
protected IStatus fSuperClassStatus;
protected IStatus fModifierStatus;
protected IStatus fSuperInterfacesStatus;
private boolean fIsClass;
private int fStaticMdfIndex;
private final int PUBLIC_INDEX= 0, DEFAULT_INDEX= 1, PRIVATE_INDEX= 2, PROTECTED_INDEX= 3;
private final int ABSTRACT_INDEX= 0, FINAL_INDEX= 1;
/**
* Creates a new <code>NewTypeWizardPage</code>
*
* @param isClass <code>true</code> if a new class is to be created; otherwise
* an interface is to be created
* @param pageName the wizard page's name
*/
public NewTypeWizardPage(boolean isClass, String pageName) {
super(pageName);
fCreatedType= null;
fIsClass= isClass;
TypeFieldsAdapter adapter= new TypeFieldsAdapter();
fPackageDialogField= new StringButtonStatusDialogField(adapter);
fPackageDialogField.setDialogFieldListener(adapter);
fPackageDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.package.label")); //$NON-NLS-1$
fPackageDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.package.button")); //$NON-NLS-1$
fPackageDialogField.setStatusWidthHint(NewWizardMessages.getString("NewTypeWizardPage.default")); //$NON-NLS-1$
fEnclosingTypeSelection= new SelectionButtonDialogField(SWT.CHECK);
fEnclosingTypeSelection.setDialogFieldListener(adapter);
fEnclosingTypeSelection.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.enclosing.selection.label")); //$NON-NLS-1$
fEnclosingTypeDialogField= new StringButtonDialogField(adapter);
fEnclosingTypeDialogField.setDialogFieldListener(adapter);
fEnclosingTypeDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.enclosing.button")); //$NON-NLS-1$
fTypeNameDialogField= new StringDialogField();
fTypeNameDialogField.setDialogFieldListener(adapter);
fTypeNameDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.typename.label")); //$NON-NLS-1$
fSuperClassDialogField= new StringButtonDialogField(adapter);
fSuperClassDialogField.setDialogFieldListener(adapter);
fSuperClassDialogField.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.superclass.label")); //$NON-NLS-1$
fSuperClassDialogField.setButtonLabel(NewWizardMessages.getString("NewTypeWizardPage.superclass.button")); //$NON-NLS-1$
String[] addButtons= new String[] {
/* 0 */ NewWizardMessages.getString("NewTypeWizardPage.interfaces.add"), //$NON-NLS-1$
/* 1 */ null,
/* 2 */ NewWizardMessages.getString("NewTypeWizardPage.interfaces.remove") //$NON-NLS-1$
};
fSuperInterfacesDialogField= new ListDialogField(adapter, addButtons, new InterfacesListLabelProvider());
fSuperInterfacesDialogField.setDialogFieldListener(adapter);
String interfaceLabel= fIsClass ? NewWizardMessages.getString("NewTypeWizardPage.interfaces.class.label") : NewWizardMessages.getString("NewTypeWizardPage.interfaces.ifc.label"); //$NON-NLS-1$ //$NON-NLS-2$
fSuperInterfacesDialogField.setLabelText(interfaceLabel);
fSuperInterfacesDialogField.setRemoveButtonIndex(2);
String[] buttonNames1= new String[] {
/* 0 == PUBLIC_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.public"), //$NON-NLS-1$
/* 1 == DEFAULT_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.default"), //$NON-NLS-1$
/* 2 == PRIVATE_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.private"), //$NON-NLS-1$
/* 3 == PROTECTED_INDEX*/ NewWizardMessages.getString("NewTypeWizardPage.modifiers.protected") //$NON-NLS-1$
};
fAccMdfButtons= new SelectionButtonDialogFieldGroup(SWT.RADIO, buttonNames1, 4);
fAccMdfButtons.setDialogFieldListener(adapter);
fAccMdfButtons.setLabelText(NewWizardMessages.getString("NewTypeWizardPage.modifiers.acc.label")); //$NON-NLS-1$
fAccMdfButtons.setSelection(0, true);
String[] buttonNames2;
if (fIsClass) {
buttonNames2= new String[] {
/* 0 == ABSTRACT_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.abstract"), //$NON-NLS-1$
/* 1 == FINAL_INDEX */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.final"), //$NON-NLS-1$
/* 2 */ NewWizardMessages.getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
};
fStaticMdfIndex= 2; // index of the static checkbox is 2
} else {
buttonNames2= new String[] {
NewWizardMessages.getString("NewTypeWizardPage.modifiers.static") //$NON-NLS-1$
};
fStaticMdfIndex= 0; // index of the static checkbox is 0
}
fOtherMdfButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 4);
fOtherMdfButtons.setDialogFieldListener(adapter);
fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, false);
fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX, false);
fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex, false);
fPackageStatus= new StatusInfo();
fEnclosingTypeStatus= new StatusInfo();
fCanModifyPackage= true;
fCanModifyEnclosingType= true;
updateEnableState();
fTypeNameStatus= new StatusInfo();
fSuperClassStatus= new StatusInfo();
fSuperInterfacesStatus= new StatusInfo();
fModifierStatus= new StatusInfo();
}
/**
* Initializes all fields provided by the page with a given selection.
*
* @param elem the selection used to intialize this page or <code>
* null</code> if no selection was available
*/
protected void initTypePage(IJavaElement elem) {
String initSuperclass= "java.lang.Object"; //$NON-NLS-1$
ArrayList initSuperinterfaces= new ArrayList(5);
IPackageFragment pack= null;
IType enclosingType= null;
if (elem != null) {
// evaluate the enclosing type
pack= (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
IType typeInCU= (IType) elem.getAncestor(IJavaElement.TYPE);
if (typeInCU != null) {
if (typeInCU.getCompilationUnit() != null) {
enclosingType= typeInCU;
}
} else {
ICompilationUnit cu= (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
if (cu != null) {
enclosingType= cu.findPrimaryType();
}
}
try {
IType type= null;
if (elem.getElementType() == IJavaElement.TYPE) {
type= (IType)elem;
if (type.exists()) {
String superName= JavaModelUtil.getFullyQualifiedName(type);
if (type.isInterface()) {
initSuperinterfaces.add(superName);
} else {
initSuperclass= superName;
}
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// ignore this exception now
}
}
setPackageFragment(pack, true);
setEnclosingType(enclosingType, true);
setEnclosingTypeSelection(false, true);
setTypeName("", true); //$NON-NLS-1$
setSuperClass(initSuperclass, true);
setSuperInterfaces(initSuperinterfaces, true);
}
// -------- UI Creation ---------
/**
* Creates a separator line. Expects a <code>GridLayout</code> with at least 1 column.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSeparator(Composite composite, int nColumns) {
(new Separator(SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(composite, nColumns, convertHeightInCharsToPixels(1));
}
/**
* Creates the controls for the package name field. Expects a <code>GridLayout</code> with at
* least 4 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createPackageControls(Composite composite, int nColumns) {
fPackageDialogField.doFillIntoGrid(composite, nColumns);
LayoutUtil.setWidthHint(fPackageDialogField.getTextControl(null), getMaxFieldWidth());
LayoutUtil.setHorizontalGrabbing(fPackageDialogField.getTextControl(null));
}
/**
* Creates the controls for the enclosing type name field. Expects a <code>GridLayout</code> with at
* least 4 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createEnclosingTypeControls(Composite composite, int nColumns) {
// #6891
Composite tabGroup= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.marginWidth= 0;
layout.marginHeight= 0;
tabGroup.setLayout(layout);
fEnclosingTypeSelection.doFillIntoGrid(tabGroup, 1);
Control c= fEnclosingTypeDialogField.getTextControl(composite);
GridData gd= new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint= getMaxFieldWidth();
gd.horizontalSpan= 2;
c.setLayoutData(gd);
Button button= fEnclosingTypeDialogField.getChangeControl(composite);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.heightHint = SWTUtil.getButtonHeigthHint(button);
gd.widthHint = SWTUtil.getButtonWidthHint(button);
button.setLayoutData(gd);
}
/**
* Creates the controls for the type name field. Expects a <code>GridLayout</code> with at
* least 2 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createTypeNameControls(Composite composite, int nColumns) {
fTypeNameDialogField.doFillIntoGrid(composite, nColumns - 1);
DialogField.createEmptySpace(composite);
LayoutUtil.setWidthHint(fTypeNameDialogField.getTextControl(null), getMaxFieldWidth());
}
/**
* Creates the controls for the modifiers radio/ceckbox buttons. Expects a
* <code>GridLayout</code> with at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createModifierControls(Composite composite, int nColumns) {
LayoutUtil.setHorizontalSpan(fAccMdfButtons.getLabelControl(composite), 1);
Control control= fAccMdfButtons.getSelectionButtonsGroup(composite);
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= nColumns - 2;
control.setLayoutData(gd);
DialogField.createEmptySpace(composite);
DialogField.createEmptySpace(composite);
control= fOtherMdfButtons.getSelectionButtonsGroup(composite);
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= nColumns - 2;
control.setLayoutData(gd);
DialogField.createEmptySpace(composite);
}
/**
* Creates the controls for the superclass name field. Expects a <code>GridLayout</code>
* with at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSuperClassControls(Composite composite, int nColumns) {
fSuperClassDialogField.doFillIntoGrid(composite, nColumns);
LayoutUtil.setWidthHint(fSuperClassDialogField.getTextControl(null), getMaxFieldWidth());
}
/**
* Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with
* at least 3 columns.
*
* @param composite the parent composite
* @param nColumns number of columns to span
*/
protected void createSuperInterfacesControls(Composite composite, int nColumns) {
fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
GridData gd= (GridData)fSuperInterfacesDialogField.getListControl(null).getLayoutData();
if (fIsClass) {
gd.heightHint= convertHeightInCharsToPixels(3);
} else {
gd.heightHint= convertHeightInCharsToPixels(6);
}
gd.grabExcessVerticalSpace= false;
gd.widthHint= getMaxFieldWidth();
}
/**
* Sets the focus on the type name input field.
*/
protected void setFocus() {
fTypeNameDialogField.setFocus();
}
// -------- TypeFieldsAdapter --------
private class TypeFieldsAdapter implements IStringButtonAdapter, IDialogFieldListener, IListAdapter {
// -------- IStringButtonAdapter
public void changeControlPressed(DialogField field) {
typePageChangeControlPressed(field);
}
// -------- IListAdapter
public void customButtonPressed(ListDialogField field, int index) {
typePageCustomButtonPressed(field, index);
}
public void selectionChanged(ListDialogField field) {}
// -------- IDialogFieldListener
public void dialogFieldChanged(DialogField field) {
typePageDialogFieldChanged(field);
}
public void doubleClicked(ListDialogField field) {
}
}
private void typePageChangeControlPressed(DialogField field) {
if (field == fPackageDialogField) {
IPackageFragment pack= choosePackage();
if (pack != null) {
fPackageDialogField.setText(pack.getElementName());
}
} else if (field == fEnclosingTypeDialogField) {
IType type= chooseEnclosingType();
if (type != null) {
fEnclosingTypeDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
}
} else if (field == fSuperClassDialogField) {
IType type= chooseSuperType();
if (type != null) {
fSuperClassDialogField.setText(JavaModelUtil.getFullyQualifiedName(type));
}
}
}
private void typePageCustomButtonPressed(DialogField field, int index) {
if (field == fSuperInterfacesDialogField) {
chooseSuperInterfaces();
}
}
/*
* A field on the type has changed. The fields' status and all dependend
* status are updated.
*/
private void typePageDialogFieldChanged(DialogField field) {
String fieldName= null;
if (field == fPackageDialogField) {
fPackageStatus= packageChanged();
updatePackageStatusLabel();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= PACKAGE;
} else if (field == fEnclosingTypeDialogField) {
fEnclosingTypeStatus= enclosingTypeChanged();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= ENCLOSING;
} else if (field == fEnclosingTypeSelection) {
updateEnableState();
boolean isEnclosedType= isEnclosingTypeSelected();
if (!isEnclosedType) {
if (fAccMdfButtons.isSelected(PRIVATE_INDEX) || fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
fAccMdfButtons.setSelection(PRIVATE_INDEX, false);
fAccMdfButtons.setSelection(PROTECTED_INDEX, false);
fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
}
if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
fOtherMdfButtons.setSelection(fStaticMdfIndex, false);
}
}
fAccMdfButtons.enableSelectionButton(PRIVATE_INDEX, isEnclosedType && fIsClass);
fAccMdfButtons.enableSelectionButton(PROTECTED_INDEX, isEnclosedType && fIsClass);
fOtherMdfButtons.enableSelectionButton(fStaticMdfIndex, isEnclosedType);
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fieldName= ENCLOSINGSELECTION;
} else if (field == fTypeNameDialogField) {
fTypeNameStatus= typeNameChanged();
fieldName= TYPENAME;
} else if (field == fSuperClassDialogField) {
fSuperClassStatus= superClassChanged();
fieldName= SUPER;
} else if (field == fSuperInterfacesDialogField) {
fSuperInterfacesStatus= superInterfacesChanged();
fieldName= INTERFACES;
} else if (field == fOtherMdfButtons || field == fAccMdfButtons) {
fModifierStatus= modifiersChanged();
fieldName= MODIFIERS;
} else {
fieldName= METHODS;
}
// tell all others
handleFieldChanged(fieldName);
}
// -------- update message ----------------
/*
* @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#handleFieldChanged(String)
*/
protected void handleFieldChanged(String fieldName) {
super.handleFieldChanged(fieldName);
if (fieldName == CONTAINER) {
fPackageStatus= packageChanged();
fEnclosingTypeStatus= enclosingTypeChanged();
fTypeNameStatus= typeNameChanged();
fSuperClassStatus= superClassChanged();
fSuperInterfacesStatus= superInterfacesChanged();
}
}
// ---- set / get ----------------
/**
* Returns the text of the package input field.
*
* @return the text of the package input field
*/
public String getPackageText() {
return fPackageDialogField.getText();
}
/**
* Returns the text of the enclosing type input field.
*
* @return the text of the enclosing type input field
*/
public String getEnclosingTypeText() {
return fEnclosingTypeDialogField.getText();
}
/**
* Returns the package fragment corresponding to the current input.
*
* @return a package fragement or <code>null</code> if the input
* could not be resolved.
*/
public IPackageFragment getPackageFragment() {
if (!isEnclosingTypeSelected()) {
return fCurrPackage;
} else {
if (fCurrEnclosingType != null) {
return fCurrEnclosingType.getPackageFragment();
}
}
return null;
}
/**
* Sets the package fragment to the given value. The method updates the model
* and the text of the control.
*
* @param pack the package fragement to be set
* @param canBeModified if <code>true</code> the package fragment is
* editable; otherwise it is read-only.
*/
public void setPackageFragment(IPackageFragment pack, boolean canBeModified) {
fCurrPackage= pack;
fCanModifyPackage= canBeModified;
String str= (pack == null) ? "" : pack.getElementName(); //$NON-NLS-1$
fPackageDialogField.setText(str);
updateEnableState();
}
/**
* Returns the enclosing type corresponding to the current input.
*
* @return the enclosing type or <code>null</code> if the enclosing type is
* not selected or the input could not be resolved
*/
public IType getEnclosingType() {
if (isEnclosingTypeSelected()) {
return fCurrEnclosingType;
}
return null;
}
/**
* Sets the enclosing type. The method updates the underlying model
* and the text of the control.
*
* @param type the enclosing type
* @param canBeModified if <code>true</code> the enclosing type field is
* editable; otherwise it is read-only.
*/
public void setEnclosingType(IType type, boolean canBeModified) {
fCurrEnclosingType= type;
fCanModifyEnclosingType= canBeModified;
String str= (type == null) ? "" : JavaModelUtil.getFullyQualifiedName(type); //$NON-NLS-1$
fEnclosingTypeDialogField.setText(str);
updateEnableState();
}
/**
* Returns the selection state of the enclosing type checkbox.
*
* @return the seleciton state of the enclosing type checkbox
*/
public boolean isEnclosingTypeSelected() {
return fEnclosingTypeSelection.isSelected();
}
/**
* Sets the enclosing type checkbox's selection state.
*
* @param isSelected the checkbox's selection state
* @param canBeModified if <code>true</code> the enclosing type checkbox is
* modifiable; otherwise it is read-only.
*/
public void setEnclosingTypeSelection(boolean isSelected, boolean canBeModified) {
fEnclosingTypeSelection.setSelection(isSelected);
fEnclosingTypeSelection.setEnabled(canBeModified);
updateEnableState();
}
/**
* Returns the type name entered into the type input field.
*
* @return the type name
*/
public String getTypeName() {
return fTypeNameDialogField.getText();
}
/**
* Sets the type name input field's text to the given value. Method doesn't update
* the model.
*
* @param name the new type name
* @param canBeModified if <code>true</code> the enclosing type name field is
* editable; otherwise it is read-only.
*/
public void setTypeName(String name, boolean canBeModified) {
fTypeNameDialogField.setText(name);
fTypeNameDialogField.setEnabled(canBeModified);
}
/**
* Returns the selected modifiers.
*
* @return the selected modifiers
* @see Flags
*/
public int getModifiers() {
int mdf= 0;
if (fAccMdfButtons.isSelected(PUBLIC_INDEX)) {
mdf+= F_PUBLIC;
} else if (fAccMdfButtons.isSelected(PRIVATE_INDEX)) {
mdf+= F_PRIVATE;
} else if (fAccMdfButtons.isSelected(PROTECTED_INDEX)) {
mdf+= F_PROTECTED;
}
if (fOtherMdfButtons.isSelected(ABSTRACT_INDEX) && (fStaticMdfIndex != 0)) {
mdf+= F_ABSTRACT;
}
if (fOtherMdfButtons.isSelected(FINAL_INDEX)) {
mdf+= F_FINAL;
}
if (fOtherMdfButtons.isSelected(fStaticMdfIndex)) {
mdf+= F_STATIC;
}
return mdf;
}
/**
* Sets the modifiers.
*
* @param modifiers <code>F_PUBLIC</code>, <code>F_PRIVATE</code>,
* <code>F_PROTECTED</code>, <code>F_ABSTRACT, F_FINAL</code>
* or <code>F_STATIC</code> or, a valid combination.
* @param canBeModified if <code>true</code> the modifier fields are
* editable; otherwise they are read-only
* @see Flags
*/
public void setModifiers(int modifiers, boolean canBeModified) {
if (Flags.isPublic(modifiers)) {
fAccMdfButtons.setSelection(PUBLIC_INDEX, true);
} else if (Flags.isPrivate(modifiers)) {
fAccMdfButtons.setSelection(PRIVATE_INDEX, true);
} else if (Flags.isProtected(modifiers)) {
fAccMdfButtons.setSelection(PROTECTED_INDEX, true);
} else {
fAccMdfButtons.setSelection(DEFAULT_INDEX, true);
}
if (Flags.isAbstract(modifiers)) {
fOtherMdfButtons.setSelection(ABSTRACT_INDEX, true);
}
if (Flags.isFinal(modifiers)) {
fOtherMdfButtons.setSelection(FINAL_INDEX, true);
}
if (Flags.isStatic(modifiers)) {
fOtherMdfButtons.setSelection(fStaticMdfIndex, true);
}
fAccMdfButtons.setEnabled(canBeModified);
fOtherMdfButtons.setEnabled(canBeModified);
}
/**
* Returns the content of the superclass input field.
*
* @return the superclass name
*/
public String getSuperClass() {
return fSuperClassDialogField.getText();
}
/**
* Sets the super class name.
*
* @param name the new superclass name
* @param canBeModified if <code>true</code> the superclass name field is
* editable; otherwise it is read-only.
*/
public void setSuperClass(String name, boolean canBeModified) {
fSuperClassDialogField.setText(name);
fSuperClassDialogField.setEnabled(canBeModified);
}
/**
* Returns the chosen super interfaces.
*
* @return a list of chosen super interfaces. The list's elements
* are of type <code>String</code>
*/
public List getSuperInterfaces() {
return fSuperInterfacesDialogField.getElements();
}
/**
* Sets the super interfaces.
*
* @param interfacesNames a list of super interface. The method requires that
* the list's elements are of type <code>String</code>
* @param canBeModified if <code>true</code> the super interface field is
* editable; otherwise it is read-only.
*/
public void setSuperInterfaces(List interfacesNames, boolean canBeModified) {
fSuperInterfacesDialogField.setElements(interfacesNames);
fSuperInterfacesDialogField.setEnabled(canBeModified);
}
// ----------- validation ----------
/**
* A hook method that gets called when the package field has changed. The method
* validates the package name and returns the status of the validation. The validation
* also updates the package fragment model.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus packageChanged() {
StatusInfo status= new StatusInfo();
fPackageDialogField.enableButton(getPackageFragmentRoot() != null);
String packName= getPackageText();
if (packName.length() > 0) {
IStatus val= JavaConventions.validatePackageName(packName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidPackageName", val.getMessage())); //$NON-NLS-1$
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.DiscouragedPackageName", val.getMessage())); //$NON-NLS-1$
// continue
}
}
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root != null) {
if (root.getJavaProject().exists() && packName.length() > 0) {
try {
IPath rootPath= root.getPath();
IPath outputPath= root.getJavaProject().getOutputLocation();
if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
// if the bin folder is inside of our root, dont allow to name a package
// like the bin folder
IPath packagePath= rootPath.append(packName.replace('.', '/'));
if (outputPath.isPrefixOf(packagePath)) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ClashOutputLocation")); //$NON-NLS-1$
return status;
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// let pass
}
}
fCurrPackage= root.getPackageFragment(packName);
} else {
status.setError(""); //$NON-NLS-1$
}
return status;
}
/*
* Updates the 'default' label next to the package field.
*/
private void updatePackageStatusLabel() {
String packName= getPackageText();
if (packName.length() == 0) {
fPackageDialogField.setStatus(NewWizardMessages.getString("NewTypeWizardPage.default")); //$NON-NLS-1$
} else {
fPackageDialogField.setStatus(""); //$NON-NLS-1$
}
}
/*
* Updates the enable state of buttons related to the enclosing type selection checkbox.
*/
private void updateEnableState() {
boolean enclosing= isEnclosingTypeSelected();
fPackageDialogField.setEnabled(fCanModifyPackage && !enclosing);
fEnclosingTypeDialogField.setEnabled(fCanModifyEnclosingType && enclosing);
}
/**
* Hook method that gets called when the enclosing type name has changed. The method
* validates the enclosing type and returns the status of the validation. It also updates the
* enclosing type model.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus enclosingTypeChanged() {
StatusInfo status= new StatusInfo();
fCurrEnclosingType= null;
IPackageFragmentRoot root= getPackageFragmentRoot();
fEnclosingTypeDialogField.enableButton(root != null);
if (root == null) {
status.setError(""); //$NON-NLS-1$
return status;
}
String enclName= getEnclosingTypeText();
if (enclName.length() == 0) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeEnterName")); //$NON-NLS-1$
return status;
}
try {
IType type= findType(root.getJavaProject(), enclName);
if (type == null) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists")); //$NON-NLS-1$
return status;
}
if (type.getCompilationUnit() == null) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotInCU")); //$NON-NLS-1$
return status;
}
if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingNotEditable")); //$NON-NLS-1$
return status;
}
fCurrEnclosingType= type;
IPackageFragmentRoot enclosingRoot= JavaModelUtil.getPackageFragmentRoot(type);
if (!enclosingRoot.equals(root)) {
status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.EnclosingNotInSourceFolder")); //$NON-NLS-1$
}
return status;
} catch (JavaModelException e) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnclosingTypeNotExists")); //$NON-NLS-1$
JavaPlugin.log(e);
return status;
}
}
/**
* Hook method that gets called when the type name has changed. The method validates the
* type name and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus typeNameChanged() {
StatusInfo status= new StatusInfo();
String typeName= getTypeName();
// must not be empty
if (typeName.length() == 0) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.EnterTypeName")); //$NON-NLS-1$
return status;
}
if (typeName.indexOf('.') != -1) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.QualifiedName")); //$NON-NLS-1$
return status;
}
IStatus val= JavaConventions.validateJavaTypeName(typeName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getFormattedString("NewTypeWizardPage.error.InvalidTypeName", val.getMessage())); //$NON-NLS-1$
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.TypeNameDiscouraged", val.getMessage())); //$NON-NLS-1$
// continue checking
}
// must not exist
if (!isEnclosingTypeSelected()) {
IPackageFragment pack= getPackageFragment();
if (pack != null) {
ICompilationUnit cu= pack.getCompilationUnit(typeName + ".java"); //$NON-NLS-1$
if (cu.getResource().exists()) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
return status;
}
}
} else {
IType type= getEnclosingType();
if (type != null) {
IType member= type.getType(typeName);
if (member.exists()) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.TypeNameExists")); //$NON-NLS-1$
return status;
}
}
}
return status;
}
/**
* Hook method that gets called when the superclass name has changed. The method
* validates the superclass name and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus superClassChanged() {
StatusInfo status= new StatusInfo();
IPackageFragmentRoot root= getPackageFragmentRoot();
fSuperClassDialogField.enableButton(root != null);
fSuperClass= null;
String sclassName= getSuperClass();
if (sclassName.length() == 0) {
// accept the empty field (stands for java.lang.Object)
return status;
}
IStatus val= JavaConventions.validateJavaTypeName(sclassName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName")); //$NON-NLS-1$
return status;
}
if (root != null) {
try {
IType type= resolveSuperTypeName(root.getJavaProject(), sclassName);
if (type == null) {
status.setWarning(NewWizardMessages.getString("NewTypeWizardPage.warning.SuperClassNotExists")); //$NON-NLS-1$
return status;
} else {
if (type.isInterface()) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotClass", sclassName)); //$NON-NLS-1$
return status;
}
int flags= type.getFlags();
if (Flags.isFinal(flags)) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsFinal", sclassName)); //$NON-NLS-1$
return status;
} else if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.SuperClassIsNotVisible", sclassName)); //$NON-NLS-1$
return status;
}
}
fSuperClass= type;
} catch (JavaModelException e) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.InvalidSuperClassName")); //$NON-NLS-1$
JavaPlugin.log(e);
}
} else {
status.setError(""); //$NON-NLS-1$
}
return status;
}
private IType resolveSuperTypeName(IJavaProject jproject, String sclassName) throws JavaModelException {
if (!jproject.exists()) {
return null;
}
IType type= null;
if (isEnclosingTypeSelected()) {
// search in the context of the enclosing type
IType enclosingType= getEnclosingType();
if (enclosingType != null) {
String[][] res= enclosingType.resolveType(sclassName);
if (res != null && res.length > 0) {
type= jproject.findType(res[0][0], res[0][1]);
}
}
} else {
IPackageFragment currPack= getPackageFragment();
if (type == null && currPack != null) {
String packName= currPack.getElementName();
// search in own package
if (!currPack.isDefaultPackage()) {
type= jproject.findType(packName, sclassName);
}
// search in java.lang
if (type == null && !"java.lang".equals(packName)) { //$NON-NLS-1$
type= jproject.findType("java.lang", sclassName); //$NON-NLS-1$
}
}
// search fully qualified
if (type == null) {
type= jproject.findType(sclassName);
}
}
return type;
}
private IType findType(IJavaProject project, String typeName) throws JavaModelException {
if (project.exists()) {
return project.findType(typeName);
}
return null;
}
/**
* Hook method that gets called when the list of super interface has changed. The method
* validates the superinterfaces and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus superInterfacesChanged() {
StatusInfo status= new StatusInfo();
IPackageFragmentRoot root= getPackageFragmentRoot();
fSuperInterfacesDialogField.enableButton(0, root != null);
if (root != null) {
List elements= fSuperInterfacesDialogField.getElements();
int nElements= elements.size();
for (int i= 0; i < nElements; i++) {
String intfname= (String)elements.get(i);
try {
IType type= findType(root.getJavaProject(), intfname);
if (type == null) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceNotExists", intfname)); //$NON-NLS-1$
return status;
} else {
if (type.isClass()) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotInterface", intfname)); //$NON-NLS-1$
return status;
}
if (!JavaModelUtil.isVisible(type, getPackageFragment())) {
status.setWarning(NewWizardMessages.getFormattedString("NewTypeWizardPage.warning.InterfaceIsNotVisible", intfname)); //$NON-NLS-1$
return status;
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// let pass, checking is an extra
}
}
}
return status;
}
/**
* Hook method that gets called when the modifiers have changed. The method validates
* the modifiers and returns the status of the validation.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus modifiersChanged() {
StatusInfo status= new StatusInfo();
int modifiers= getModifiers();
if (Flags.isFinal(modifiers) && Flags.isAbstract(modifiers)) {
status.setError(NewWizardMessages.getString("NewTypeWizardPage.error.ModifiersFinalAndAbstract")); //$NON-NLS-1$
}
return status;
}
// selection dialogs
private IPackageFragment choosePackage() {
IPackageFragmentRoot froot= getPackageFragmentRoot();
IJavaElement[] packages= null;
try {
if (froot != null && froot.exists()) {
packages= froot.getChildren();
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
if (packages == null) {
packages= new IJavaElement[0];
}
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
dialog.setIgnoreCase(false);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.description")); //$NON-NLS-1$
dialog.setEmptyListMessage(NewWizardMessages.getString("NewTypeWizardPage.ChoosePackageDialog.empty")); //$NON-NLS-1$
dialog.setElements(packages);
IPackageFragment pack= getPackageFragment();
if (pack != null) {
dialog.setInitialSelections(new Object[] { pack });
}
if (dialog.open() == ElementListSelectionDialog.OK) {
return (IPackageFragment) dialog.getFirstResult();
}
return null;
}
private IType chooseEnclosingType() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return null;
}
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { root });
TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(), getWizard().getContainer(), IJavaSearchConstants.TYPE, scope);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.ChooseEnclosingTypeDialog.description")); //$NON-NLS-1$
dialog.setFilter(Signature.getSimpleName(getEnclosingTypeText()));
if (dialog.open() == TypeSelectionDialog.OK) {
return (IType) dialog.getFirstResult();
}
return null;
}
private IType chooseSuperType() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return null;
}
IJavaElement[] elements= new IJavaElement[] { root.getJavaProject() };
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);
TypeSelectionDialog dialog= new TypeSelectionDialog(getShell(), getWizard().getContainer(), IJavaSearchConstants.CLASS, scope);
dialog.setTitle(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.title")); //$NON-NLS-1$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.SuperClassDialog.message")); //$NON-NLS-1$
dialog.setFilter(getSuperClass());
if (dialog.open() == TypeSelectionDialog.OK) {
return (IType) dialog.getFirstResult();
}
return null;
}
private void chooseSuperInterfaces() {
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root == null) {
return;
}
IJavaProject project= root.getJavaProject();
SuperInterfaceSelectionDialog dialog= new SuperInterfaceSelectionDialog(getShell(), getWizard().getContainer(), fSuperInterfacesDialogField, project);
dialog.setTitle(fIsClass ? NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.class.title") : NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.interface.title")); //$NON-NLS-1$ //$NON-NLS-2$
dialog.setMessage(NewWizardMessages.getString("NewTypeWizardPage.InterfacesDialog.message")); //$NON-NLS-1$
dialog.open();
return;
}
// ---- creation ----------------
/**
* Creates the new type using the entered field values.
*
* @param monitor a progress monitor to report progress.
*/
public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
monitor.beginTask(NewWizardMessages.getString("NewTypeWizardPage.operationdesc"), 10); //$NON-NLS-1$
ICompilationUnit createdWorkingCopy= null;
try {
IPackageFragmentRoot root= getPackageFragmentRoot();
IPackageFragment pack= getPackageFragment();
if (pack == null) {
pack= root.getPackageFragment(""); //$NON-NLS-1$
}
if (!pack.exists()) {
String packName= pack.getElementName();
pack= root.createPackageFragment(packName, true, null);
}
monitor.worked(1);
String clName= getTypeName();
boolean isInnerClass= isEnclosingTypeSelected();
IType createdType;
ImportsStructure imports;
int indent= 0;
IPreferenceStore store= PreferenceConstants.getPreferenceStore();
String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store);
int threshold= JavaPreferencesSettings.getImportNumberThreshold(store);
String lineDelimiter= null;
if (!isInnerClass) {
lineDelimiter= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
ICompilationUnit parentCU= pack.createCompilationUnit(clName + ".java", "", false, new SubProgressMonitor(monitor, 2)); //$NON-NLS-1$ //$NON-NLS-2$
createdWorkingCopy= (ICompilationUnit) parentCU.getSharedWorkingCopy(null, JavaUI.getBufferFactory(), null);
imports= new ImportsStructure(createdWorkingCopy, prefOrder, threshold, false);
// add an import that will be removed again. Having this import solves 14661
imports.addImport(pack.getElementName(), getTypeName());
String typeContent= constructTypeStub(new ImportsManager(imports), lineDelimiter);
String cuContent= constructCUContent(parentCU, typeContent, lineDelimiter);
createdWorkingCopy.getBuffer().setContents(cuContent);
createdType= createdWorkingCopy.getType(clName);
} else {
IType enclosingType= getEnclosingType();
// if we are working on a enclosed type that is open in an editor,
// then replace the enclosing type with its working copy
IType workingCopy= (IType) EditorUtility.getWorkingCopy(enclosingType);
if (workingCopy != null) {
enclosingType= workingCopy;
}
ICompilationUnit parentCU= enclosingType.getCompilationUnit();
imports= new ImportsStructure(parentCU, prefOrder, threshold, true);
// add imports that will be removed again. Having the imports solves 14661
IType[] topLevelTypes= parentCU.getTypes();
for (int i= 0; i < topLevelTypes.length; i++) {
imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
}
lineDelimiter= StubUtility.getLineDelimiterUsed(enclosingType);
StringBuffer content= new StringBuffer();
String comment= getTypeComment(parentCU);
if (comment != null) {
content.append(comment);
content.append(lineDelimiter);
}
content.append(constructTypeStub(new ImportsManager(imports), lineDelimiter));
IJavaElement[] elems= enclosingType.getChildren();
IJavaElement sibling= elems.length > 0 ? elems[0] : null;
createdType= enclosingType.createType(content.toString(), sibling, false, new SubProgressMonitor(monitor, 1));
indent= StubUtility.getIndentUsed(enclosingType) + 1;
}
// add imports for superclass/interfaces, so types can be resolved correctly
imports.create(false, new SubProgressMonitor(monitor, 1));
ICompilationUnit cu= createdType.getCompilationUnit();
synchronized(cu) {
cu.reconcile();
}
createTypeMembers(createdType, new ImportsManager(imports), new SubProgressMonitor(monitor, 1));
// add imports
imports.create(false, new SubProgressMonitor(monitor, 1));
synchronized(cu) {
cu.reconcile();
}
ISourceRange range= createdType.getSourceRange();
IBuffer buf= cu.getBuffer();
String originalContent= buf.getText(range.getOffset(), range.getLength());
String formattedContent= StubUtility.codeFormat(originalContent, indent, lineDelimiter);
buf.replace(range.getOffset(), range.getLength(), formattedContent);
if (!isInnerClass) {
String fileComment= getFileComment(cu);
if (fileComment != null && fileComment.length() > 0) {
buf.replace(0, 0, fileComment + lineDelimiter);
}
cu.commit(false, new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
fCreatedType= createdType;
} finally {
if (createdWorkingCopy != null) {
createdWorkingCopy.destroy();
}
monitor.done();
}
}
/**
* Uses the New Java file template from the code template page to generate a
* compilation unit with the given type content.
* @param cu The new created compilation unit
* @param typeContent The content of the type, including signature and type
* body.
* @param lineDelimiter The line delimiter to be used.
* @return String Returns the result of evaluating the new file template
* with the given type content.
* @throws CoreException
* @since 2.1
*/
protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
StringBuffer typeQualifiedName= new StringBuffer();
if (isEnclosingTypeSelected()) {
typeQualifiedName.append(JavaModelUtil.getTypeQualifiedName(getEnclosingType())).append('.');
}
typeQualifiedName.append(getTypeName());
String typeComment= CodeGeneration.getTypeComment(cu, typeQualifiedName.toString(), lineDelimiter);
IPackageFragment pack= (IPackageFragment) cu.getParent();
String content= CodeGeneration.getCompilationUnitContent(cu, typeComment, typeContent, lineDelimiter);
if (content != null) {
CompilationUnit unit= AST.parseCompilationUnit(content.toCharArray());
if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
return content;
}
}
StringBuffer buf= new StringBuffer();
if (!pack.isDefaultPackage()) {
buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
}
buf.append(lineDelimiter).append(lineDelimiter);
if (typeComment != null) {
buf.append(typeComment).append(lineDelimiter);
}
buf.append(typeContent);
return buf.toString();
}
/**
* Returns the created type. The method only returns a valid type
* after <code>createType</code> has been called.
*
* @return the created type
* @see #createType(IProgressMonitor)
*/
public IType getCreatedType() {
return fCreatedType;
}
// ---- construct cu body----------------
private void writeSuperClass(StringBuffer buf, ImportsManager imports) {
String typename= getSuperClass();
if (fIsClass && typename.length() > 0 && !"java.lang.Object".equals(typename)) { //$NON-NLS-1$
buf.append(" extends "); //$NON-NLS-1$
String qualifiedName= fSuperClass != null ? JavaModelUtil.getFullyQualifiedName(fSuperClass) : typename;
buf.append(imports.addImport(qualifiedName));
}
}
private void writeSuperInterfaces(StringBuffer buf, ImportsManager imports) {
List interfaces= getSuperInterfaces();
int last= interfaces.size() - 1;
if (last >= 0) {
if (fIsClass) {
buf.append(" implements "); //$NON-NLS-1$
} else {
buf.append(" extends "); //$NON-NLS-1$
}
for (int i= 0; i <= last; i++) {
String typename= (String) interfaces.get(i);
buf.append(imports.addImport(typename));
if (i < last) {
buf.append(',');
}
}
}
}
/*
* Called from createType to construct the source for this type
*/
private String constructTypeStub(ImportsManager imports, String lineDelimiter) {
StringBuffer buf= new StringBuffer();
int modifiers= getModifiers();
buf.append(Flags.toString(modifiers));
if (modifiers != 0) {
buf.append(' ');
}
buf.append(fIsClass ? "class " : "interface "); //$NON-NLS-2$ //$NON-NLS-1$
buf.append(getTypeName());
writeSuperClass(buf, imports);
writeSuperInterfaces(buf, imports);
buf.append('{');
buf.append(lineDelimiter);
buf.append(lineDelimiter);
buf.append('}');
buf.append(lineDelimiter);
return buf.toString();
}
/**
* @deprecated Overwrite createTypeMembers(IType, IImportsManager, IProgressMonitor) instead
*/
protected void createTypeMembers(IType newType, IImportsStructure imports, IProgressMonitor monitor) throws CoreException {
//deprecated
}
/**
* Hook method that gets called from <code>createType</code> to support adding of
* unanticipated methods, fields, and inner types to the created type.
* <p>
* Implementers can use any methods defined on <code>IType</code> to manipulate the
* new type.
* </p>
* <p>
* The source code of the new type will be formtted using the platform's formatter. Needed
* imports are added by the wizard at the end of the type creation process using the given
* import manager.
* </p>
*
* @param newType the new type created via <code>createType</code>
* @param imports an import manager which can be used to add new imports
* @param monitor a progress monitor to report progress. Must not be <code>null</code>
*
* @see #createType(IProgressMonitor)
*/
protected void createTypeMembers(IType newType, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
// call for compatibility
createTypeMembers(newType, ((ImportsManager)imports).getImportsStructure(), monitor);
// default implementation does nothing
// example would be
// String mainMathod= "public void foo(Vector vec) {}"
// createdType.createMethod(main, null, false, null);
// imports.addImport("java.lang.Vector");
}
/**
* @deprecated Instead of file templates, the new type code template
* specifies the stub for a compilation unit.
*/
protected String getFileComment(ICompilationUnit parentCU) {
return null;
}
private boolean isValidComment(String template) {
IScanner scanner= ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next= scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next= scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
/**
* Hook method that gets called from <code>createType</code> to retrieve
* a type comment. This default implementation returns the content of the
* 'typecomment' template.
*
* @return the type comment or <code>null</code> if a type comment
* is not desired
*/
protected String getTypeComment(ICompilationUnit parentCU) {
if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS)) {
try {
StringBuffer typeName= new StringBuffer();
if (isEnclosingTypeSelected()) {
typeName.append(JavaModelUtil.getTypeQualifiedName(getEnclosingType())).append('.');
}
typeName.append(getTypeName());
String comment= CodeGeneration.getTypeComment(parentCU, typeName.toString(), String.valueOf('\n'));
if (comment != null && isValidComment(comment)) {
return comment;
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
return null;
}
/**
* @deprecated Use getTemplate(String,ICompilationUnit,int)
*/
protected String getTemplate(String name, ICompilationUnit parentCU) {
return getTemplate(name, parentCU, 0);
}
/**
* Returns the string resulting from evaluation the given template in
* the context of the given compilation unit. This accesses the normal
* template page, not the code templates. To use code templates use
* <code>constructCUContent</code> to construct a compilation unit stub or
* getTypeComment for the comment of the type.
*
* @param name the template to be evaluated
* @param parentCU the templates evaluation context
* @param pos a source offset into the parent compilation unit. The
* template is evalutated at the given source offset
*/
protected String getTemplate(String name, ICompilationUnit parentCU, int pos) {
try {
Template[] templates= Templates.getInstance().getTemplates(name);
if (templates.length > 0) {
return JavaContext.evaluateTemplate(templates[0], parentCU, pos);
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
return null;
}
/**
* @deprecated Use createInheritedMethods(IType,boolean,boolean,IImportsManager,IProgressMonitor)
*/
protected IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, IImportsStructure imports, IProgressMonitor monitor) throws CoreException {
return createInheritedMethods(type, doConstructors, doUnimplementedMethods, new ImportsManager(imports), monitor);
}
/**
* Creates the bodies of all unimplemented methods and constructors and adds them to the type.
* Method is typically called by implementers of <code>NewTypeWizardPage</code> to add
* needed method and constructors.
*
* @param type the type for which the new methods and constructor are to be created
* @param doConstructors if <code>true</code> unimplemented constructors are created
* @param doUnimplementedMethods if <code>true</code> unimplemented methods are created
* @param imports an import manager to add all neded import statements
* @param monitor a progress monitor to report progress
*/
protected IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
ArrayList newMethods= new ArrayList();
ITypeHierarchy hierarchy= null;
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
if (doConstructors) {
hierarchy= type.newSupertypeHierarchy(monitor);
IType superclass= hierarchy.getSuperclass(type);
if (superclass != null) {
String[] constructors= StubUtility.evalConstructors(type, superclass, settings, imports.getImportsStructure());
if (constructors != null) {
for (int i= 0; i < constructors.length; i++) {
newMethods.add(constructors[i]);
}
}
}
}
if (doUnimplementedMethods) {
if (hierarchy == null) {
hierarchy= type.newSupertypeHierarchy(monitor);
}
String[] unimplemented= StubUtility.evalUnimplementedMethods(type, hierarchy, false, settings, imports.getImportsStructure());
if (unimplemented != null) {
for (int i= 0; i < unimplemented.length; i++) {
newMethods.add(unimplemented[i]);
}
}
}
IMethod[] createdMethods= new IMethod[newMethods.size()];
for (int i= 0; i < newMethods.size(); i++) {
String content= (String) newMethods.get(i) + '\n'; // content will be formatted, ok to use \n
createdMethods[i]= type.createMethod(content, null, false, null);
}
return createdMethods;
}
// ---- creation ----------------
/**
* Returns the runnable that creates the type using the current settings.
* The returned runnable must be executed in the UI thread.
*
* @return the runnable to create the new type
*/
public IRunnableWithProgress getRunnable() {
return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
createType(monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
}
}
|
39,324 |
Bug 39324 TextEdits: Moved positions removed
|
20030625 See TextBufferTest.testMoveWithRangeMarker2 The RangeMarker is inside the MoveSource, and the MoveSource inside a delete: The resulting range of the Range Marker is deleted, not moved (TextBufferTest.testMoveWithRangeMarker shows that is works if there is no surrounding delete)
|
resolved fixed
|
1505d17
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-25T13:55:24Z | 2003-06-25T14:06:40Z |
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/TextBufferTest.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.tests.core;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.internal.corext.textmanipulation.CopySourceEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.CopyTargetEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MoveSourceEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MoveTargetEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.MultiTextEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.RangeMarker;
import org.eclipse.jdt.internal.corext.textmanipulation.SimpleTextEdit;
import org.eclipse.jdt.internal.corext.textmanipulation.TextBuffer;
import org.eclipse.jdt.internal.corext.textmanipulation.TextBufferEditor;
import org.eclipse.jdt.internal.corext.textmanipulation.TextRange;
import org.eclipse.jdt.internal.corext.textmanipulation.UndoMemento;
public class TextBufferTest extends TestCase {
private static final Class THIS= TextBufferTest.class;
private TextBuffer fBuffer;
private TextBufferEditor fEditor;
public TextBufferTest(String name) {
super(name);
}
public static Test allTests() {
return new TestSuite(THIS);
}
public static Test suite() {
TestSuite result= new TestSuite(THIS);
if (false) { // For hot code replace when debugging test cases
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
result.addTestSuite(THIS);
}
return result;
}
protected void setUp() throws Exception {
fBuffer= TextBuffer.create("0123456789");
fEditor= new TextBufferEditor(fBuffer);
}
protected void tearDown() throws Exception {
fEditor= null;
}
public void testOverlap1() throws Exception {
// [ [ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(1, 2, "12"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap2() throws Exception {
// [[ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(0, 1, "0"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap3() throws Exception {
// [ [ ]]
fEditor.add(SimpleTextEdit.createReplace(0, 2, "01"));
fEditor.add(SimpleTextEdit.createReplace(1, 1, "1"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap4() throws Exception {
// [ [ ] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createReplace(1, 1, "1"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap5() throws Exception {
// [ [] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createInsert(1, "xx"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap6() throws Exception {
// [ [] ]
fEditor.add(SimpleTextEdit.createReplace(0, 3, "012"));
fEditor.add(SimpleTextEdit.createInsert(2, "xx"));
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap7() throws Exception {
MoveSourceEdit source= new MoveSourceEdit(2, 5);
MoveTargetEdit target= new MoveTargetEdit(3, source);
fEditor.add(source);
fEditor.add(target);
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap8() throws Exception {
MoveSourceEdit source= new MoveSourceEdit(2, 5);
MoveTargetEdit target= new MoveTargetEdit(6, source);
fEditor.add(source);
fEditor.add(target);
assertFalse(fEditor.canPerformEdits());
}
public void testOverlap9() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(3, 1);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
MoveSourceEdit s2= new MoveSourceEdit(2, 3);
MoveTargetEdit t2= new MoveTargetEdit(8, s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(s2);
fEditor.add(t2);
assertFalse(fEditor.canPerformEdits());
}
public void testInsert1() throws Exception {
// [][ ]
SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy");
SimpleTextEdit e2= SimpleTextEdit.createReplace(2, 3, "3456");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 4, 4);
assertEquals("Buffer content", "01yy345656789", fBuffer.getContent());
doUndoRedo(undo, "01yy345656789");
}
public void testInsert2() throws Exception {
// [][]
SimpleTextEdit e1= SimpleTextEdit.createInsert(2, "yy");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 4, 2);
assertEquals("Buffer content", "01yyxx23456789", fBuffer.getContent());
doUndoRedo(undo, "01yyxx23456789");
}
public void testInsert3() throws Exception {
// [ ][][ ]
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 2, "011");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
SimpleTextEdit e3= SimpleTextEdit.createReplace(2, 2, "2");
fEditor.add(e1);
fEditor.add(e2);
fEditor.add(e3);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 0, 3);
assertEquals(e2.getTextRange(), 3, 2);
assertEquals(e3.getTextRange(), 5, 1);
assertEquals("Buffer content", "011xx2456789", fBuffer.getContent());
doUndoRedo(undo, "011xx2456789");
}
public void testInsert4() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(0, "xx");
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assertEquals(e1.getTextRange(), 0, 2);
assertEquals("Buffer content", "xx0123456789", fBuffer.getContent());
doUndoRedo(undo, "xx0123456789");
}
public void testInsert5() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(10, "xx");
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer length", 12, fBuffer.getLength());
assertEquals(e1.getTextRange(), 10, 2);
assertEquals("Buffer content", "0123456789xx", fBuffer.getContent());
doUndoRedo(undo, "0123456789xx");
}
public void testInsertReplace1() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createReplace(2, 1, "y");
SimpleTextEdit e2= SimpleTextEdit.createInsert(2, "xx");
fEditor.add(e1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 4, 1);
assertEquals(e2.getTextRange(), 2, 2);
assertEquals("Buffer content", "01xxy3456789", fBuffer.getContent());
doUndoRedo(undo, "01xxy3456789");
}
public void testDelete1() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(3, 1);
fEditor.add(e1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 0);
assertEquals("Buffer content", "012456789", fBuffer.getContent());
doUndoRedo(undo, "012456789");
}
public void testDelete2() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(4, 1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1);
SimpleTextEdit e3= SimpleTextEdit.createDelete(5, 1);
fEditor.add(e1);
fEditor.add(e2);
fEditor.add(e3);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 0);
assertEquals(e2.getTextRange(), 3, 0);
assertEquals(e3.getTextRange(), 3, 0);
assertEquals("Buffer content", "0126789", fBuffer.getContent());
doUndoRedo(undo, "0126789");
}
public void testDelete3() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createInsert(3, "x");
SimpleTextEdit e2= SimpleTextEdit.createDelete(3, 1);
fEditor.add(e1);
fEditor.add(e2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(e1.getTextRange(), 3, 1);
assertEquals(e2.getTextRange(), 4, 0);
assertEquals("Buffer content", "012x456789", fBuffer.getContent());
doUndoRedo(undo, "012x456789");
}
public void testDeleteWithChildren() throws Exception {
SimpleTextEdit e1= SimpleTextEdit.createDelete(2, 6);
MultiTextEdit e2= new MultiTextEdit();
e1.add(e2);
SimpleTextEdit e3= SimpleTextEdit.createReplace(3,1,"xx");
SimpleTextEdit e4= SimpleTextEdit.createReplace(5,1,"yy");
e2.add(e3);
e2.add(e4);
fEditor.add(e1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0189", fBuffer.getContent());
assertTrue(e2.getTextRange().isDeleted());
assertTrue(e3.getTextRange().isDeleted());
assertTrue(e4.getTextRange().isDeleted());
doUndoRedo(undo, "0189");
}
public void testMove1() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0142356789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 3, 2);
doUndoRedo(undo, "0142356789");
}
public void testMove2() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0156234789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 7, 0);
assertEquals(t1.getTextRange(), 2, 2);
doUndoRedo(undo, "0156234789");
}
public void testMove3() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(4, 1, "x");
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01x5623789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 5, 2);
assertEquals(e2.getTextRange(), 2, 1);
doUndoRedo(undo, "01x5623789");
}
public void testMove4() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(7, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(5, 1, "x");
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0178234x69", fBuffer.getContent());
assertEquals(s1.getTextRange(), 9, 0);
assertEquals(t1.getTextRange(), 2, 2);
assertEquals(e2.getTextRange(), 7, 1);
doUndoRedo(undo, "0178234x69");
}
public void testMove5() throws Exception {
// Move onto itself
MoveSourceEdit s1= new MoveSourceEdit(2, 1);
MoveTargetEdit t1= new MoveTargetEdit(3, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 2, 1);
assertEquals(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndoRedo(undo, "01x3456789");
}
public void testMove6() throws Exception {
// Move onto itself
MoveSourceEdit s1= new MoveSourceEdit(2, 1);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(2,1,"x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 3, 0);
assertEquals(t1.getTextRange(), 2, 1);
assertEquals(e2.getTextRange(), 2, 1);
assertEquals("Buffer content", "01x3456789", fBuffer.getContent());
doUndoRedo(undo,"01x3456789");
}
public void testMove7() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 3);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(3, 1, "x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01562x4789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 4, 3);
assertEquals(e2.getTextRange(), 5, 1);
doUndoRedo(undo, "01562x4789");
}
public void testMove8() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 3);
MoveTargetEdit t1= new MoveTargetEdit(1, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(6, 1, "x");
s1.add(e2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "05x7123489", fBuffer.getContent());
assertEquals(s1.getTextRange(), 8, 0);
assertEquals(t1.getTextRange(), 1, 3);
assertEquals(e2.getTextRange(), 2, 1);
doUndoRedo(undo, "05x7123489");
}
public void testMove9() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(1, 3);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
MoveSourceEdit s2= new MoveSourceEdit(1, 1);
MoveTargetEdit t2= new MoveTargetEdit(3, s2);
s1.add(s2);
s1.add(t2);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 1, 0);
assertEquals(t1.getTextRange(), 2, 3);
assertEquals(s2.getTextRange(), 2, 0);
assertEquals(t2.getTextRange(), 3, 1);
assertEquals("Buffer content", "0421356789", fBuffer.getContent());
doUndoRedo(undo, "0421356789");
}
public void testMove10() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(8, s1);
MoveSourceEdit s2= new MoveSourceEdit(5, 2);
MoveTargetEdit t2= new MoveTargetEdit(1, s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(s2);
fEditor.add(t2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 4, 0);
assertEquals(t1.getTextRange(), 6, 2);
assertEquals(s2.getTextRange(), 5, 0);
assertEquals(t2.getTextRange(), 1, 2);
assertEquals("Buffer content", "0561472389", fBuffer.getContent());
doUndoRedo(undo, "0561472389");
}
public void testMoveWithTargetDelete() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 3);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(6, 2);
e2.add(t1);
fEditor.add(s1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01589", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertTrue(t1.getTextRange().isDeleted());
assertEquals(e2.getTextRange(), 3, 0);
doUndoRedo(undo, "01589");
}
public void testMoveWithSourceDelete() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(5, 2);
MoveTargetEdit t1= new MoveTargetEdit(1, s1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(5, 2);
e2.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0561234789", fBuffer.getContent());
assertTrue(s1.getTextRange().isDeleted());
assertEquals(t1.getTextRange(), 1, 2);
assertEquals(e2.getTextRange(), 7, 0);
doUndoRedo(undo, "0561234789");
}
public void testMoveWithSourceDelete2() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createDelete(2, 2);
e2.add(s1);
fEditor.add(t1);
fEditor.add(e2);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0145623789", fBuffer.getContent());
assertTrue(s1.getTextRange().isDeleted());
assertEquals(t1.getTextRange(), 5, 2);
doUndoRedo(undo, "0145623789");
}
public void testMoveUpWithInnerMark() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(7, 2);
MoveTargetEdit t1= new MoveTargetEdit(2, s1);
SimpleTextEdit m= SimpleTextEdit.createReplace(4, 1, "yy");
fEditor.add(t1);
fEditor.add(m);
fEditor.add(s1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "017823yy569", fBuffer.getContent());
assertEquals(s1.getTextRange(), 10, 0);
assertEquals(t1.getTextRange(), 2, 2);
assertEquals(m.getTextRange(), 6, 2);
doUndoRedo(undo, "017823yy569");
}
public void testMoveDownWithInnerMark() throws Exception {
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(7, s1);
SimpleTextEdit m= SimpleTextEdit.createReplace(4, 1, "yy");
fEditor.add(t1);
fEditor.add(m);
fEditor.add(s1);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "01yy5623789", fBuffer.getContent());
assertEquals(s1.getTextRange(), 2, 0);
assertEquals(t1.getTextRange(), 6, 2);
assertEquals(m.getTextRange(), 2, 2);
doUndoRedo(undo, "01yy5623789");
}
public void testMoveUpWithParentMark() throws Exception {
RangeMarker m= new RangeMarker(2, 6);
MoveSourceEdit s1= new MoveSourceEdit(4, 2);
MoveTargetEdit t1= new MoveTargetEdit(3, s1);
m.add(s1);
m.add(t1);
fEditor.add(m);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0124536789", fBuffer.getContent());
assertEquals(m.getTextRange(), 2, 6);
assertEquals(t1.getTextRange(), 3, 2);
assertEquals(s1.getTextRange(), 6, 0);
doUndoRedo(undo, "0124536789");
}
public void testMoveDownWithParentMark() throws Exception {
RangeMarker m= new RangeMarker(2, 6);
MoveSourceEdit s1= new MoveSourceEdit(2, 2);
MoveTargetEdit t1= new MoveTargetEdit(5, s1);
m.add(s1);
m.add(t1);
fEditor.add(m);
assertTrue(fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals("Buffer content", "0142356789", fBuffer.getContent());
assertEquals(m.getTextRange(), 2, 6);
assertEquals(t1.getTextRange(), 3, 2);
assertEquals(s1.getTextRange(), 2, 0);
doUndoRedo(undo, "0142356789");
}
public void testCopyDown() throws Exception {
CopySourceEdit s1= new CopySourceEdit(2, 3);
CopyTargetEdit t1= new CopyTargetEdit(8, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 2, 3);
assertEquals(t1.getTextRange(), 8, 3);
String result= "0123456723489";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testCopyUp() throws Exception {
CopySourceEdit s1= new CopySourceEdit(7, 2);
CopyTargetEdit t1= new CopyTargetEdit(3, s1);
fEditor.add(s1);
fEditor.add(t1);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 9, 2);
assertEquals(t1.getTextRange(), 3, 2);
String result= "012783456789";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testDoubleCopy() throws Exception {
CopySourceEdit s1= new CopySourceEdit(5, 2);
CopyTargetEdit t1= new CopyTargetEdit(8, s1);
CopySourceEdit s2= new CopySourceEdit(5, 2);
CopyTargetEdit t2= new CopyTargetEdit(2, s2);
s1.add(s2);
fEditor.add(s1);
fEditor.add(t1);
fEditor.add(t2);
assertTrue("Can perform edits", fEditor.canPerformEdits());
UndoMemento undo= fEditor.performEdits(null);
assertEquals(s1.getTextRange(), 7, 2);
assertEquals(t1.getTextRange(), 10, 2);
assertEquals(s2.getTextRange(), 7, 2);
assertEquals(t2.getTextRange(), 2, 2);
String result= "01562345675689";
assertEquals("Buffer content", result, fBuffer.getContent());
doUndoRedo(undo, result);
}
public void testSwap1() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
MultiTextEdit root= new MultiTextEdit();
{
CopySourceEdit innerRoot= new CopySourceEdit(0, 9);
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 9, "");
e1.add(innerRoot);
CopyTargetEdit t1= new CopyTargetEdit(11, innerRoot);
SimpleTextEdit e2= SimpleTextEdit.createReplace(11, 1, "");
CopySourceEdit s2= new CopySourceEdit(11, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(0, s2);
root.add(e1);
root.add(t2);
root.add(e2);
root.add(t1);
editor.add(root);
}
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "3, foo(1, 2)";
assertEquals("Buffer content", result, buffer.getContent());
}
public void testSwap2() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
MultiTextEdit innerRoot= new MultiTextEdit();
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(4, 1, "");
CopySourceEdit s1= new CopySourceEdit(4, 1);
e1.add(s1);
CopyTargetEdit t1= new CopyTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(7, 1, "");
CopySourceEdit s2= new CopySourceEdit(7, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(4, s2);
innerRoot.add(e1);
innerRoot.add(t2);
innerRoot.add(e2);
innerRoot.add(t1);
}
editor.add(innerRoot);
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "foo(2, 1), 3";
assertEquals("Buffer content", result, buffer.getContent());
}
public void testSwap2InSwap1() throws Exception {
TextBuffer buffer= TextBuffer.create("foo(1, 2), 3");
TextBufferEditor editor= new TextBufferEditor(buffer);
CopySourceEdit innerRoot= new CopySourceEdit(0, 9);
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(4, 1, "");
CopySourceEdit s1= new CopySourceEdit(4, 1);
e1.add(s1);
CopyTargetEdit t1= new CopyTargetEdit(7, s1);
SimpleTextEdit e2= SimpleTextEdit.createReplace(7, 1, "");
CopySourceEdit s2= new CopySourceEdit(7, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(4, s2);
innerRoot.add(e1);
innerRoot.add(t2);
innerRoot.add(e2);
innerRoot.add(t1);
}
MultiTextEdit root= new MultiTextEdit();
{
SimpleTextEdit e1= SimpleTextEdit.createReplace(0, 9, "");
e1.add(innerRoot);
CopyTargetEdit t1= new CopyTargetEdit(11, innerRoot);
SimpleTextEdit e2= SimpleTextEdit.createReplace(11, 1, "");
CopySourceEdit s2= new CopySourceEdit(11, 1);
e2.add(s2);
CopyTargetEdit t2= new CopyTargetEdit(0, s2);
root.add(e1);
root.add(t2);
root.add(e2);
root.add(t1);
editor.add(root);
}
assertTrue("Can perform edits", editor.canPerformEdits());
editor.performEdits(null);
String result= "3, foo(2, 1)";
assertEquals("Buffer content", result, buffer.getContent());
}
private void doUndoRedo(UndoMemento undo, String redoResult) throws Exception {
fEditor.add(undo);
UndoMemento redo= fEditor.performEdits(null);
assertBufferContent();
fEditor.add(redo);
undo= fEditor.performEdits(null);
assertEquals("Buffer content redo", redoResult, fBuffer.getContent());
fEditor.add(undo);
fEditor.performEdits(null);
assertBufferContent();
}
private void assertEquals(TextRange r, int offset, int length) {
assertEquals("Offset", offset, r.getOffset());
assertEquals("Length", length, r.getLength());
}
private void assertBufferContent() {
assertEquals("Buffer content restored", "0123456789", fBuffer.getContent());
}
private void assertTrue(IStatus status) {
assertTrue(status.isOK());
}
private void assertTrue(String message, IStatus status) {
assertTrue(message, status.isOK());
}
private void assertFalse(IStatus status) {
assertTrue(!status.isOK());
}
}
|
38,922 |
Bug 38922 method getNextPage() in JavadocTreeWizardPage unnecessary [Javadoc] [Wizard]
| null |
closed fixed
|
34a38d2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-25T14:01:12Z | 2003-06-14T17:00:00Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocTreeWizardPage.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javadocexport;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.jdt.internal.ui.jarpackager.CheckboxTreeAndListGroup;
import org.eclipse.jdt.internal.ui.util.SWTUtil;
public class JavadocTreeWizardPage extends JavadocWizardPage {
private CheckboxTreeAndListGroup fInputGroup;
protected IWorkspaceRoot fRoot;
protected String fWorkspace;
//private JavadocTreeViewerFilter fFilter;
protected Text fDestinationText;
protected Text fDocletText;
protected Text fDocletTypeText;
protected Button fStandardButton;
protected Button fDestinationBrowserButton;
protected Button fCustomButton;
protected Button fPrivateVisibility;
protected Button fProtectedVisibility;
protected Button fPackageVisibility;
protected Button fPublicVisibility;
private Label fDocletLabel;
private Label fDocletTypeLabel;
private Label fDestinationLabel;
private CLabel fDescriptionLabel;
protected String fVisibilitySelection;
protected boolean fDocletSelected;
private JavadocOptionsManager fStore;
private JavadocWizard fWizard;
protected StatusInfo fDestinationStatus;
protected StatusInfo fDocletStatus;
protected StatusInfo fTreeStatus;
protected StatusInfo fPreferenceStatus;
protected StatusInfo fWizardStatus;
private final int PREFERENCESTATUS= 0;
private final int CUSTOMSTATUS= 1;
private final int STANDARDSTATUS= 2;
private final int TREESTATUS= 3;
/**
* Constructor for JavadocTreeWizardPage.
* @param pageName
*/
protected JavadocTreeWizardPage(String pageName, JavadocOptionsManager store) {
super(pageName);
setDescription(JavadocExportMessages.getString("JavadocTreeWizardPage.javadoctreewizardpage.description")); //$NON-NLS-1$
fStore= store;
// Status variables
fDestinationStatus= new StatusInfo();
fDocletStatus= new StatusInfo();
fTreeStatus= new StatusInfo();
fPreferenceStatus= new StatusInfo();
fWizardStatus= store.getWizardStatus();
}
/*
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
initializeDialogUnits(parent);
fWizard= (JavadocWizard) this.getWizard();
Composite composite= new Composite(parent, SWT.NONE);
GridLayout compositeGridLayout= new GridLayout();
composite.setLayoutData(createGridData(GridData.FILL_BOTH, 0, 0));
compositeGridLayout.numColumns= 6;
composite.setLayout(compositeGridLayout);
createInputGroup(composite);
createVisibilitySet(composite);
createOptionsSet(composite);
setControl(composite);
Dialog.applyDialogFont(composite);
WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.JAVADOC_TREE_PAGE);
}
protected void createInputGroup(Composite composite) {
createLabel(composite, SWT.NONE, JavadocExportMessages.getString("JavadocTreeWizardPage.checkboxtreeandlistgroup.label"), createGridData(6)); //$NON-NLS-1$
Composite c= new Composite(composite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.numColumns= 1;
layout.makeColumnsEqualWidth= true;
c.setLayout(layout);
c.setLayoutData(createGridData(GridData.FILL_BOTH, 6, 0));
ITreeContentProvider treeContentProvider= new JavadocProjectContentProvider();
ITreeContentProvider listContentProvider= new JavadocMemberContentProvider();
fInputGroup= new CheckboxTreeAndListGroup(c, fStore.getRoot(), treeContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), listContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), SWT.NONE, convertWidthInCharsToPixels(60), convertHeightInCharsToPixels(10));
fInputGroup.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
doValidation(TREESTATUS);
fWizard.removeAllProjects();
setProjects();
}
});
try {
//the store will contain at least one project in it's list so long as
//the workspace is not empty.
if (!fStore.getJavaProjects().isEmpty())
setTreeChecked(fStore.getSelectedElements(), (IJavaProject) fStore.getJavaProjects().get(0));
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
fInputGroup.aboutToOpen();
}
private void createVisibilitySet(Composite composite) {
GridLayout visibilityLayout= createGridLayout(4);
visibilityLayout.marginHeight= 0;
visibilityLayout.marginWidth= 0;
Composite visibilityGroup= new Composite(composite, SWT.NONE);
visibilityGroup.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 6, 0));
visibilityGroup.setLayout(visibilityLayout);
createLabel(visibilityGroup, SWT.NONE, JavadocExportMessages.getString("JavadocTreeWizardPage.visibilitygroup.label"), createGridData(GridData.FILL_HORIZONTAL, 4, 0)); //$NON-NLS-1$
fPrivateVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.privatebutton.label"), createGridData(GridData.FILL_HORIZONTAL, 1, 0)); //$NON-NLS-1$
fPackageVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.packagebutton.label"), createGridData(GridData.FILL_HORIZONTAL, 1, 0)); //$NON-NLS-1$
fProtectedVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.protectedbutton.label"), createGridData(GridData.FILL_HORIZONTAL, 1, 0)); //$NON-NLS-1$
fPublicVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.publicbutton.label"), createGridData(GridData.FILL_HORIZONTAL, 1, 0)); //$NON-NLS-1$
fDescriptionLabel= new CLabel(visibilityGroup, SWT.LEFT);
fDescriptionLabel.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 4, convertWidthInCharsToPixels(3) - 3)); // INDENT of CLabel
fPrivateVisibility.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (((Button) e.widget).getSelection()) {
fVisibilitySelection= fStore.PRIVATE;
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.privatevisibilitydescription.label")); //$NON-NLS-1$
}
}
});
fPackageVisibility.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (((Button) e.widget).getSelection()) {
fVisibilitySelection= fStore.PACKAGE;
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.packagevisibledescription.label")); //$NON-NLS-1$
}
}
});
fProtectedVisibility.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (((Button) e.widget).getSelection()) {
fVisibilitySelection= fStore.PROTECTED;
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.protectedvisibilitydescription.label")); //$NON-NLS-1$
}
}
});
fPublicVisibility.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (((Button) e.widget).getSelection()) {
fVisibilitySelection= fStore.PUBLIC;
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.publicvisibilitydescription.label")); //$NON-NLS-1$
}
}
});
setVisibilitySettings();
}
protected void setVisibilitySettings() {
fVisibilitySelection= fStore.getAccess();
fPrivateVisibility.setSelection(fVisibilitySelection.equals(fStore.PRIVATE));
if (fPrivateVisibility.getSelection())
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.privatevisibilitydescription.label")); //$NON-NLS-1$
//$NON-NLS-1$
fProtectedVisibility.setSelection(fVisibilitySelection.equals(fStore.PROTECTED));
if (fProtectedVisibility.getSelection())
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.protectedvisibilitydescription.label")); //$NON-NLS-1$
//$NON-NLS-1$
fPackageVisibility.setSelection(fVisibilitySelection.equals(fStore.PACKAGE));
if (fPackageVisibility.getSelection())
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.packagevisibledescription.label")); //$NON-NLS-1$
//$NON-NLS-1$
fPublicVisibility.setSelection(fVisibilitySelection.equals(fStore.PUBLIC));
if (fPublicVisibility.getSelection())
fDescriptionLabel.setText(JavadocExportMessages.getString("JavadocTreeWizardPage.publicvisibilitydescription.label")); //$NON-NLS-1$
//$NON-NLS-1$
}
private void createOptionsSet(Composite composite) {
GridLayout optionSetLayout= createGridLayout(3);
optionSetLayout.marginHeight= 0;
optionSetLayout.marginWidth= 0;
Composite optionSetGroup= new Composite(composite, SWT.NONE);
optionSetGroup.setLayoutData(createGridData(GridData.FILL_BOTH, 6, 0));
optionSetGroup.setLayout(optionSetLayout);
fStandardButton= createButton(optionSetGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.standarddocletbutton.label"), createGridData(GridData.HORIZONTAL_ALIGN_FILL, 3, 0)); //$NON-NLS-1$
GridData gd= new GridData();
gd.horizontalSpan= 1;
fDestinationLabel= createLabel(optionSetGroup, SWT.NONE, JavadocExportMessages.getString("JavadocTreeWizardPage.destinationfield.label"), createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, convertWidthInCharsToPixels(3))); //$NON-NLS-1$
fDestinationText= createText(optionSetGroup, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
//there really aught to be a way to specify this
((GridData) fDestinationText.getLayoutData()).widthHint= 200;
fDestinationText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
doValidation(STANDARDSTATUS);
}
});
fDestinationBrowserButton= createButton(optionSetGroup, SWT.PUSH, JavadocExportMessages.getString("JavadocTreeWizardPage.destinationbrowse.label"), createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, 0)); //$NON-NLS-1$
SWTUtil.setButtonDimensionHint(fDestinationBrowserButton);
//Option to use custom doclet
fCustomButton= createButton(optionSetGroup, SWT.RADIO, JavadocExportMessages.getString("JavadocTreeWizardPage.customdocletbutton.label"), createGridData(3)); //$NON-NLS-1$
//For Entering location of custom doclet
fDocletTypeLabel= createLabel(optionSetGroup, SWT.NONE, JavadocExportMessages.getString("JavadocTreeWizardPage.docletnamefield.label"), createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, convertWidthInCharsToPixels(3))); //$NON-NLS-1$
fDocletTypeText= createText(optionSetGroup, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 2, 0));
fDocletTypeText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
doValidation(CUSTOMSTATUS);
}
});
fDocletLabel= createLabel(optionSetGroup, SWT.NONE, JavadocExportMessages.getString("JavadocTreeWizardPage.docletpathfield.label"), createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, convertWidthInCharsToPixels(3))); //$NON-NLS-1$
fDocletText= createText(optionSetGroup, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 2, 0));
fDocletText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
doValidation(CUSTOMSTATUS);
}
});
//Add Listeners
fCustomButton.addSelectionListener(new EnableSelectionAdapter(new Control[] { fDocletLabel, fDocletText, fDocletTypeLabel, fDocletTypeText }, new Control[] { fDestinationLabel, fDestinationText, fDestinationBrowserButton }));
fCustomButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
doValidation(CUSTOMSTATUS);
}
});
fStandardButton.addSelectionListener(new EnableSelectionAdapter(new Control[] { fDestinationLabel, fDestinationText, fDestinationBrowserButton }, new Control[] { fDocletLabel, fDocletText, fDocletTypeLabel, fDocletTypeText }));
fStandardButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
doValidation(STANDARDSTATUS);
}
});
fDestinationBrowserButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String text= handleFolderBrowseButtonPressed(fDestinationText.getText(), fDestinationText.getShell(), JavadocExportMessages.getString("JavadocTreeWizardPage.destinationbrowsedialog.title"), //$NON-NLS-1$
JavadocExportMessages.getString("JavadocTreeWizardPage.destinationbrowsedialog.label")); //$NON-NLS-1$
fDestinationText.setText(text);
}
});
setOptionSetSettings();
}
public boolean getCustom() {
return fCustomButton.getSelection();
}
private void setOptionSetSettings() {
if (!fStore.fromStandard()) {
fCustomButton.setSelection(true);
fDocletText.setText(fStore.getDocletPath());
fDocletTypeText.setText(fStore.getDocletName());
//take the destination as the destination of the first project
fDestinationText.setText(fStore.getDestination((IJavaProject) fWizard.getSelectedProjects().iterator().next()));
fDestinationText.setEnabled(false);
fDestinationBrowserButton.setEnabled(false);
fDestinationLabel.setEnabled(false);
} else {
fStandardButton.setSelection(true);
if (fWizard.getSelectedProjects().size() == 1)
fDestinationText.setText(fStore.getDestination((IJavaProject) fWizard.getSelectedProjects().iterator().next()));
else
fDestinationText.setText(fStore.getDestination());
fDocletText.setText(fStore.getDocletPath());
fDocletTypeText.setText(fStore.getDocletName());
fDocletText.setEnabled(false);
fDocletLabel.setEnabled(false);
fDocletTypeText.setEnabled(false);
fDocletTypeLabel.setEnabled(false);
}
}
/**
* Receives of list of elements selected by the user and passes them
* to the CheckedTree. List can contain multiple projects and elements from
* different projects. If the list of seletected elements is empty a default
* project is selected.
*/
protected void setTreeChecked(IJavaElement[] sourceElements, IJavaProject project) throws JavaModelException {
if (sourceElements.length < 1)
fInputGroup.initialCheckTreeItem(project);
else {
for (int i= 0; i < sourceElements.length; i++) {
IJavaElement curr= sourceElements[i];
if (curr instanceof ICompilationUnit) {
fInputGroup.initialCheckListItem(curr);
} else if (curr instanceof IPackageFragment) {
fInputGroup.initialCheckTreeItem(curr);
} else if (curr instanceof IJavaProject) {
fInputGroup.initialCheckTreeItem(curr);
} else if (curr instanceof IPackageFragmentRoot) {
IPackageFragmentRoot root= (IPackageFragmentRoot) curr;
if (!root.isArchive())
fInputGroup.initialCheckTreeItem(curr);
}
}
}
}
private IPath[] getSourcePath(IJavaProject[] projects) {
ArrayList res= new ArrayList();
//loops through all projects and gets a list if of thier sourpaths
for (int k= 0; k < projects.length; k++) {
IJavaProject iJavaProject= projects[k];
try {
IPackageFragmentRoot[] roots= iJavaProject.getPackageFragmentRoots();
for (int i= 0; i < roots.length; i++) {
IPackageFragmentRoot curr= roots[i];
if (curr.getKind() == IPackageFragmentRoot.K_SOURCE) {
IResource resource= curr.getResource();
if (resource != null) {
IPath p= resource.getLocation();
if (p != null) {
res.add(p);
}
}
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
}
return (IPath[]) res.toArray(new IPath[res.size()]);
}
private IPath[] getClassPath(IJavaProject[] javaProjects) {
ArrayList res= new ArrayList();
for (int j= 0; j < javaProjects.length; j++) {
IJavaProject iJavaProject= javaProjects[j];
try {
IPath p= iJavaProject.getProject().getLocation();
if (p == null)
continue;
IPath outputLocation= p.append(iJavaProject.getOutputLocation());
String[] classPath= JavaRuntime.computeDefaultRuntimeClassPath(iJavaProject);
for (int i= 0; i < classPath.length; i++) {
String curr= classPath[i];
IPath path= new Path(curr);
if (!outputLocation.equals(path)) {
res.add(path);
}
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
return (IPath[]) res.toArray(new IPath[res.size()]);
}
/**
* Gets a list of elements to generated javadoc for from each project.
* Javadoc can be generated for either a IPackageFragmentRoot or a ICompilationUnit.
*/
private IJavaElement[] getSourceElements(IJavaProject[] projects) {
ArrayList res= new ArrayList();
try {
Set allChecked= fInputGroup.getAllCheckedTreeItems();
Set incompletePackages= new HashSet();
for (int h= 0; h < projects.length; h++) {
IJavaProject iJavaProject= projects[h];
IPackageFragmentRoot[] roots= iJavaProject.getPackageFragmentRoots();
for (int i= 0; i < roots.length; i++) {
IPackageFragmentRoot root= roots[i];
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
IJavaElement[] packs= root.getChildren();
for (int k= 0; k < packs.length; k++) {
IJavaElement curr= packs[k];
if (curr.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
// default packages are always incomplete
if (curr.getElementName().length() == 0 || !allChecked.contains(curr) || fInputGroup.isTreeItemGreyChecked(curr)) {
incompletePackages.add(curr.getElementName());
}
}
}
}
}
}
Iterator checkedElements= fInputGroup.getAllCheckedListItems();
while (checkedElements.hasNext()) {
Object element= checkedElements.next();
if (element instanceof ICompilationUnit) {
ICompilationUnit unit= (ICompilationUnit) element;
if (incompletePackages.contains(unit.getParent().getElementName())) {
res.add(unit);
}
}
}
Set addedPackages= new HashSet();
checkedElements= allChecked.iterator();
while (checkedElements.hasNext()) {
Object element= checkedElements.next();
if (element instanceof IPackageFragment) {
IPackageFragment fragment= (IPackageFragment) element;
String name= fragment.getElementName();
if (!incompletePackages.contains(name) && !addedPackages.contains(name)) {
res.add(fragment);
addedPackages.add(name);
}
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
return (IJavaElement[]) res.toArray(new IJavaElement[res.size()]);
}
protected void finish() {
if (fCustomButton.getSelection()) {
fStore.setDocletName(fDocletTypeText.getText());
fStore.setDocletPath(fDocletText.getText());
fStore.setFromStandard(false);
}
if (fStandardButton.getSelection()) {
fStore.setFromStandard(true);
//in case of a single project selection the personal destination is updated for
//storage in the dialog settings
if (fWizard.getSelectedProjects().size() == 1) {
fStore.setDestination((IJavaProject) fWizard.getSelectedProjects().iterator().next(), fDestinationText.getText());
}
//the destination used in javadoc generation
fStore.setDestination(fDestinationText.getText());
}
IJavaProject[] projects= (IJavaProject[]) fWizard.getSelectedProjects().toArray(new IJavaProject[fWizard.getSelectedProjects().size()]);
fStore.setProjects(projects, true);
fStore.setSourcepath(getSourcePath(projects));
fStore.setClasspath(getClassPath(projects));
fStore.setAccess(fVisibilitySelection);
fStore.setSourceElements(getSourceElements(projects));
}
protected void setProjects() {
TreeItem[] treeItems= fInputGroup.getTree().getItems();
for (int i= 0; i < treeItems.length; i++) {
if (treeItems[i].getChecked())
fWizard.addSelectedProject((IJavaProject) treeItems[i].getData());
}
}
private void doValidation(int validate) {
switch (validate) {
case PREFERENCESTATUS :
fPreferenceStatus= new StatusInfo();
fDocletStatus= new StatusInfo();
updateStatus(findMostSevereStatus());
break;
case CUSTOMSTATUS :
if (fCustomButton.getSelection()) {
fDestinationStatus= new StatusInfo();
fDocletStatus= new StatusInfo();
String doclet= fDocletTypeText.getText();
String docletPath= fDocletText.getText();
if (doclet.length() == 0) {
fDocletStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.nodocletname.error")); //$NON-NLS-1$
} else if (JavaConventions.validateJavaTypeName(doclet).matches(IStatus.ERROR)) {
fDocletStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.invaliddocletname.error")); //$NON-NLS-1$
} else if ((docletPath.length() == 0) || !validDocletPath(docletPath)) {
fDocletStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.invaliddocletpath.error")); //$NON-NLS-1$
}
updateStatus(findMostSevereStatus());
}
break;
case STANDARDSTATUS :
if (fStandardButton.getSelection()) {
fDestinationStatus= new StatusInfo();
fDocletStatus= new StatusInfo();
IPath path= new Path(fDestinationText.getText());
if (Path.ROOT.equals(path) || Path.EMPTY.equals(path)) {
fDestinationStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.nodestination.error")); //$NON-NLS-1$
}
File file= new File(path.toOSString());
if (!path.isValidPath(path.toOSString()) || file.isFile()) {
fDestinationStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.invaliddestination.error")); //$NON-NLS-1$
}
if ((path.append("package-list").toFile().exists()) || (path.append("index.html").toFile().exists())) //$NON-NLS-1$//$NON-NLS-2$
fDestinationStatus.setWarning(JavadocExportMessages.getString("JavadocTreeWizardPage.warning.mayoverwritefiles")); //$NON-NLS-1$
updateStatus(findMostSevereStatus());
}
break;
case TREESTATUS :
fTreeStatus= new StatusInfo();
if (fInputGroup.getAllCheckedTreeItems().size() == 0)
fTreeStatus.setError(JavadocExportMessages.getString("JavadocTreeWizardPage.invalidtreeselection.error")); //$NON-NLS-1$
updateStatus(findMostSevereStatus());
break;
} //end switch
}
private boolean validDocletPath(String docletPath) {
StringTokenizer tokens= new StringTokenizer(docletPath, ";"); //$NON-NLS-1$
while (tokens.hasMoreTokens()) {
File file= new File(tokens.nextToken());
if (!file.exists())
return false;
}
return true;
}
/**
* Finds the most severe error (if there is one)
*/
private IStatus findMostSevereStatus() {
return StatusUtil.getMostSevere(new IStatus[] { fPreferenceStatus, fDestinationStatus, fDocletStatus, fTreeStatus, fWizardStatus });
}
public void init() {
updateStatus(new StatusInfo());
}
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
doValidation(STANDARDSTATUS);
doValidation(CUSTOMSTATUS);
doValidation(TREESTATUS);
doValidation(PREFERENCESTATUS);
}
}
public IPath getDestination() {
if (fStandardButton.getSelection()) {
return new Path(fDestinationText.getText());
}
return null;
}
public IWizardPage getNextPage() {
return super.getNextPage();
}
}
|
31,240 |
Bug 31240 quick fix: new methods called from construcotr calls should be static [code manipulation]
|
class A{ A(){ this(bar()); //<<< wiggly here } A(int y){} } the new bar method should be static (otherwise it will not compile) same for 'this(..)'
|
resolved fixed
|
93b2fe3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-25T14:50:14Z | 2003-02-07T12:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.correction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
public class ASTResolving {
public static ITypeBinding guessBindingForReference(ASTNode node) {
return Bindings.normalizeTypeBinding(getPossibleReferenceBinding(node));
}
private static ITypeBinding getPossibleReferenceBinding(ASTNode node) {
ASTNode parent= node.getParent();
switch (parent.getNodeType()) {
case ASTNode.ASSIGNMENT:
Assignment assignment= (Assignment) parent;
if (node.equals(assignment.getLeftHandSide())) {
// field write access: xx= expression
return assignment.getRightHandSide().resolveTypeBinding();
}
// read access
return assignment.getLeftHandSide().resolveTypeBinding();
case ASTNode.INFIX_EXPRESSION:
InfixExpression infix= (InfixExpression) parent;
if (node.equals(infix.getLeftOperand())) {
// xx == expression
return infix.getRightOperand().resolveTypeBinding();
}
// expression == xx
InfixExpression.Operator op= infix.getOperator();
if (op == InfixExpression.Operator.LEFT_SHIFT || op == InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED
|| op == InfixExpression.Operator.RIGHT_SHIFT_SIGNED) {
return infix.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
}
return infix.getLeftOperand().resolveTypeBinding();
case ASTNode.INSTANCEOF_EXPRESSION:
InstanceofExpression instanceofExpression= (InstanceofExpression) parent;
return instanceofExpression.getRightOperand().resolveBinding();
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
VariableDeclarationFragment frag= (VariableDeclarationFragment) parent;
if (frag.getInitializer().equals(node)) {
return frag.getName().resolveTypeBinding();
}
break;
case ASTNode.SUPER_METHOD_INVOCATION:
SuperMethodInvocation superMethodInvocation= (SuperMethodInvocation) parent;
IMethodBinding superMethodBinding= ASTNodes.getMethodBinding(superMethodInvocation.getName());
if (superMethodBinding != null) {
return getParameterTypeBinding(node, superMethodInvocation.arguments(), superMethodBinding);
}
break;
case ASTNode.METHOD_INVOCATION:
MethodInvocation methodInvocation= (MethodInvocation) parent;
IMethodBinding methodBinding= ASTNodes.getMethodBinding(methodInvocation.getName());
if (methodBinding != null) {
return getParameterTypeBinding(node, methodInvocation.arguments(), methodBinding);
}
break;
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
SuperConstructorInvocation superInvocation= (SuperConstructorInvocation) parent;
IMethodBinding superBinding= superInvocation.resolveConstructorBinding();
if (superBinding != null) {
return getParameterTypeBinding(node, superInvocation.arguments(), superBinding);
}
break;
case ASTNode.CONSTRUCTOR_INVOCATION:
ConstructorInvocation constrInvocation= (ConstructorInvocation) parent;
IMethodBinding constrBinding= constrInvocation.resolveConstructorBinding();
if (constrBinding != null) {
return getParameterTypeBinding(node, constrInvocation.arguments(), constrBinding);
}
break;
case ASTNode.CLASS_INSTANCE_CREATION:
ClassInstanceCreation creation= (ClassInstanceCreation) parent;
IMethodBinding creationBinding= creation.resolveConstructorBinding();
if (creationBinding != null) {
return getParameterTypeBinding(node, creation.arguments(), creationBinding);
}
break;
case ASTNode.PARENTHESIZED_EXPRESSION:
return guessBindingForReference(parent);
case ASTNode.ARRAY_ACCESS:
if (((ArrayAccess) parent).getIndex().equals(node)) {
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
} else {
return getPossibleReferenceBinding(parent);
}
case ASTNode.ARRAY_CREATION:
if (((ArrayCreation) parent).dimensions().contains(node)) {
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
}
break;
case ASTNode.ARRAY_INITIALIZER:
ASTNode initializerParent= parent.getParent();
if (initializerParent instanceof ArrayCreation) {
return ((ArrayCreation) initializerParent).getType().getElementType().resolveBinding();
}
break;
case ASTNode.CONDITIONAL_EXPRESSION:
ConditionalExpression expression= (ConditionalExpression) parent;
if (node.equals(expression.getExpression())) {
return parent.getAST().resolveWellKnownType("boolean"); //$NON-NLS-1$
}
if (node.equals(expression.getElseExpression())) {
return expression.getThenExpression().resolveTypeBinding();
}
return expression.getElseExpression().resolveTypeBinding();
case ASTNode.POSTFIX_EXPRESSION:
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
case ASTNode.PREFIX_EXPRESSION:
if (((PrefixExpression) parent).getOperator() == PrefixExpression.Operator.NOT) {
return parent.getAST().resolveWellKnownType("boolean"); //$NON-NLS-1$
}
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
case ASTNode.IF_STATEMENT:
case ASTNode.WHILE_STATEMENT:
case ASTNode.DO_STATEMENT:
if (node instanceof Expression) {
return parent.getAST().resolveWellKnownType("boolean"); //$NON-NLS-1$
}
break;
case ASTNode.SWITCH_STATEMENT:
if (((SwitchStatement) parent).getExpression().equals(node)) {
return parent.getAST().resolveWellKnownType("int"); //$NON-NLS-1$
}
break;
case ASTNode.RETURN_STATEMENT:
MethodDeclaration decl= findParentMethodDeclaration(parent);
if (decl != null) {
return decl.getReturnType().resolveBinding();
}
break;
case ASTNode.CAST_EXPRESSION:
return ((CastExpression) parent).getType().resolveBinding();
case ASTNode.THROW_STATEMENT:
case ASTNode.CATCH_CLAUSE:
return parent.getAST().resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$
case ASTNode.FIELD_ACCESS:
if (node.equals(((FieldAccess) parent).getName())) {
return getPossibleReferenceBinding(parent);
}
break;
case ASTNode.SUPER_FIELD_ACCESS:
return getPossibleReferenceBinding(parent);
case ASTNode.QUALIFIED_NAME:
if (node.equals(((QualifiedName) parent).getName())) {
return getPossibleReferenceBinding(parent);
}
break;
}
return null;
}
private static ITypeBinding getParameterTypeBinding(ASTNode node, List args, IMethodBinding binding) {
ITypeBinding[] paramTypes= binding.getParameterTypes();
int index= args.indexOf(node);
if (index >= 0 && index < paramTypes.length) {
return paramTypes[index];
}
return null;
}
public static ITypeBinding guessBindingForTypeReference(ASTNode node) {
return Bindings.normalizeTypeBinding(getPossibleTypeBinding(node));
}
private static ITypeBinding getPossibleTypeBinding(ASTNode node) {
ASTNode parent= node.getParent();
while (parent instanceof Type) {
parent= parent.getParent();
}
switch (parent.getNodeType()) {
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
return guessVariableType(((VariableDeclarationStatement) parent).fragments());
case ASTNode.FIELD_DECLARATION:
return guessVariableType(((FieldDeclaration) parent).fragments());
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
return guessVariableType(((VariableDeclarationExpression) parent).fragments());
case ASTNode.SINGLE_VARIABLE_DECLARATION:
SingleVariableDeclaration varDecl= (SingleVariableDeclaration) parent;
if (varDecl.getInitializer() != null) {
return varDecl.getInitializer().resolveTypeBinding();
}
break;
case ASTNode.ARRAY_CREATION:
ArrayCreation creation= (ArrayCreation) parent;
if (creation.getInitializer() != null) {
return creation.getInitializer().resolveTypeBinding();
}
return getPossibleReferenceBinding(parent);
case ASTNode.TYPE_LITERAL:
case ASTNode.CLASS_INSTANCE_CREATION:
return getPossibleReferenceBinding(parent);
}
return null;
}
private static ITypeBinding guessVariableType(List fragments) {
for (Iterator iter= fragments.iterator(); iter.hasNext();) {
VariableDeclarationFragment frag= (VariableDeclarationFragment) iter.next();
if (frag.getInitializer() != null) {
return frag.getInitializer().resolveTypeBinding();
}
}
return null;
}
public static MethodDeclaration findParentMethodDeclaration(ASTNode node) {
while ((node != null) && (node.getNodeType() != ASTNode.METHOD_DECLARATION)) {
node= node.getParent();
}
return (MethodDeclaration) node;
}
public static BodyDeclaration findParentBodyDeclaration(ASTNode node) {
while ((node != null) && (!(node instanceof BodyDeclaration))) {
node= node.getParent();
}
return (BodyDeclaration) node;
}
public static CompilationUnit findParentCompilationUnit(ASTNode node) {
return (CompilationUnit) findAncestor(node, ASTNode.COMPILATION_UNIT);
}
/**
* Returns either a TypeDeclaration or an AnonymousTypeDeclaration
* @param node
* @return CompilationUnit
*/
public static ASTNode findParentType(ASTNode node) {
while ((node != null) && (node.getNodeType() != ASTNode.TYPE_DECLARATION) && (node.getNodeType() != ASTNode.ANONYMOUS_CLASS_DECLARATION)) {
node= node.getParent();
}
return node;
}
public static ASTNode findAncestor(ASTNode node, int nodeType) {
while ((node != null) && (node.getNodeType() != nodeType)) {
node= node.getParent();
}
return node;
}
public static Statement findParentStatement(ASTNode node) {
while ((node != null) && (!(node instanceof Statement))) {
node= node.getParent();
if (node instanceof BodyDeclaration) {
return null;
}
}
return (Statement) node;
}
public static TryStatement findParentTryStatement(ASTNode node) {
while ((node != null) && (!(node instanceof TryStatement))) {
node= node.getParent();
if (node instanceof BodyDeclaration) {
return null;
}
}
return (TryStatement) node;
}
public static boolean isInStaticContext(ASTNode selectedNode) {
BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
if (decl instanceof MethodDeclaration) {
return Modifier.isStatic(((MethodDeclaration)decl).getModifiers());
} else if (decl instanceof Initializer) {
return Modifier.isStatic(((Initializer)decl).getModifiers());
} else if (decl instanceof FieldDeclaration) {
return Modifier.isStatic(((FieldDeclaration)decl).getModifiers());
}
return false;
}
public static Type getTypeFromTypeBinding(AST ast, ITypeBinding binding) {
if (binding.isArray()) {
int dim= binding.getDimensions();
return ast.newArrayType(getTypeFromTypeBinding(ast, binding.getElementType()), dim);
} else if (binding.isPrimitive()) {
String name= binding.getName();
return ast.newPrimitiveType(PrimitiveType.toCode(name));
} else if (!binding.isNullType() && !binding.isAnonymous()) {
return ast.newSimpleType(ast.newSimpleName(binding.getName()));
}
return null;
}
private static TypeDeclaration findTypeDeclaration(List decls, String name) {
for (Iterator iter= decls.iterator(); iter.hasNext();) {
ASTNode elem= (ASTNode) iter.next();
if (elem instanceof TypeDeclaration) {
TypeDeclaration decl= (TypeDeclaration) elem;
if (name.equals(decl.getName().getIdentifier())) {
return decl;
}
}
}
return null;
}
public static TypeDeclaration findTypeDeclaration(CompilationUnit root, ITypeBinding binding) {
ArrayList names= new ArrayList(5);
while (binding != null) {
names.add(binding.getName());
binding= binding.getDeclaringClass();
}
List types= root.types();
for (int i= names.size() - 1; i >= 0; i--) {
String name= (String) names.get(i);
TypeDeclaration decl= findTypeDeclaration(types, name);
if (decl == null || i == 0) {
return decl;
}
types= decl.bodyDeclarations();
}
return null;
}
public static String getFullName(Name name) {
return ASTNodes.asString(name);
}
public static String getQualifier(Name name) {
if (name.isQualifiedName()) {
return getFullName(((QualifiedName) name).getQualifier());
}
return ""; //$NON-NLS-1$
}
public static String getSimpleName(Name name) {
if (name.isQualifiedName()) {
return ((QualifiedName) name).getName().getIdentifier();
} else {
return ((SimpleName) name).getIdentifier();
}
}
public static ICompilationUnit findCompilationUnitForBinding(ICompilationUnit cu, CompilationUnit astRoot, ITypeBinding binding) throws JavaModelException {
if (binding != null && binding.isFromSource() && astRoot.findDeclaringNode(binding) == null) {
ICompilationUnit targetCU= Bindings.findCompilationUnit(binding, cu.getJavaProject());
if (targetCU != null) {
return JavaModelUtil.toWorkingCopy(targetCU);
}
return null;
}
return cu;
}
}
|
31,240 |
Bug 31240 quick fix: new methods called from construcotr calls should be static [code manipulation]
|
class A{ A(){ this(bar()); //<<< wiggly here } A(int y){} } the new bar method should be static (otherwise it will not compile) same for 'this(..)'
|
resolved fixed
|
93b2fe3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-25T14:50:14Z | 2003-02-07T12:13:20Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/NewMethodCompletionProposal.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.correction;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.NamingConventions;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.ui.CodeGeneration;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.ASTRewrite;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
public class NewMethodCompletionProposal extends ASTRewriteCorrectionProposal {
private ASTNode fNode; // MethodInvocation, ConstructorInvocation, SuperConstructorInvocation, ClassInstanceCreation, SuperMethodInvocation
private List fArguments;
private ITypeBinding fSenderBinding;
private boolean fIsInDifferentCU;
public NewMethodCompletionProposal(String label, ICompilationUnit targetCU, ASTNode invocationNode, List arguments, ITypeBinding binding, int relevance, Image image) {
super(label, targetCU, null, relevance, image);
fNode= invocationNode;
fArguments= arguments;
fSenderBinding= binding;
}
protected ASTRewrite getRewrite() throws CoreException {
CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fNode);
ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
ASTNode newTypeDecl= null;
if (typeDecl != null) {
fIsInDifferentCU= false;
newTypeDecl= typeDecl;
} else {
fIsInDifferentCU= true;
CompilationUnit newRoot= AST.parseCompilationUnit(getCompilationUnit(), true);
newTypeDecl= newRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
ASTRewrite rewrite= new ASTRewrite(newTypeDecl);
List members;
if (fSenderBinding.isAnonymous()) {
members= ((AnonymousClassDeclaration) newTypeDecl).bodyDeclarations();
} else {
members= ((TypeDeclaration) newTypeDecl).bodyDeclarations();
}
MethodDeclaration newStub= getStub(rewrite, newTypeDecl);
if (isConstructor()) {
members.add(findConstructorInsertIndex(members), newStub);
} else if (!fIsInDifferentCU) {
members.add(findMethodInsertIndex(members, fNode.getStartPosition()), newStub);
} else {
members.add(newStub);
}
rewrite.markAsInserted(newStub, SELECTION_GROUP_DESC);
return rewrite;
}
return null;
}
private boolean isConstructor() {
return fNode.getNodeType() != ASTNode.METHOD_INVOCATION && fNode.getNodeType() != ASTNode.SUPER_METHOD_INVOCATION;
}
private MethodDeclaration getStub(ASTRewrite rewrite, ASTNode targetTypeDecl) throws CoreException {
AST ast= targetTypeDecl.getAST();
MethodDeclaration decl= ast.newMethodDeclaration();
decl.setConstructor(isConstructor());
decl.setModifiers(evaluateModifiers(targetTypeDecl));
decl.setName(ast.newSimpleName(getMethodName()));
List arguments= fArguments;
List params= decl.parameters();
int nArguments= arguments.size();
ArrayList takenNames= new ArrayList(nArguments);
IVariableBinding[] declaredFields= fSenderBinding.getDeclaredFields();
for (int i= 0; i < declaredFields.length; i++) { // avoid to take parameter names that are equal to field names
takenNames.add(declaredFields[i].getName());
}
for (int i= 0; i < arguments.size(); i++) {
Expression elem= (Expression) arguments.get(i);
SingleVariableDeclaration param= ast.newSingleVariableDeclaration();
Type type= getParameterType(ast, elem);
param.setType(type);
param.setName(ast.newSimpleName(getParameterName(takenNames, elem, type)));
params.add(param);
}
Block body= null;
String bodyStatement= ""; //$NON-NLS-1$
if (!isConstructor()) {
Type returnType= evaluateMethodType(ast);
if (returnType == null) {
decl.setReturnType(ast.newPrimitiveType(PrimitiveType.VOID));
} else {
decl.setReturnType(returnType);
}
if (!fSenderBinding.isInterface() && returnType != null) {
ReturnStatement returnStatement= ast.newReturnStatement();
returnStatement.setExpression(ASTNodeFactory.newDefaultExpression(ast, returnType, 0));
bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, String.valueOf('\n'));
}
}
if (!fSenderBinding.isInterface()) {
body= ast.newBlock();
String placeHolder= CodeGeneration.getMethodBodyContent(getCompilationUnit(), fSenderBinding.getName(), getMethodName(), isConstructor(), bodyStatement, String.valueOf('\n'));
if (placeHolder != null) {
ASTNode todoNode= rewrite.createPlaceholder(placeHolder, ASTRewrite.STATEMENT);
body.statements().add(todoNode);
}
}
decl.setBody(body);
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
if (settings.createComments && !fSenderBinding.isAnonymous()) {
String string= CodeGeneration.getMethodComment(getCompilationUnit(), fSenderBinding.getName(), decl, null, String.valueOf('\n'));
if (string != null) {
Javadoc javadoc= (Javadoc) rewrite.createPlaceholder(string, ASTRewrite.JAVADOC);
decl.setJavadoc(javadoc);
}
}
return decl;
}
private String getParameterName(ArrayList takenNames, Expression argNode, Type type) {
IJavaProject project= getCompilationUnit().getJavaProject();
String[] excludedNames= (String[]) takenNames.toArray(new String[takenNames.size()]);
if (argNode instanceof SimpleName) {
SimpleName name= (SimpleName) argNode;
String suggestion= StubUtility.guessArgumentName(project, name.getIdentifier(), excludedNames);
takenNames.add(suggestion);
return suggestion;
}
int dim= 0;
if (type.isArrayType()) {
ArrayType arrayType= (ArrayType) type;
dim= arrayType.getDimensions();
type= arrayType.getElementType();
}
String typeName= ASTNodes.asString(type);
String packName= Signature.getQualifier(typeName);
String[] names= NamingConventions.suggestArgumentNames(project, packName, typeName, dim, excludedNames);
takenNames.add(names[0]);
return names[0];
}
private int findMethodInsertIndex(List decls, int currPos) {
int nDecls= decls.size();
for (int i= 0; i < nDecls; i++) {
ASTNode curr= (ASTNode) decls.get(i);
if (curr instanceof MethodDeclaration && currPos < curr.getStartPosition() + curr.getLength()) {
return i + 1;
}
}
return nDecls;
}
private int findConstructorInsertIndex(List decls) {
int nDecls= decls.size();
int lastMethod= 0;
for (int i= nDecls - 1; i >= 0; i--) {
ASTNode curr= (ASTNode) decls.get(i);
if (curr instanceof MethodDeclaration) {
if (((MethodDeclaration) curr).isConstructor()) {
return i + 1;
}
lastMethod= i;
}
}
return lastMethod;
}
private String getMethodName() {
if (fNode instanceof MethodInvocation) {
return ((MethodInvocation)fNode).getName().getIdentifier();
} else if (fNode instanceof SuperMethodInvocation) {
return ((SuperMethodInvocation)fNode).getName().getIdentifier();
} else {
return fSenderBinding.getName(); // name of the class
}
}
private int evaluateModifiers(ASTNode targetTypeDecl) {
if (fSenderBinding.isInterface()) {
// for interface members copy the modifiers from an existing field
MethodDeclaration[] methodDecls= ((TypeDeclaration) targetTypeDecl).getMethods();
if (methodDecls.length > 0) {
return methodDecls[0].getModifiers();
}
return 0;
}
if (fNode instanceof MethodInvocation) {
int modifiers= 0;
Expression expression= ((MethodInvocation)fNode).getExpression();
if (expression != null) {
if (expression instanceof Name && ((Name) expression).resolveBinding().getKind() == IBinding.TYPE) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(fNode)) {
modifiers |= Modifier.STATIC;
}
ASTNode node= ASTResolving.findParentType(fNode);
if (targetTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration) {
modifiers |= Modifier.PROTECTED;
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
return Modifier.PUBLIC;
}
private Type evaluateMethodType(AST ast) throws CoreException {
ITypeBinding binding= ASTResolving.guessBindingForReference(fNode);
if (binding != null) {
String typeName= addImport(binding);
return ASTNodeFactory.newType(ast, typeName);
}
return null;
}
private Type getParameterType(AST ast, Expression elem) throws CoreException {
ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
if (binding != null) {
String typeName= addImport(binding);
return ASTNodeFactory.newType(ast, typeName);
}
return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
}
|
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
org.eclipse.jdt.ui/ui
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeParametersControl.java
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
org.eclipse.jdt.ui/ui
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeSignatureWizard.java
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
org.eclipse.jdt.ui/ui
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/PullUpWizard.java
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
org.eclipse.jdt.ui/ui
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/PushDownWizard.java
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
org.eclipse.jdt.ui/ui
| |
39,423 |
Bug 39423 The members list in push down menu does not fill the requester [refactoring]
|
It only fills the requester horisontally when the requester is resized. yvind
|
resolved fixed
|
179ca06
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:15:16Z | 2003-06-27T13:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/code/ExtractMethodInputPage.java
| |
38,635 |
Bug 38635 Refactor / Rename Package doesn't allow rename to same name with different case [refactoring]
|
When using Refactor/Rename on a package in Ecipse 2.1.0, I try to rename package OtherPackage to "otherpackage" but it will not let me, giving the error message, "A resource exists with a different case". I can get around it by naming the package "otherXXXpackage", and *then* to "otherpackage", but hey.
|
verified fixed
|
fd2e195
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:19:00Z | 2003-06-08T16:33:20Z |
org.eclipse.jdt.ui/core
| |
38,635 |
Bug 38635 Refactor / Rename Package doesn't allow rename to same name with different case [refactoring]
|
When using Refactor/Rename on a package in Ecipse 2.1.0, I try to rename package OtherPackage to "otherpackage" but it will not let me, giving the error message, "A resource exists with a different case". I can get around it by naming the package "otherXXXpackage", and *then* to "otherpackage", but hey.
|
verified fixed
|
fd2e195
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T16:19:00Z | 2003-06-08T16:33:20Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamePackageRefactoring.java
| |
38,181 |
Bug 38181 Empty dialog after use supertype where possible [refactoring]
|
1) execute a "use supertype where possible" refactoring in a case where no supertypes can be used. ->end up with an empty dialog with no indication that no super types can be used. We should show the user that no supertype could be used in the dialog.
|
resolved fixed
|
efb37ff
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T17:10:55Z | 2003-05-28T08:20:00Z |
org.eclipse.jdt.ui/ui
| |
38,181 |
Bug 38181 Empty dialog after use supertype where possible [refactoring]
|
1) execute a "use supertype where possible" refactoring in a case where no supertypes can be used. ->end up with an empty dialog with no indication that no super types can be used. We should show the user that no supertype could be used in the dialog.
|
resolved fixed
|
efb37ff
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-06-30T17:10:55Z | 2003-05-28T08:20:00Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/UseSupertypeWizard.java
| |
39,414 |
Bug 39414 Pull up could add import statements as necessary [refactoring]
|
When pulling up a method, the necessary import statements might not be present. Pull up could figure out which import statements to add.
|
resolved fixed
|
1e9f0e3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-02T11:28:21Z | 2003-06-27T10:33:20Z |
org.eclipse.jdt.ui/core
| |
39,414 |
Bug 39414 Pull up could add import statements as necessary [refactoring]
|
When pulling up a method, the necessary import statements might not be present. Pull up could figure out which import statements to add.
|
resolved fixed
|
1e9f0e3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-02T11:28:21Z | 2003-06-27T10:33:20Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoring.java
| |
39,414 |
Bug 39414 Pull up could add import statements as necessary [refactoring]
|
When pulling up a method, the necessary import statements might not be present. Pull up could figure out which import statements to add.
|
resolved fixed
|
1e9f0e3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-02T11:28:21Z | 2003-06-27T10:33:20Z |
org.eclipse.jdt.ui/core
| |
39,414 |
Bug 39414 Pull up could add import statements as necessary [refactoring]
|
When pulling up a method, the necessary import statements might not be present. Pull up could figure out which import statements to add.
|
resolved fixed
|
1e9f0e3
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-02T11:28:21Z | 2003-06-27T10:33:20Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoring.java
| |
38,955 |
Bug 38955 old junit launches not killed after run finished [JUnit]
|
20030611 on windows old junit launches are killed (good) on linux gtk they live and clutter my workbench (bug)
|
verified fixed
|
ae7c206
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-04T20:52:21Z | 2003-06-16T16:13:20Z |
org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Sebastian Davids: [email protected] bug 26754
*******************************************************************************/
package org.eclipse.jdt.internal.junit.runner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Socket;
import java.util.Vector;
import junit.extensions.TestDecorator;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestFailure;
import junit.framework.TestListener;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
/**
* A TestRunner that reports results via a socket connection.
* See MessageIds for more information about the protocl.
*/
public class RemoteTestRunner implements TestListener {
/**
* Holder for information for a rerun request
*/
private static class RerunRequest {
String fClassName;
String fTestName;
int fTestId;
public RerunRequest(int testId, String className, String testName) {
fTestId= testId;
fClassName= className;
fTestName= testName;
}
}
private static final String SUITE_METHODNAME= "suite"; //$NON-NLS-1$
/**
* The name of the test classes to be executed
*/
private String[] fTestClassNames;
/**
* The name of the test (argument -test)
*/
private String fTestName;
/**
* The current test result
*/
private TestResult fTestResult;
/**
* The client socket.
*/
private Socket fClientSocket;
/**
* Print writer for sending messages
*/
private PrintWriter fWriter;
/**
* Reader for incoming messages
*/
private BufferedReader fReader;
/**
* Host to connect to, default is the localhost
*/
private String fHost= ""; //$NON-NLS-1$
/**
* Port to connect to.
*/
private int fPort= -1;
/**
* Is the debug mode enabled?
*/
private boolean fDebugMode= false;
/**
* Keep the test run server alive after a test run has finished.
* This allows to rerun tests.
*/
private boolean fKeepAlive= false;
/**
* Has the server been stopped
*/
private boolean fStopped= false;
/**
* Queue of rerun requests.
*/
private Vector fRerunRequests= new Vector(10);
/**
* Reader thread that processes messages from the client.
*/
private class ReaderThread extends Thread {
public ReaderThread() {
super("ReaderThread"); //$NON-NLS-1$
}
public void run(){
try {
String message= null;
while (true) {
if ((message= fReader.readLine()) != null) {
if (message.startsWith(MessageIds.TEST_STOP)){
fStopped= true;
RemoteTestRunner.this.stop();
synchronized(RemoteTestRunner.this) {
RemoteTestRunner.this.notifyAll();
}
break;
}
else if (message.startsWith(MessageIds.TEST_RERUN)) {
String arg= message.substring(MessageIds.MSG_HEADER_LENGTH);
//format: testId className testName
int c0= arg.indexOf(' '); //$NON-NLS-1$
int c1= arg.indexOf(' ', c0+1);
String s= arg.substring(0, c0);
int testId= Integer.parseInt(s);
String className= arg.substring(c0+1, c1);
String testName= arg.substring(c1+1, arg.length());
synchronized(RemoteTestRunner.this) {
fRerunRequests.add(new RerunRequest(testId, className, testName));
RemoteTestRunner.this.notifyAll();
}
}
}
}
} catch (Exception e) {
RemoteTestRunner.this.stop();
}
}
}
/**
* The main entry point.
* Parameters<pre>
* -classnames: the name of the test suite class
* -testfilename: the name of a file containing classnames of test suites
* -test: the test method name (format classname testname)
* -host: the host to connect to default local host
* -port: the port to connect to, mandatory argument
* -keepalive: keep the process alive after a test run
* </pre>
*/
public static void main(String[] args) {
RemoteTestRunner testRunServer= new RemoteTestRunner();
testRunServer.init(args);
testRunServer.run();
// fix for 14434
System.exit(0);
}
/**
* Parse command line arguments. Hook for subclasses to process
* additional arguments.
*/
protected void init(String[] args) {
defaultInit(args);
}
/**
* The class loader to be used for loading tests.
* Subclasses may override to use another class loader.
*/
protected ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
/**
* Process the default arguments.
*/
protected final void defaultInit(String[] args) {
for(int i= 0; i < args.length; i++) {
if(args[i].toLowerCase().equals("-classnames") || args[i].toLowerCase().equals("-classname")){ //$NON-NLS-1$ //$NON-NLS-2$
Vector list= new Vector();
for (int j= i+1; j < args.length; j++) {
if (args[j].startsWith("-")) //$NON-NLS-1$
break;
list.add(args[j]);
}
fTestClassNames= (String[]) list.toArray(new String[list.size()]);
}
else if(args[i].toLowerCase().equals("-test")) { //$NON-NLS-1$
String testName= args[i+1];
int p= testName.indexOf(':');
if (p == -1)
throw new IllegalArgumentException("Testname not separated by \'%\'"); //$NON-NLS-1$
fTestName= testName.substring(p+1);
fTestClassNames= new String[]{ testName.substring(0, p) };
i++;
}
else if(args[i].toLowerCase().equals("-testnamefile")) { //$NON-NLS-1$
String testNameFile= args[i+1];
try {
readTestNames(testNameFile);
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read testname file."); //$NON-NLS-1$
}
i++;
} else if(args[i].toLowerCase().equals("-port")) { //$NON-NLS-1$
fPort= Integer.parseInt(args[i+1]);
i++;
}
else if(args[i].toLowerCase().equals("-host")) { //$NON-NLS-1$
fHost= args[i+1];
i++;
}
else if(args[i].toLowerCase().equals("-keepalive")) { //$NON-NLS-1$
fKeepAlive= true;
}
else if(args[i].toLowerCase().equals("-debugging") || args[i].toLowerCase().equals("-debug")){ //$NON-NLS-1$ //$NON-NLS-2$
fDebugMode= true;
}
}
if(fTestClassNames == null || fTestClassNames.length == 0)
throw new IllegalArgumentException(JUnitMessages.getString("RemoteTestRunner.error.classnamemissing")); //$NON-NLS-1$
if (fPort == -1)
throw new IllegalArgumentException(JUnitMessages.getString("RemoteTestRunner.error.portmissing")); //$NON-NLS-1$
if (fDebugMode)
System.out.println("keepalive "+fKeepAlive); //$NON-NLS-1$
}
private void readTestNames(String testNameFile) throws IOException {
BufferedReader br= new BufferedReader(new FileReader(new File(testNameFile)));
try {
String line;
Vector list= new Vector();
while ((line= br.readLine()) != null) {
list.add(line);
}
fTestClassNames= (String[]) list.toArray(new String[list.size()]);
}
finally {
br.close();
}
if (fDebugMode) {
System.out.println("Tests:"); //$NON-NLS-1$
for (int i= 0; i < fTestClassNames.length; i++) {
System.out.println(" "+fTestClassNames[i]); //$NON-NLS-1$
}
}
}
/**
* Connects to the remote ports and runs the tests.
*/
protected void run() {
if (!connect()) {
return;
}
fTestResult= new TestResult();
fTestResult.addListener(this);
runTests(fTestClassNames, fTestName);
fTestResult.removeListener(this);
if (fTestResult != null) {
fTestResult.stop();
fTestResult= null;
}
if (fKeepAlive)
waitForReruns();
shutDown();
}
/**
* Waits for rerun requests until an explicit stop request
*/
private synchronized void waitForReruns() {
while (!fStopped) {
try {
wait();
if (!fStopped && fRerunRequests.size() > 0) {
RerunRequest r= (RerunRequest)fRerunRequests.remove(0);
rerunTest(r.fTestId, r.fClassName, r.fTestName);
}
} catch (InterruptedException e) {
}
}
}
/**
* Returns the Test corresponding to the given suite.
*/
private Test getTest(String suiteClassName, String testName) {
Class testClass= null;
try {
testClass= loadSuiteClass(suiteClassName);
} catch (ClassNotFoundException e) {
String clazz= e.getMessage();
if (clazz == null)
clazz= suiteClassName;
runFailed(JUnitMessages.getFormattedString("RemoteTestRunner.error.classnotfound", clazz)); //$NON-NLS-1$
return null;
} catch(Exception e) {
runFailed(JUnitMessages.getFormattedString("RemoteTestRunner.error.exception", e.toString() )); //$NON-NLS-1$
return null;
}
if (testName != null) {
return createTest(testName, testClass);
}
Method suiteMethod= null;
try {
suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]);
} catch(Exception e) {
// try to extract a test suite automatically
return new TestSuite(testClass);
}
Test test= null;
try {
test= (Test)suiteMethod.invoke(null, new Class[0]); // static method
}
catch (InvocationTargetException e) {
runFailed(JUnitMessages.getFormattedString("RemoteTestRunner.error.invoke", e.getTargetException().toString() )); //$NON-NLS-1$
return null;
}
catch (IllegalAccessException e) {
runFailed(JUnitMessages.getFormattedString("RemoteTestRunner.error.invoke", e.toString() )); //$NON-NLS-1$
return null;
}
return test;
}
protected void runFailed(String message) {
System.err.println(message);
}
/**
* Loads the test suite class.
*/
private Class loadSuiteClass(String className) throws ClassNotFoundException {
if (className == null)
return null;
return getClassLoader().loadClass(className);
}
/**
* Runs a set of tests.
*/
private void runTests(String[] testClassNames, String testName) {
// instantiate all tests
Test[] suites= new Test[testClassNames.length];
for (int i= 0; i < suites.length; i++) {
suites[i]= getTest(testClassNames[i], testName);
}
// count all testMethods and inform ITestRunListeners
int count= countTests(suites);
notifyTestRunStarted(count);
if (count == 0) {
notifyTestRunEnded(0);
return;
}
long startTime= System.currentTimeMillis();
if (fDebugMode)
System.out.print("start send tree..."); //$NON-NLS-1$
for (int i= 0; i < suites.length; i++) {
sendTree(suites[i]);
}
if (fDebugMode)
System.out.println("done send tree - time(ms): "+(System.currentTimeMillis()-startTime)); //$NON-NLS-1$
long testStartTime= System.currentTimeMillis();
for (int i= 0; i < suites.length; i++) {
suites[i].run(fTestResult);
}
// inform ITestRunListeners of test end
if (fTestResult == null || fTestResult.shouldStop())
notifyTestRunStopped(System.currentTimeMillis() - testStartTime);
else
notifyTestRunEnded(System.currentTimeMillis() - testStartTime);
}
private int countTests(Test[] tests) {
int count= 0;
for (int i= 0; i < tests.length; i++) {
if (tests[i] != null)
count= count + tests[i].countTestCases();
}
return count;
}
/**
* Reruns a test as defined by the fully qualified class name and
* the name of the test.
*/
public void rerunTest(int testId, String className, String testName) {
Test reloadedTest= null;
try {
Class reloadedTestClass= getClassLoader().loadClass(className);
reloadedTest= createTest(testName, reloadedTestClass);
} catch(Exception e) {
reloadedTest= warning("Could not create test \'"+testName+"\'"); //$NON-NLS-1$ //$NON-NLS-2$
}
TestResult result= new TestResult();
reloadedTest.run(result);
notifyTestReran(result, Integer.toString(testId), className, testName);
}
/**
* Returns a test which will fail and log a warning message.
*/
private Test warning(final String message) {
return new TestCase("warning") { //$NON-NLS-1$
protected void runTest() {
fail(message);
}
};
}
private Test createTest(String testName, Class testClass) {
Class[] classArgs= { String.class };
Test test;
Constructor constructor= null;
try {
try {
constructor= testClass.getConstructor(classArgs);
test= (Test)constructor.newInstance(new Object[]{testName});
} catch (NoSuchMethodException e) {
// try the no arg constructor supported in 3.8.1
constructor= testClass.getConstructor(new Class[0]);
test= (Test)constructor.newInstance(new Object[0]);
if (test instanceof TestCase)
((TestCase) test).setName(testName);
}
if (test != null)
return test;
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
} catch (ClassCastException e) {
}
return warning("Could not create test \'"+testName+"\' "); //$NON-NLS-1$ //$NON-NLS-2$
}
/*
* @see TestListener#addError(Test, Throwable)
*/
public final void addError(Test test, Throwable throwable) {
notifyTestFailed(test, MessageIds.TEST_ERROR, getTrace(throwable));
}
/*
* @see TestListener#addFailure(Test, AssertionFailedError)
*/
public final void addFailure(Test test, AssertionFailedError assertionFailedError) {
notifyTestFailed(test, MessageIds.TEST_FAILED, getTrace(assertionFailedError));
}
/*
* @see TestListener#endTest(Test)
*/
public void endTest(Test test) {
notifyTestEnded(test);
}
/*
* @see TestListener#startTest(Test)
*/
public void startTest(Test test) {
notifyTestStarted(test);
}
private void sendTree(Test test){
if(test instanceof TestDecorator){
TestDecorator decorator= (TestDecorator) test;
sendTree(decorator.getTest());
}
else if(test instanceof TestSuite){
TestSuite suite= (TestSuite) test;
notifyTestTreeEntry(getTestId(test)+','+escapeComma(suite.toString().trim()) + ',' + true + ',' + suite.testCount());
for(int i=0; i < suite.testCount(); i++){
sendTree(suite.testAt(i));
}
}
else {
notifyTestTreeEntry(getTestId(test)+ ',' + escapeComma(getTestName(test).trim()) + ',' + false + ',' + test.countTestCases());
}
}
private String escapeComma(String s) {
if ((s.indexOf(',') < 0) && (s.indexOf('\\') < 0))
return s;
StringBuffer sb= new StringBuffer(s.length()+10);
for (int i= 0; i < s.length(); i++) {
char c= s.charAt(i);
if (c == ',')
sb.append("\\,"); //$NON-NLS-1$
else if (c == '\\')
sb.append("\\\\"); //$NON-NLS-1$
else
sb.append(c);
}
return sb.toString();
}
private String getTestId(Test test) {
return Integer.toString(System.identityHashCode(test));
}
private String getTestName(Test test) {
return test.toString();
}
/**
* Returns the stack trace for the given throwable.
*/
private String getTrace(Throwable t) {
StringWriter stringWriter= new StringWriter();
PrintWriter writer= new PrintWriter(stringWriter);
t.printStackTrace(writer);
StringBuffer buffer= stringWriter.getBuffer();
return buffer.toString();
}
/**
* Stop the current test run.
*/
protected void stop() {
if (fTestResult != null) {
fTestResult.stop();
}
}
/**
* Connect to the remote test listener.
*/
private boolean connect() {
if (fDebugMode)
System.out.println("RemoteTestRunner: trying to connect" + fHost + ":" + fPort); //$NON-NLS-1$ //$NON-NLS-2$
Exception exception= null;
for (int i= 1; i < 20; i++) {
try{
fClientSocket= new Socket(fHost, fPort);
fWriter= new PrintWriter(fClientSocket.getOutputStream(), false/*true*/);
fReader= new BufferedReader(new InputStreamReader(fClientSocket.getInputStream()));
new ReaderThread().start();
return true;
} catch(IOException e){
exception= e;
}
try {
Thread.sleep(2000);
} catch(InterruptedException e) {
}
}
runFailed(JUnitMessages.getFormattedString("RemoteTestRunner.error.connect", new String[]{fHost, Integer.toString(fPort)} )); //$NON-NLS-1$
exception.printStackTrace();
return false;
}
/**
* Shutsdown the connection to the remote test listener.
*/
private void shutDown() {
if (fWriter != null) {
fWriter.close();
fWriter= null;
}
try {
if (fReader != null) {
fReader.close();
fReader= null;
}
} catch(IOException e) {
if (fDebugMode)
e.printStackTrace();
}
try {
if (fClientSocket != null) {
fClientSocket.close();
fClientSocket= null;
}
} catch(IOException e) {
if (fDebugMode)
e.printStackTrace();
}
}
private void sendMessage(String msg) {
if(fWriter == null)
return;
fWriter.println(msg);
}
private void notifyTestRunStarted(int testCount) {
sendMessage(MessageIds.TEST_RUN_START + testCount + " " + "v2"); //$NON-NLS-1$ //$NON-NLS-2$
}
private void notifyTestRunEnded(long elapsedTime) {
sendMessage(MessageIds.TEST_RUN_END + elapsedTime);
fWriter.flush();
//shutDown();
}
private void notifyTestRunStopped(long elapsedTime) {
sendMessage(MessageIds.TEST_STOPPED + elapsedTime );
fWriter.flush();
//shutDown();
}
private void notifyTestStarted(Test test) {
sendMessage(MessageIds.TEST_START + getTestId(test) + ','+test.toString());
fWriter.flush();
}
private void notifyTestEnded(Test test) {
sendMessage(MessageIds.TEST_END + getTestId(test)+','+getTestName(test));
}
private void notifyTestFailed(Test test, String status, String trace) {
sendMessage(status + getTestId(test) + ',' + getTestName(test));
sendMessage(MessageIds.TRACE_START);
sendMessage(trace);
sendMessage(MessageIds.TRACE_END);
fWriter.flush();
}
private void notifyTestTreeEntry(String treeEntry) {
sendMessage(MessageIds.TEST_TREE + treeEntry);
}
private void notifyTestReran(TestResult result, String testId, String testClass, String testName) {
TestFailure failure= null;
if (result.errorCount() > 0) {
failure= (TestFailure)result.errors().nextElement();
}
if (result.failureCount() > 0) {
failure= (TestFailure)result.failures().nextElement();
}
if (failure != null) {
Throwable t= failure.thrownException();
String trace= getTrace(t);
sendMessage(MessageIds.RTRACE_START);
sendMessage(trace);
sendMessage(MessageIds.RTRACE_END);
fWriter.flush();
}
String status= "OK"; //$NON-NLS-1$
if (result.errorCount() > 0)
status= "ERROR"; //$NON-NLS-1$
else if (result.failureCount() > 0)
status= "FAILURE"; //$NON-NLS-1$
if (fPort != -1) {
sendMessage(MessageIds.TEST_RERAN + testId+ " "+testClass+" "+testName+" "+status); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
fWriter.flush();
}
}
}
|
39,660 |
Bug 39660 JUnit: red/green colors are too bright
|
the colors should be consistent with the icon colors.
|
resolved fixed
|
45f12ca
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-04T21:17:47Z | 2003-07-04T20:20:00Z |
org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitProgressBar.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.junit.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
/**
* A progress bar with a red/green indication for success or failure.
*/
public class JUnitProgressBar extends Canvas {
private static final int DEFAULT_WIDTH = 160;
private static final int DEFAULT_HEIGHT = 18;
private int fCurrentTickCount= 0;
private int fMaxTickCount= 0;
private int fColorBarWidth= 0;
private boolean fError;
public JUnitProgressBar(Composite parent) {
super(parent, SWT.NONE);
addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
fColorBarWidth= scale(fCurrentTickCount);
redraw();
}
});
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
paint(e);
}
});
}
public void setMaximum(int max) {
fMaxTickCount= max;
}
public void reset() {
fError= false;
fCurrentTickCount= 0;
fColorBarWidth= 0;
fMaxTickCount= 0;
redraw();
}
private void paintStep(int startX, int endX) {
GC gc = new GC(this);
setStatusColor(gc);
Rectangle rect= getClientArea();
startX= Math.max(1, startX);
gc.fillRectangle(startX, 1, endX-startX, rect.height-2);
gc.dispose();
}
private void setStatusColor(GC gc) {
if (fError)
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_RED));
else
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));
}
private int scale(int value) {
if (fMaxTickCount > 0) {
Rectangle r= getClientArea();
if (r.width != 0)
return Math.max(0, value*(r.width-2)/fMaxTickCount);
}
return value;
}
private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
gc.setForeground(topleft);
gc.drawLine(x, y, x+w-1, y);
gc.drawLine(x, y, x, y+h-1);
gc.setForeground(bottomright);
gc.drawLine(x+w, y, x+w, y+h);
gc.drawLine(x, y+h, x+w, y+h);
}
private void paint(PaintEvent event) {
GC gc = event.gc;
Display disp= getDisplay();
Rectangle rect= getClientArea();
gc.fillRectangle(rect);
drawBevelRect(gc, rect.x, rect.y, rect.width-1, rect.height-1,
disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
setStatusColor(gc);
fColorBarWidth= Math.min(rect.width-2, fColorBarWidth);
gc.fillRectangle(1, 1, fColorBarWidth, rect.height-2);
}
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget();
Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
if (wHint != SWT.DEFAULT) size.x= wHint;
if (hHint != SWT.DEFAULT) size.y= hHint;
return size;
}
public void step(int failures) {
fCurrentTickCount++;
int x= fColorBarWidth;
fColorBarWidth= scale(fCurrentTickCount);
if (!fError && failures > 0) {
fError= true;
x= 1;
}
if (fCurrentTickCount == fMaxTickCount)
fColorBarWidth= getClientArea().width-1;
paintStep(x, fColorBarWidth);
}
public void refresh(boolean hasErrors) {
fError= hasErrors;
redraw();
}
}
|
39,716 |
Bug 39716 Refactor of nested type broken for default package [refactoring]
|
Problem first noticed in 2.1.1 - it may be in 2.1, never checked. If in the following code, I right click on Baz, Refactor->Convert Nested Type to TopLevel, references (in this _and_ other classes) to "Foo.Baz" end up being refactored to ".Baz" (note the erroneous period). This problem only seems to exists for classes in the default package. public class Foo { public static class Baz { } public Foo() { super(); new Foo.Baz(); } }
|
resolved fixed
|
a342f84
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T13:41:18Z | 2003-07-07T23:20:00Z |
org.eclipse.jdt.ui.tests.refactoring/resources/MoveInnerToTopLevel/test25/in/A.java
| |
39,716 |
Bug 39716 Refactor of nested type broken for default package [refactoring]
|
Problem first noticed in 2.1.1 - it may be in 2.1, never checked. If in the following code, I right click on Baz, Refactor->Convert Nested Type to TopLevel, references (in this _and_ other classes) to "Foo.Baz" end up being refactored to ".Baz" (note the erroneous period). This problem only seems to exists for classes in the default package. public class Foo { public static class Baz { } public Foo() { super(); new Foo.Baz(); } }
|
resolved fixed
|
a342f84
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T13:41:18Z | 2003-07-07T23:20:00Z |
org.eclipse.jdt.ui.tests.refactoring/resources/MoveInnerToTopLevel/test25/out/A.java
| |
39,716 |
Bug 39716 Refactor of nested type broken for default package [refactoring]
|
Problem first noticed in 2.1.1 - it may be in 2.1, never checked. If in the following code, I right click on Baz, Refactor->Convert Nested Type to TopLevel, references (in this _and_ other classes) to "Foo.Baz" end up being refactored to ".Baz" (note the erroneous period). This problem only seems to exists for classes in the default package. public class Foo { public static class Baz { } public Foo() { super(); new Foo.Baz(); } }
|
resolved fixed
|
a342f84
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T13:41:18Z | 2003-07-07T23:20:00Z |
org.eclipse.jdt.ui.tests.refactoring/resources/MoveInnerToTopLevel/test25/out/Inner.java
| |
39,716 |
Bug 39716 Refactor of nested type broken for default package [refactoring]
|
Problem first noticed in 2.1.1 - it may be in 2.1, never checked. If in the following code, I right click on Baz, Refactor->Convert Nested Type to TopLevel, references (in this _and_ other classes) to "Foo.Baz" end up being refactored to ".Baz" (note the erroneous period). This problem only seems to exists for classes in the default package. public class Foo { public static class Baz { } public Foo() { super(); new Foo.Baz(); } }
|
resolved fixed
|
a342f84
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T13:41:18Z | 2003-07-07T23:20:00Z |
org.eclipse.jdt.ui.tests.refactoring/test
| |
39,716 |
Bug 39716 Refactor of nested type broken for default package [refactoring]
|
Problem first noticed in 2.1.1 - it may be in 2.1, never checked. If in the following code, I right click on Baz, Refactor->Convert Nested Type to TopLevel, references (in this _and_ other classes) to "Foo.Baz" end up being refactored to ".Baz" (note the erroneous period). This problem only seems to exists for classes in the default package. public class Foo { public static class Baz { } public Foo() { super(); new Foo.Baz(); } }
|
resolved fixed
|
a342f84
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T13:41:18Z | 2003-07-07T23:20:00Z |
cases/org/eclipse/jdt/ui/tests/refactoring/MoveInnerToTopLevelTests.java
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
org.eclipse.jdt.ui/core
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/xml/ObjectStateExpression.java
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
org.eclipse.jdt.ui/core
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenamePackageProcessor.java
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
org.eclipse.jdt.ui/core
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameResourceProcessor.java
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
org.eclipse.jdt.ui/core
| |
39,738 |
Bug 39738 assertion failed in RenameResourceProcessor after creation of class in default package
|
input for 20030708 org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: assertion failed; at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java:75) at org.eclipse.jdt.internal.corext.Assert$AssertionFailedException.<init> (Assert.java:55) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:136) at org.eclipse.jdt.internal.corext.Assert.isTrue(Assert.java:121) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameResourceProcessor.initi alize(RenameResourceProcessor.java:39) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.create Processor(ExtensionManager.java:152) at org.eclipse.jdt.internal.corext.refactoring.participants.ExtensionManager.getPro cessor(ExtensionManager.java:86) at org.eclipse.jdt.internal.corext.refactoring.participants.RenameExtensionManager. getProcessor(RenameExtensionManager.java:23) at org.eclipse.jdt.internal.corext.refactoring.rename.RenameRefactoring.<init> (RenameRefactoring.java:45) at org.eclipse.jdt.ui.refactoring.RenameSupport.<init> (RenameSupport.java:151) at org.eclipse.jdt.ui.refactoring.RenameSupport.create (RenameSupport.java:202) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.createGe neric(RenameJavaElementAction.java:164) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.canEnabl e(RenameJavaElementAction.java:89) at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.selectio nChanged(RenameJavaElementAction.java:59) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged (SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.RenameAction.selectionChanged (RenameAction.java:82) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run (InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1290) at org.eclipse.jface.viewers.StructuredViewer.handleSelect (StructuredViewer.java:657) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected (StructuredViewer.java:681) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent (OpenStrategy.java:178) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:173) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:61) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:40) at java.lang.reflect.Method.invoke(Method.java:335) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
|
resolved fixed
|
668cdd2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:11:46Z | 2003-07-08T10:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java
| |
39,264 |
Bug 39264 Override method dialog: Selection get's lost when toggling tree/flat mode
|
20030624 1. Open the setter/getter dialog, enable the tree mode 2. select some getters and setters 3. toggle to the flat list: Elements still selected 4. toggle to the tree mode: Tree collapsed (Should remember the old state) 5. Open the tree: No nodes checked, description still stays '2 of 5 selected'
|
resolved fixed
|
c2a67c2
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:52:09Z | 2003-06-24T10:20:00Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OverrideMethodDialog.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.dialogs;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.JavaUIMessages;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.util.ViewerPane;
public class OverrideMethodDialog extends SourceActionDialog {
private class OverrideFlatTreeAction extends Action {
private boolean fToggle;
public OverrideFlatTreeAction() {
super(); //$NON-NLS-1$
setToolTipText(JavaUIMessages.getString("OverrideMethodDialog.groupMethodsByTypes")); //$NON-NLS-1$
JavaPluginImages.setLocalImageDescriptors(this, "impl_co.gif"); //$NON-NLS-1$
fToggle= getOverrideContentProvider().isShowTypes();
setChecked(fToggle);
}
public void run() {
fToggle= !fToggle;
setChecked(fToggle);
getOverrideContentProvider().setShowTypes(fToggle);
}
private OverrideMethodContentProvider getOverrideContentProvider() {
return (OverrideMethodContentProvider) getContentProvider();
}
}
private static class OverrideMethodContentProvider implements ITreeContentProvider {
private final String SETTINGS_SECTION= "OverrideMethodDialog"; //$NON-NLS-1$
private final String SETTINGS_SHOWTYPES= "showtypes"; //$NON-NLS-1$
private Object[] fTypes;
private IMethod[] fMethods;
private final Object[] fEmpty= new Object[0];
private boolean fShowTypes;
private Viewer fViewer;
private IDialogSettings fSettings;
/**
* Constructor for OverrideMethodContentProvider.
*/
public OverrideMethodContentProvider() {
IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
fSettings= dialogSettings.getSection(SETTINGS_SECTION);
if (fSettings == null) {
fSettings= dialogSettings.addNewSection(SETTINGS_SECTION);
fSettings.put(SETTINGS_SHOWTYPES, true);
}
fShowTypes= fSettings.getBoolean(SETTINGS_SHOWTYPES);
}
public void init(IMethod[] methods, IType[] types) {
fMethods= methods;
fTypes= types;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IType) {
ArrayList result= new ArrayList(fMethods.length);
for (int i= 0; i < fMethods.length; i++) {
if (fMethods[i].getDeclaringType().equals(parentElement)) {
result.add(fMethods[i]);
}
}
return result.toArray();
}
return fEmpty;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
if (element instanceof IMethod) {
return ((IMethod)element).getDeclaringType();
}
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fShowTypes ? fTypes : fMethods;
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
fViewer= viewer;
}
public boolean isShowTypes() {
return fShowTypes;
}
public void setShowTypes(boolean showTypes) {
if (fShowTypes != showTypes) {
fShowTypes= showTypes;
fSettings.put(SETTINGS_SHOWTYPES, showTypes);
if (fViewer != null) {
fViewer.refresh();
}
}
}
}
private static class OverrideMethodSorter extends ViewerSorter {
private IType[] fAllTypes;
public OverrideMethodSorter(ITypeHierarchy typeHierarchy) {
IType curr= typeHierarchy.getType();
IType[] superTypes= typeHierarchy.getAllSupertypes(curr);
fAllTypes= new IType[superTypes.length + 1];
fAllTypes[0]= curr;
System.arraycopy(superTypes, 0, fAllTypes, 1, superTypes.length);
}
/*
* @see ViewerSorter#compare(Viewer, Object, Object)
*/
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof IType && e2 instanceof IType) {
if (e1.equals(e2)) {
return 0;
}
for (int i= 0; i < fAllTypes.length; i++) {
IType curr= fAllTypes[i];
if (curr.equals(e1)) {
return -1;
}
if (curr.equals(e2)) {
return 1;
}
}
return 0;
} else {
return super.compare(viewer, e1, e2);
}
}
}
private static class OverrideMethodValidator implements ISelectionStatusValidator {
private static int fNumMethods;
public OverrideMethodValidator(int entries) {
super();
fNumMethods= entries;
}
/*
* @see ISelectionValidator#validate(Object[])
*/
public IStatus validate(Object[] selection) {
int count= 0;
for (int i= 0; i < selection.length; i++) {
if (selection[i] instanceof IMethod) {
count++;
}
}
if (count == 0) {
return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
}
String[] args= { String.valueOf(count), String.valueOf(fNumMethods)};
String message= JavaUIMessages.getFormattedString("OverrideMethodDialog.selectioninfo.more", args); //$NON-NLS-1$
return new StatusInfo(IStatus.INFO, message);
}
}
public OverrideMethodDialog(Shell parent, CompilationUnitEditor editor, IType type, boolean isSubType) throws JavaModelException {
super(parent, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), new OverrideMethodContentProvider(), editor, type);
init(type, isSubType);
}
public boolean hasMethodsToOverride() {
return getContentProvider().getElements(null).length > 0;
}
private void init(IType type, boolean isSubType) throws JavaModelException {
ITypeHierarchy typeHierarchy= type.newSupertypeHierarchy(null);
IMethod[] inheritedMethods= StubUtility.getOverridableMethods(type, typeHierarchy, isSubType);
List toImplement= new ArrayList();
for (int i= 0; i < inheritedMethods.length; i++) {
IMethod curr= inheritedMethods[i];
if (JdtFlags.isAbstract(curr)) {
toImplement.add(curr);
}
}
IMethod[] toImplementArray= (IMethod[]) toImplement.toArray(new IMethod[toImplement.size()]);
setInitialSelections(toImplementArray);
HashSet expanded= new HashSet(toImplementArray.length);
for (int i= 0; i < toImplementArray.length; i++) {
expanded.add(toImplementArray[i].getDeclaringType());
}
HashSet types= new HashSet(inheritedMethods.length);
for (int i= 0; i < inheritedMethods.length; i++) {
types.add(inheritedMethods[i].getDeclaringType());
}
IType[] typesArrays= (IType[]) types.toArray(new IType[types.size()]);
ViewerSorter sorter= new OverrideMethodSorter(typeHierarchy);
if (expanded.isEmpty() && typesArrays.length > 0) {
sorter.sort(null, typesArrays); // sort to get the first one
expanded.add(typesArrays[0]);
}
setExpandedElements(expanded.toArray());
ITreeContentProvider contentProvider= getContentProvider();
((OverrideMethodContentProvider) contentProvider).init(inheritedMethods, typesArrays);
setTitle(JavaUIMessages.getString("OverrideMethodDialog.dialog.title")); //$NON-NLS-1$
setMessage(null);
setValidator(new OverrideMethodValidator(inheritedMethods.length));
setSorter(sorter);
setContainerMode(true);
setSize(60, 18);
setInput(new Object());
}
/*
* @see CheckedTreeSelectionDialog#createTreeViewer(Composite)
*/
protected CheckboxTreeViewer createTreeViewer(Composite composite) {
initializeDialogUnits(composite);
ViewerPane pane= new ViewerPane(composite, SWT.BORDER | SWT.FLAT);
pane.setText(JavaUIMessages.getString("OverrideMethodDialog.dialog.description")); //$NON-NLS-1$
CheckboxTreeViewer treeViewer= super.createTreeViewer(pane);
pane.setContent(treeViewer.getControl());
GridLayout paneLayout= new GridLayout();
paneLayout.marginHeight= 0;
paneLayout.marginWidth= 0;
paneLayout.numColumns= 1;
pane.setLayout(paneLayout);
GridData gd= new GridData(GridData.FILL_BOTH);
gd.widthHint = convertWidthInCharsToPixels(55);
gd.heightHint = convertHeightInCharsToPixels(15);
pane.setLayoutData(gd);
ToolBarManager tbm= pane.getToolBarManager();
tbm.add(new OverrideFlatTreeAction()); // create after tree is created
tbm.update(true);
return treeViewer;
}
/*
* @see org.eclipse.jface.window.Window#configureShell(Shell)
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
WorkbenchHelp.setHelp(newShell, IJavaHelpContextIds.OVERRIDE_TREE_SELECTION_DIALOG);
}
}
|
39,692 |
Bug 39692 Create constructor from fields adds extra ',' when default constructor chosen.
|
public class TestA { TestA() {} TestA(int a, int b, int c) {} TestA(char a, boolean foob, String fooSTringy) {} TestA(double cdDouble, char fFooChar, StringBuffer fBuffer) {} } public class TestB extends TestA { private int fFirstVar; protected char fSecondVar; public String fThirdVar; private StringBuffer fFourthVar; private List fListVar; TestB(int a, char q) { super(1, 2, 3); } } Choose the super() from the default constructor and this is created: public TestB(, char secondVar, StringBuffer fourthVar, List listVar) { super(); // TODO Auto-generated constructor stub fSecondVar= secondVar; fFourthVar= fourthVar; fListVar= listVar; }
|
resolved fixed
|
4053da8
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:53:58Z | 2003-07-07T12:13:20Z |
org.eclipse.jdt.ui/core
| |
39,692 |
Bug 39692 Create constructor from fields adds extra ',' when default constructor chosen.
|
public class TestA { TestA() {} TestA(int a, int b, int c) {} TestA(char a, boolean foob, String fooSTringy) {} TestA(double cdDouble, char fFooChar, StringBuffer fBuffer) {} } public class TestB extends TestA { private int fFirstVar; protected char fSecondVar; public String fThirdVar; private StringBuffer fFourthVar; private List fListVar; TestB(int a, char q) { super(1, 2, 3); } } Choose the super() from the default constructor and this is created: public TestB(, char secondVar, StringBuffer fourthVar, List listVar) { super(); // TODO Auto-generated constructor stub fSecondVar= secondVar; fFourthVar= fourthVar; fListVar= listVar; }
|
resolved fixed
|
4053da8
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T14:53:58Z | 2003-07-07T12:13:20Z |
extension/org/eclipse/jdt/internal/corext/codemanipulation/AddCustomConstructorOperation.java
| |
39,746 |
Bug 39746 Move super class constructor combo up.
|
Move the combo selection for the super class constructors to be above the field treeviewer for the "Create constructor using fields" source action.
|
resolved fixed
|
20de25e
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-08T15:38:05Z | 2003-07-08T10:26:40Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/CreateNewConstructorAction.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.text.IRewriteTarget;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.internal.corext.codemanipulation.AddCustomConstructorOperation;
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings;
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.actions.ActionMessages;
import org.eclipse.jdt.internal.ui.actions.ActionUtil;
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.SourceActionDialog;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.internal.ui.util.ElementValidator;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabels;
public class CreateNewConstructorAction extends SelectionDispatchAction {
private CompilationUnitEditor fEditor;
private static final String fDialogTitle= ActionMessages.getString("CreateNewConstructorAction.error.title"); //$NON-NLS-1$
/**
* Creates a new <code>CreateNewConstructorAction</code>. The action requires
* that the selection provided by the site's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the site providing context information for this action
*/
public CreateNewConstructorAction(IWorkbenchSite site) {
super(site);
setText(ActionMessages.getString("CreateNewConstructorAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("CreateNewConstructorAction.description")); //$NON-NLS-1$
setToolTipText(ActionMessages.getString("CreateNewConstructorAction.tooltip")); //$NON-NLS-1$
WorkbenchHelp.setHelp(this, IJavaHelpContextIds.CREATE_NEW_CONSTRUCTOR_ACTION);
}
/**
* Note: This constructor is for internal use only. Clients should not call this constructor.
*/
public CreateNewConstructorAction(CompilationUnitEditor editor) {
this(editor.getEditorSite());
fEditor= editor;
setEnabled(checkEnabledEditor());
}
//---- Structured Viewer -----------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(IStructuredSelection selection) {
try {
setEnabled(canEnable(selection));
} catch (JavaModelException e) {
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.filterNotPresentException(e))
JavaPlugin.log(e);
setEnabled(false);
}
}
private boolean canEnable(IStructuredSelection selection) throws JavaModelException {
if (getSelectedFields(selection) != null)
return true;
if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType)) {
IType type= (IType) selection.getFirstElement();
return type.getCompilationUnit() != null && type.isClass(); // look if class: not cheap but done by all source generation actions
}
if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
return true;
return false;
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(IStructuredSelection selection) {
try {
IField[] selectedFields= getSelectedFields(selection);
// open an editor and work on a working copy
IEditorPart editor= null;
if (selectedFields != null)
editor= EditorUtility.openInEditor(selectedFields[0]);
else
editor= EditorUtility.openInEditor(getSelectedType(selection).getCompilationUnit());
if (canRunOn(selectedFields)){
run((IType)EditorUtility.getWorkingCopy(selectedFields[0].getDeclaringType()), selectedFields, editor, false);
return;
}
Object firstElement= selection.getFirstElement();
if (firstElement instanceof IType)
run((IType)EditorUtility.getWorkingCopy((IType)firstElement), new IField[0], editor, false);
else if (firstElement instanceof ICompilationUnit) {
IType type= ((ICompilationUnit) firstElement).findPrimaryType();
if (type.isInterface()) {
MessageDialog.openInformation(getShell(), fDialogTitle, ActionMessages.getString("CreateNewConstructorAction.interface_not_applicable")); //$NON-NLS-1$
return;
}
else
run((IType)EditorUtility.getWorkingCopy(((ICompilationUnit) firstElement).findPrimaryType()), new IField[0], editor, false);
}
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), fDialogTitle, ActionMessages.getString("CreateNewConstructorAction.error.actionfailed")); //$NON-NLS-1$
}
}
private IType getSelectedType(IStructuredSelection selection) throws JavaModelException {
Object[] elements= selection.toArray();
if (elements.length == 1 && (elements[0] instanceof IType)) {
IType type= (IType) elements[0];
if (type.getCompilationUnit() != null && type.isClass()) {
return type;
}
}
else if (elements[0] instanceof ICompilationUnit) {
ICompilationUnit cu= (ICompilationUnit) elements[0];
IType type= cu.findPrimaryType();
if (!type.isInterface())
return type;
}
return null;
}
private static boolean canRunOn(IField[] fields) throws JavaModelException {
return fields != null && fields.length > 0;
}
/*
* Returns fields in the selection or <code>null</code> if the selection is
* empty or not valid.
*/
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements= selection.toList();
int nElements= elements.size();
if (nElements > 0) {
IField[] res= new IField[nElements];
ICompilationUnit cu= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (curr instanceof IField) {
IField fld= (IField)curr;
if (i == 0) {
// remember the cu of the first element
cu= fld.getCompilationUnit();
if (cu == null) {
return null;
}
} else if (!cu.equals(fld.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
if (fld.getDeclaringType().isInterface()) {
// no constructors for interfaces
return null;
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
return null;
}
res[i]= fld;
} else {
return null;
}
}
return res;
}
return null;
}
//---- Java Editior --------------------------------------------------------------
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void selectionChanged(ITextSelection selection) {
}
/* (non-Javadoc)
* Method declared on SelectionDispatchAction
*/
public void run(ITextSelection selection) {
try {
IJavaElement[] elements= SelectionConverter.codeResolve(fEditor);
if (elements.length == 1 && (elements[0] instanceof IField)) {
IField field= (IField)elements[0];
run(field.getDeclaringType(), new IField[] {field}, fEditor, false);
return;
}
IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
if (element != null){
IType type= (IType)element.getAncestor(IJavaElement.TYPE);
if (type != null) {
if (type.getFields().length > 0) {
run(type, new IField[0], fEditor, true);
return;
}
}
}
MessageDialog.openInformation(getShell(), fDialogTitle,
ActionMessages.getString("CreateNewConstructorAction.not_applicable")); //$NON-NLS-1$
} catch (CoreException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
}
}
private boolean checkEnabledEditor() {
return fEditor != null && SelectionConverter.canOperateOn(fEditor);
}
//---- Helpers -------------------------------------------------------------------
private void run(IType type, IField[] preselected, IEditorPart editor, boolean activatedFromEditor) throws CoreException {
if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) {
return;
}
if (!ActionUtil.isProcessable(getShell(), type)) {
return;
}
IField[] constructorFields= type.getFields();
ArrayList constructorFieldsList= new ArrayList();
for (int i= 0; i < constructorFields.length; i++) {
constructorFieldsList.add(constructorFields[i]);
}
if (constructorFieldsList.isEmpty()){
MessageDialog.openInformation(getShell(), fDialogTitle, ActionMessages.getString("CreateNewConstructorAction.typeContainsNoFields.message")); //$NON-NLS-1$
return;
}
JavaElementLabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
CreateNewConstructorContentProvider contentProvider = new CreateNewConstructorContentProvider(constructorFieldsList);
CreateNewConstructorSelectionDialog dialog= new CreateNewConstructorSelectionDialog(getShell(), labelProvider, contentProvider, fEditor, type);
dialog.setCommentString(ActionMessages.getString("SourceActionDialog.createConstructorComment")); //$NON-NLS-1$
dialog.setTitle(getDialogTitle());
dialog.setInitialSelections(preselected);
dialog.setContainerMode(true);
dialog.setSize(60, 18);
dialog.setInput(new Object());
dialog.setMessage(ActionMessages.getString("CreateNewConstructorAction.dialog.label")); //$NON-NLS-1$
dialog.setValidator(createValidator(constructorFields.length));
IField[] selected= null;
int dialogResult = dialog.open();
if (dialogResult == Window.OK) {
Object[] checkedElements = dialog.getResult();
if (checkedElements == null)
return;
ArrayList result= new ArrayList(checkedElements.length);
for (int i= 0; i < checkedElements.length; i++) {
Object curr= checkedElements[i];
if (curr instanceof IField) {
result.add(curr);
}
}
selected= (IField[]) result.toArray(new IField[result.size()]);
CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
settings.createComments= dialog.getGenerateComment();
IJavaElement elementPosition= dialog.getElementPosition();
int superIndex= dialog.getSuperIndex();
AddCustomConstructorOperation op= new AddCustomConstructorOperation(type, settings, selected, false, elementPosition, superIndex);
IRewriteTarget target= editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null;
if (target != null) {
target.beginCompoundChange();
}
try {
IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow();
if (context == null) {
context= new BusyIndicatorRunnableContext();
}
context.run(false, true, new WorkbenchRunnableAdapter(op));
IMethod res= op.getCreatedConstructor();
if (res.getCompilationUnit().isWorkingCopy()) {
synchronized(res.getCompilationUnit()) {
res.getCompilationUnit().reconcile();
}
}
EditorUtility.revealInEditor(editor, res);
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), null);
} catch (InterruptedException e) {
// Do nothing. Operation has been canceled by user.
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
}
private static ISelectionStatusValidator createValidator(int entries) {
CreateNewConstructorValidator validator= new CreateNewConstructorValidator(entries);
return validator;
}
private String getDialogTitle() {
return fDialogTitle;
}
private static class CreateNewConstructorContentProvider implements ITreeContentProvider {
private List fFieldsList;
private static final Object[] EMPTY= new Object[0];
public CreateNewConstructorContentProvider(List fieldList) {
fFieldsList= fieldList;
}
/*
* @see ITreeContentProvider#getChildren(Object)
*/
public Object[] getChildren(Object parentElement) {
return EMPTY;
}
/*
* @see ITreeContentProvider#getParent(Object)
*/
public Object getParent(Object element) {
return null;
}
/*
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
return getChildren(element).length > 0;
}
/*
* @see IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object inputElement) {
return fFieldsList.toArray();
}
/*
* @see IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
private List moveUp(List elements, List move) {
int nElements= elements.size();
List res= new ArrayList(nElements);
Object floating= null;
for (int i= 0; i < nElements; i++) {
Object curr= elements.get(i);
if (move.contains(curr)) {
res.add(curr);
} else {
if (floating != null) {
res.add(floating);
}
floating= curr;
}
}
if (floating != null) {
res.add(floating);
}
return res;
}
private List reverse(List p) {
List reverse= new ArrayList(p.size());
for (int i= p.size() - 1; i >= 0; i--) {
reverse.add(p.get(i));
}
return reverse;
}
public void setElements(List elements, CheckboxTreeViewer tree) {
fFieldsList= new ArrayList(elements);
if (tree != null)
tree.refresh();
}
public void up(List checkedElements, CheckboxTreeViewer tree) {
if (checkedElements.size() > 0) {
setElements(moveUp(fFieldsList, checkedElements), tree);
tree.reveal(checkedElements.get(0));
}
}
public void down(List checkedElements, CheckboxTreeViewer tree) {
if (checkedElements.size() > 0) {
setElements(reverse(moveUp(reverse(fFieldsList), checkedElements)), tree);
tree.reveal(checkedElements.get(checkedElements.size() - 1));
}
}
}
private static class CreateNewConstructorValidator implements ISelectionStatusValidator {
private static int fEntries;
CreateNewConstructorValidator(int entries) {
super();
fEntries= entries;
}
public IStatus validate(Object[] selection) {
int count= countSelectedFields(selection);
String message= ActionMessages.getFormattedString("CreateNewConstructorAction.fields_selected", //$NON-NLS-1$
new Object[] { String.valueOf(count), String.valueOf(fEntries)} );
return new StatusInfo(IStatus.INFO, message);
}
private int countSelectedFields(Object[] selection){
int count= 0;
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof IField)
count++;
}
return count;
}
}
private static class CreateNewConstructorSelectionDialog extends SourceActionDialog {
private CreateNewConstructorContentProvider fContentProvider;
private IType fType;
private int fSuperIndex;
private static final int UP_BUTTON= IDialogConstants.CLIENT_ID + 1;
private static final int DOWN_BUTTON= IDialogConstants.CLIENT_ID + 2;
public CreateNewConstructorSelectionDialog(Shell parent, ILabelProvider labelProvider, CreateNewConstructorContentProvider contentProvider, CompilationUnitEditor editor, IType type) {
super(parent, labelProvider, contentProvider, editor, type);
fContentProvider= contentProvider;
fType= type;
}
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite= super.createSelectionButtons(composite);
GridLayout layout = new GridLayout();
buttonComposite.setLayout(layout);
createUpDownButtons(buttonComposite);
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 1;
return buttonComposite;
}
protected void createUpDownButtons(Composite buttonComposite) {
createButton(buttonComposite, UP_BUTTON, ActionMessages.getString("CreateNewConstructorSelectionDialog.up_button"), false); //$NON-NLS-1$
createButton(buttonComposite, DOWN_BUTTON, ActionMessages.getString("CreateNewConstructorSelectionDialog.down_button"), false); //$NON-NLS-1$
}
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
switch(buttonId) {
case UP_BUTTON: {
fContentProvider.up(getElementList(), getTreeViewer());
updateOKStatus();
break;
}
case DOWN_BUTTON: {
fContentProvider.down(getElementList(), getTreeViewer());
updateOKStatus();
break;
}
}
}
private List getElementList() {
IStructuredSelection selection= (IStructuredSelection) getTreeViewer().getSelection();
List elements= selection.toList();
ArrayList elementList= new ArrayList();
for (int i= 0; i < elements.size(); i++) {
elementList.add(elements.get(i));
}
return elementList;
}
protected Composite createEntryPtCombo(Composite composite) {
Composite entryComposite= super.createEntryPtCombo(composite);
addSuperClassConstructorChoices(entryComposite);
return entryComposite;
}
private Composite addSuperClassConstructorChoices(Composite composite) {
try {
Label label= new Label(composite, SWT.NONE);
label.setText(ActionMessages.getString("CreateNewConstructorSelectionDialog.sort_constructor_choices.label")); //$NON-NLS-1$
GridData gd= new GridData(GridData.FILL_BOTH);
label.setLayoutData(gd);
final Combo combo= new Combo(composite, SWT.READ_ONLY);
IMethod[] constructorMethods= StubUtility.getOverridableConstructors(fType);
for (int i= 0; i < constructorMethods.length; i++) {
combo.add(JavaElementLabels.getElementLabel(constructorMethods[i], JavaElementLabels.M_PARAMETER_TYPES));
}
// TODO: Can we be a little more intelligent about guessing the super() ?
combo.setText(combo.getItem(0));
combo.setLayoutData(new GridData(GridData.FILL_BOTH));
combo.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
fSuperIndex= combo.getSelectionIndex();
}
});
} catch (CoreException e) {
}
return composite;
}
public int getSuperIndex() {
return fSuperIndex;
}
}
}
|
39,720 |
Bug 39720 Adding external jar to the Build Path of an existing Java project [build path]
|
When adding an external jar file to an existing Java project, the "Setting Build Path" error dialog is displayed. The dialog displays the text "An error occured while setting the build path. Reason: /usr does not exist". The jar to be added in this case is located in the /usr/local/bin/ directory. I am working with the release 2.1 build for linux.
|
verified fixed
|
0c8a280
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T08:43:25Z | 2003-07-07T23:20:00Z |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.wizards.buildpaths;
import java.net.URL;
import java.util.ArrayList;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaUI;
public class CPListElement {
public static final String SOURCEATTACHMENT= "sourcepath"; //$NON-NLS-1$
public static final String SOURCEATTACHMENTROOT= "rootpath"; //$NON-NLS-1$
public static final String JAVADOC= "javadoc"; //$NON-NLS-1$
public static final String OUTPUT= "output"; //$NON-NLS-1$
public static final String EXCLUSION= "exclusion"; //$NON-NLS-1$
private IJavaProject fProject;
private int fEntryKind;
private IPath fPath;
private IResource fResource;
private boolean fIsExported;
private boolean fIsMissing;
private CPListElement fParentContainer;
private IClasspathEntry fCachedEntry;
private ArrayList fChildren;
public CPListElement(IJavaProject project, int entryKind, IPath path, IResource res) {
fProject= project;
fEntryKind= entryKind;
fPath= path;
fChildren= new ArrayList();
fResource= res;
fIsExported= false;
fIsMissing= false;
fCachedEntry= null;
fParentContainer= null;
switch (entryKind) {
case IClasspathEntry.CPE_SOURCE:
createAttributeElement(OUTPUT, null);
createAttributeElement(EXCLUSION, new Path[0]);
break;
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
createAttributeElement(SOURCEATTACHMENT, null);
createAttributeElement(JAVADOC, null);
break;
case IClasspathEntry.CPE_PROJECT:
break;
case IClasspathEntry.CPE_CONTAINER:
try {
IClasspathContainer container= JavaCore.getClasspathContainer(fPath, fProject);
if (container != null) {
IClasspathEntry[] entries= container.getClasspathEntries();
for (int i= 0; i < entries.length; i++) {
CPListElement curr= createFromExisting(entries[i], fProject);
curr.setParentContainer(this);
fChildren.add(curr);
}
}
} catch (JavaModelException e) {
}
break;
default:
}
}
public IClasspathEntry getClasspathEntry() {
if (fCachedEntry == null) {
fCachedEntry= newClasspathEntry();
}
return fCachedEntry;
}
private IClasspathEntry newClasspathEntry() {
switch (fEntryKind) {
case IClasspathEntry.CPE_SOURCE:
IPath outputLocation= (IPath) getAttribute(OUTPUT);
IPath[] exclusionPattern= (IPath[]) getAttribute(EXCLUSION);
return JavaCore.newSourceEntry(fPath, exclusionPattern, outputLocation);
case IClasspathEntry.CPE_LIBRARY:
IPath attach= (IPath) getAttribute(SOURCEATTACHMENT);
return JavaCore.newLibraryEntry(fPath, attach, null, isExported());
case IClasspathEntry.CPE_PROJECT:
return JavaCore.newProjectEntry(fPath, isExported());
case IClasspathEntry.CPE_CONTAINER:
return JavaCore.newContainerEntry(fPath, isExported());
case IClasspathEntry.CPE_VARIABLE:
IPath varAttach= (IPath) getAttribute(SOURCEATTACHMENT);
return JavaCore.newVariableEntry(fPath, varAttach, null, isExported());
default:
return null;
}
}
/**
* Gets the classpath entry path.
* @see IClasspathEntry#getPath()
*/
public IPath getPath() {
return fPath;
}
/**
* Gets the classpath entry kind.
* @see IClasspathEntry#getEntryKind()
*/
public int getEntryKind() {
return fEntryKind;
}
/**
* Entries without resource are either non existing or a variable entry
* External jars do not have a resource
*/
public IResource getResource() {
return fResource;
}
public CPListElementAttribute setAttribute(String key, Object value) {
CPListElementAttribute attribute= findAttributeElement(key);
if (attribute == null) {
return null;
}
attribute.setValue(value);
attributeChanged(key);
return attribute;
}
private CPListElementAttribute findAttributeElement(String key) {
for (int i= 0; i < fChildren.size(); i++) {
Object curr= fChildren.get(i);
if (curr instanceof CPListElementAttribute) {
CPListElementAttribute elem= (CPListElementAttribute) curr;
if (key.equals(elem.getKey())) {
return elem;
}
}
}
return null;
}
public Object getAttribute(String key) {
CPListElementAttribute attrib= findAttributeElement(key);
if (attrib != null) {
return attrib.getValue();
}
return null;
}
private void createAttributeElement(String key, Object value) {
fChildren.add(new CPListElementAttribute(this, key, value));
}
public Object[] getChildren(boolean hideOutputFolder) {
if (hideOutputFolder && fEntryKind == IClasspathEntry.CPE_SOURCE) {
return new Object[] { findAttributeElement(EXCLUSION) };
}
return fChildren.toArray();
}
private void setParentContainer(CPListElement element) {
fParentContainer= element;
}
public CPListElement getParentContainer() {
return fParentContainer;
}
private void attributeChanged(String key) {
fCachedEntry= null;
}
/*
* @see Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {
if (other != null && other.getClass().equals(getClass())) {
CPListElement elem= (CPListElement)other;
return elem.fEntryKind == fEntryKind && elem.fPath.equals(fPath);
}
return false;
}
/*
* @see Object#hashCode()
*/
public int hashCode() {
return fPath.hashCode() + fEntryKind;
}
/**
* Returns if a entry is missing.
* @return Returns a boolean
*/
public boolean isMissing() {
return fIsMissing;
}
/**
* Sets the 'missing' state of the entry.
*/
public void setIsMissing(boolean isMissing) {
fIsMissing= isMissing;
}
/**
* Returns if a entry is exported (only applies to libraries)
* @return Returns a boolean
*/
public boolean isExported() {
return fIsExported;
}
/**
* Sets the export state of the entry.
*/
public void setExported(boolean isExported) {
if (isExported != fIsExported) {
fIsExported = isExported;
attributeChanged(null);
}
}
/**
* Gets the project.
* @return Returns a IJavaProject
*/
public IJavaProject getJavaProject() {
return fProject;
}
public static CPListElement createFromExisting(IClasspathEntry curr, IJavaProject project) {
IPath path= curr.getPath();
IWorkspaceRoot root= project.getProject().getWorkspace().getRoot();
// get the resource
IResource res= null;
boolean isMissing= false;
URL javaDocLocation= null;
switch (curr.getEntryKind()) {
case IClasspathEntry.CPE_CONTAINER:
res= null;
try {
isMissing= (JavaCore.getClasspathContainer(path, project) == null);
} catch (JavaModelException e) {
isMissing= true;
}
break;
case IClasspathEntry.CPE_VARIABLE:
IPath resolvedPath= JavaCore.getResolvedVariablePath(path);
res= null;
isMissing= root.findMember(resolvedPath) == null && !resolvedPath.toFile().isFile();
javaDocLocation= JavaUI.getLibraryJavadocLocation(resolvedPath);
break;
case IClasspathEntry.CPE_LIBRARY:
res= root.findMember(path);
if (res == null) {
if (!ArchiveFileFilter.isArchivePath(path)) {
if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
res= root.getFolder(path);
}
}
isMissing= !path.toFile().isFile(); // look for external JARs
}
javaDocLocation= JavaUI.getLibraryJavadocLocation(path);
break;
case IClasspathEntry.CPE_SOURCE:
res= root.findMember(path);
if (res == null) {
if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
res= root.getFolder(path);
}
isMissing= true;
}
break;
case IClasspathEntry.CPE_PROJECT:
res= root.findMember(path);
isMissing= (res == null);
break;
}
CPListElement elem= new CPListElement(project, curr.getEntryKind(), path, res);
elem.setExported(curr.isExported());
elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
elem.setAttribute(JAVADOC, javaDocLocation);
elem.setAttribute(OUTPUT, curr.getOutputLocation());
elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
if (project.exists()) {
elem.setIsMissing(isMissing);
}
return elem;
}
}
|
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/core
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/IRefactoringProcessor.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/core
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringStyles.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/core
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RenameProcessor.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/core
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameRefactoring.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/core
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameResourceProcessor.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/ui
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringWizard.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/ui
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameRefactoringAction.java
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
org.eclipse.jdt.ui/ui
| |
39,794 |
Bug 39794 rename method does not ask for saving, misses refs [refactoring]
|
20030703+export from 0709 class A{ void foo(){} } and , in other file class B{ void f(A a){ a.foo(); } } make B.java dirty select the call to a.foo() refactor, rename you're not asked to save files and the reference in B.java is not updated
|
verified fixed
|
82e2950
|
JDT
|
https://github.com/eclipse-jdt/eclipse.jdt.ui
|
eclipse-jdt/eclipse.jdt.ui
|
java
| null | null | null | 2003-07-09T14:37:00Z | 2003-07-09T11:26:40Z |
refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/RenameRefactoringWizard.java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.