1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 05:45:58 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-01-08 01:18:34 +00:00
parent cd19464169
commit c961b374f4

View file

@ -27,7 +27,6 @@ import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterIns
import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
public class GetterAndSetterContext implements ITreeContentProvider{ public class GetterAndSetterContext implements ITreeContentProvider{
public ArrayList<IASTSimpleDeclaration> existingFields = new ArrayList<IASTSimpleDeclaration>(); public ArrayList<IASTSimpleDeclaration> existingFields = new ArrayList<IASTSimpleDeclaration>();
public ArrayList<IASTFunctionDefinition> existingFunctionDefinitions = new ArrayList<IASTFunctionDefinition>(); public ArrayList<IASTFunctionDefinition> existingFunctionDefinitions = new ArrayList<IASTFunctionDefinition>();
public ArrayList<IASTSimpleDeclaration> existingFunctionDeclarations = new ArrayList<IASTSimpleDeclaration>(); public ArrayList<IASTSimpleDeclaration> existingFunctionDeclarations = new ArrayList<IASTSimpleDeclaration>();
@ -37,16 +36,15 @@ public class GetterAndSetterContext implements ITreeContentProvider{
private boolean implementationInHeader = false; private boolean implementationInHeader = false;
public Object[] getChildren(Object parentElement) { public Object[] getChildren(Object parentElement) {
ArrayList<GetterSetterInsertEditProvider> children = new ArrayList<GetterSetterInsertEditProvider>(); ArrayList<GetterSetterInsertEditProvider> children = new ArrayList<GetterSetterInsertEditProvider>();
if (parentElement instanceof FieldWrapper) { if (parentElement instanceof FieldWrapper) {
FieldWrapper wrapper = (FieldWrapper) parentElement; FieldWrapper wrapper = (FieldWrapper) parentElement;
if(wrapper.getChildNodes().isEmpty()) { if (wrapper.getChildNodes().isEmpty()) {
if(!wrapper.getter.exists()){ if (!wrapper.getter.exists()){
wrapper.childNodes.add(createGetterInserter(wrapper.field)); wrapper.childNodes.add(createGetterInserter(wrapper.field));
} }
if(!wrapper.setter.exists() && !wrapper.field.getDeclSpecifier().isConst()){ if (!wrapper.setter.exists() && !wrapper.field.getDeclSpecifier().isConst()){
wrapper.childNodes.add(createSetterInserter(wrapper.field)); wrapper.childNodes.add(createSetterInserter(wrapper.field));
} }
} }
@ -72,14 +70,12 @@ public class GetterAndSetterContext implements ITreeContentProvider{
public boolean hasChildren(Object element) { public boolean hasChildren(Object element) {
if (element instanceof FieldWrapper) { if (element instanceof FieldWrapper) {
FieldWrapper wrapper = (FieldWrapper) element; FieldWrapper wrapper = (FieldWrapper) element;
return wrapper.missingGetterOrSetter(); return wrapper.missingGetterOrSetter();
} }
return false; return false;
} }
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
return getWrappedFields().toArray(); return getWrappedFields().toArray();
} }
@ -98,14 +94,14 @@ public class GetterAndSetterContext implements ITreeContentProvider{
} }
private ArrayList<FieldWrapper> getWrappedFields() { private ArrayList<FieldWrapper> getWrappedFields() {
if(wrappedFields == null) { if (wrappedFields == null) {
wrappedFields = new ArrayList<FieldWrapper>(); wrappedFields = new ArrayList<FieldWrapper>();
for(IASTSimpleDeclaration currentField : existingFields){ for (IASTSimpleDeclaration currentField : existingFields){
FieldWrapper wrapper = new FieldWrapper(); FieldWrapper wrapper = new FieldWrapper();
wrapper.field = currentField; wrapper.field = currentField;
wrapper.getter = getGetterForField(currentField); wrapper.getter = getGetterForField(currentField);
wrapper.setter = getSetterForField(currentField); wrapper.setter = getSetterForField(currentField);
if(wrapper.missingGetterOrSetter()){ if (wrapper.missingGetterOrSetter()){
wrappedFields.add(wrapper); wrappedFields.add(wrapper);
} }
} }
@ -119,7 +115,6 @@ public class GetterAndSetterContext implements ITreeContentProvider{
String getterName = "get" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$ String getterName = "get" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$
setFunctionToWrapper(wrapper, getterName); setFunctionToWrapper(wrapper, getterName);
return wrapper; return wrapper;
} }
@ -137,18 +132,18 @@ public class GetterAndSetterContext implements ITreeContentProvider{
String setterName = "set" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$ String setterName = "set" + NameHelper.makeFirstCharUpper(trimmedName); //$NON-NLS-1$
setFunctionToWrapper(wrapper, setterName); setFunctionToWrapper(wrapper, setterName);
return wrapper; return wrapper;
} }
private void setFunctionToWrapper(FunctionWrapper wrapper, String getterName) { private void setFunctionToWrapper(FunctionWrapper wrapper, String getterName) {
for(IASTFunctionDefinition currentDefinition : existingFunctionDefinitions){ for (IASTFunctionDefinition currentDefinition : existingFunctionDefinitions){
if(currentDefinition.getDeclarator().getName().toString().endsWith(getterName)){ if (currentDefinition.getDeclarator().getName().toString().endsWith(getterName)){
wrapper.functionDefinition = currentDefinition; wrapper.functionDefinition = currentDefinition;
} }
} }
for(IASTSimpleDeclaration currentDeclaration : existingFunctionDeclarations){ for (IASTSimpleDeclaration currentDeclaration : existingFunctionDeclarations){
if(getFieldDeclarationName(currentDeclaration).toString().endsWith(getterName)){ if (getFieldDeclarationName(currentDeclaration).toString().endsWith(getterName)){
wrapper.functionDeclaration = currentDeclaration; wrapper.functionDeclaration = currentDeclaration;
} }
} }
@ -184,7 +179,6 @@ public class GetterAndSetterContext implements ITreeContentProvider{
protected IASTFunctionDefinition functionDefinition; protected IASTFunctionDefinition functionDefinition;
public boolean exists() { public boolean exists() {
return functionDeclaration != null || functionDefinition != null; return functionDeclaration != null || functionDefinition != null;
} }
} }