mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
d44a0b76f7
commit
99cdc84b19
3 changed files with 37 additions and 49 deletions
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||
|
||||
|
@ -41,8 +41,8 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.NameHelper;
|
|||
|
||||
public class FunctionFactory {
|
||||
|
||||
public static IASTFunctionDefinition createGetterDefinition(String varName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||
|
||||
public static IASTFunctionDefinition createGetterDefinition(String varName,
|
||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||
IASTFunctionDefinition getter = new CPPASTFunctionDefinition();
|
||||
|
||||
getter.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations));
|
||||
|
@ -52,9 +52,7 @@ public class FunctionFactory {
|
|||
getterDeclarator = getterDeclarator.getNestedDeclarator();
|
||||
}
|
||||
getter.setDeclarator((IASTFunctionDeclarator) getterDeclarator);
|
||||
|
||||
getter.setBody(getGetterBody(varName));
|
||||
|
||||
return getter;
|
||||
}
|
||||
|
||||
|
@ -72,7 +70,6 @@ public class FunctionFactory {
|
|||
|
||||
private static IASTDeclarator getGetterDeclarator(String varName,
|
||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||
|
||||
CPPASTName getterName = new CPPASTName();
|
||||
String varPartOfGetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName));
|
||||
getterName.setName("get".concat(varPartOfGetterName).toCharArray()); //$NON-NLS-1$
|
||||
|
@ -89,13 +86,13 @@ public class FunctionFactory {
|
|||
// create a new innermost function declarator basing on the field declarator
|
||||
CPPASTFunctionDeclarator functionDeclarator = new CPPASTFunctionDeclarator();
|
||||
functionDeclarator.setConst(true);
|
||||
if(name != null) {
|
||||
if (name != null) {
|
||||
name.addName(getterName);
|
||||
functionDeclarator.setName(name);
|
||||
}else {
|
||||
} else {
|
||||
functionDeclarator.setName(getterName);
|
||||
}
|
||||
for(IASTPointerOperator pointer : innermost.getPointerOperators()){
|
||||
for (IASTPointerOperator pointer : innermost.getPointerOperators()){
|
||||
functionDeclarator.addPointerOperator(pointer.copy(CopyStyle.withLocations));
|
||||
}
|
||||
|
||||
|
@ -107,18 +104,15 @@ public class FunctionFactory {
|
|||
IASTDeclarator parent = (IASTDeclarator) innermost.getParent();
|
||||
parent.setNestedDeclarator(functionDeclarator);
|
||||
return topDeclarator;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static IASTFunctionDefinition createSetterDefinition(String varName, IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||
|
||||
public static IASTFunctionDefinition createSetterDefinition(String varName,
|
||||
IASTSimpleDeclaration fieldDeclaration, ICPPASTQualifiedName name) {
|
||||
IASTFunctionDefinition setter = new CPPASTFunctionDefinition();
|
||||
|
||||
setter.setDeclSpecifier(getVoidDeclSpec());
|
||||
setter.setDeclarator(getSetterDeclarator(varName, fieldDeclaration, name));
|
||||
setter.setBody(getSetterBody(fieldDeclaration));
|
||||
|
||||
return setter;
|
||||
}
|
||||
|
||||
|
@ -153,15 +147,14 @@ public class FunctionFactory {
|
|||
String varPartOfSetterName = NameHelper.makeFirstCharUpper(NameHelper.trimFieldName(varName));
|
||||
setterName.setName("set".concat(varPartOfSetterName).toCharArray()); //$NON-NLS-1$
|
||||
CPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator();
|
||||
if(name != null) {
|
||||
if (name != null) {
|
||||
name.addName(setterName);
|
||||
declarator.setName(name);
|
||||
}else {
|
||||
} else {
|
||||
declarator.setName(setterName);
|
||||
}
|
||||
CPPASTParameterDeclaration parameterDeclaration = new CPPASTParameterDeclaration();
|
||||
parameterDeclaration
|
||||
.setDeclarator(fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations));
|
||||
parameterDeclaration.setDeclarator(fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations));
|
||||
parameterDeclaration.setDeclSpecifier(fieldDeclaration.getDeclSpecifier().copy(
|
||||
CopyStyle.withLocations));
|
||||
declarator.addParameterDeclaration(parameterDeclaration.copy(CopyStyle.withLocations));
|
||||
|
@ -190,5 +183,4 @@ public class FunctionFactory {
|
|||
setter.addDeclarator(getSetterDeclarator(name, fieldDeclaration, null));
|
||||
return setter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
|||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||
|
||||
public class GetterSetterInsertEditProvider implements Comparable<GetterSetterInsertEditProvider>{
|
||||
public class GetterSetterInsertEditProvider implements Comparable<GetterSetterInsertEditProvider> {
|
||||
public enum Type {
|
||||
getter,
|
||||
setter;
|
||||
|
@ -35,7 +35,6 @@ public class GetterSetterInsertEditProvider implements Comparable<GetterSetterIn
|
|||
public GetterSetterInsertEditProvider(String name, IASTSimpleDeclaration fieldDeclaration, Type type) {
|
||||
switch (type) {
|
||||
case getter:
|
||||
|
||||
this.functionDeclaration = FunctionFactory.createGetterDeclaration(name, fieldDeclaration);
|
||||
break;
|
||||
case setter:
|
||||
|
@ -60,7 +59,7 @@ public class GetterSetterInsertEditProvider implements Comparable<GetterSetterIn
|
|||
public IASTFunctionDefinition getFunctionDefinition(boolean qualifedName) {
|
||||
IASTFunctionDefinition definition = null;
|
||||
ICPPASTQualifiedName qname;
|
||||
if(qualifedName) {
|
||||
if (qualifedName) {
|
||||
qname = getClassname();
|
||||
} else {
|
||||
qname = null;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.utils;
|
||||
|
||||
|
@ -34,10 +34,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
|||
/**
|
||||
* Helper class to find Namespace informations.
|
||||
* @author Mirko Stocker
|
||||
*
|
||||
*/
|
||||
public class NamespaceHelper {
|
||||
|
||||
/**
|
||||
* Returns the qualified name of all namespaces that are defined at the specified file and offset.
|
||||
*
|
||||
|
@ -46,43 +44,42 @@ public class NamespaceHelper {
|
|||
* @return ICPPASTQualifiedName with the names of all namespaces
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static ICPPASTQualifiedName getSurroundingNamespace(final IFile insertFile, final int offset) throws CoreException {
|
||||
|
||||
public static ICPPASTQualifiedName getSurroundingNamespace(final IFile insertFile, final int offset)
|
||||
throws CoreException {
|
||||
final CPPASTQualifiedName qualifiedName = new CPPASTQualifiedName();
|
||||
|
||||
TranslationUnitHelper.loadTranslationUnit(insertFile, false).accept(new CPPASTAllVisitor() {
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier && checkFileNameAndLocation(insertFile, offset, declSpec)) {
|
||||
qualifiedName.addName(createNameWithTemplates(declSpec));
|
||||
}
|
||||
return super.visit(declSpec);
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier && checkFileNameAndLocation(insertFile, offset, declSpec)) {
|
||||
qualifiedName.addName(createNameWithTemplates(declSpec));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||
if (checkFileNameAndLocation(insertFile, offset, namespace)) {
|
||||
qualifiedName.addName((namespace).getName().copy());
|
||||
}
|
||||
|
||||
return super.visit(namespace);
|
||||
return super.visit(declSpec);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||
if (checkFileNameAndLocation(insertFile, offset, namespace)) {
|
||||
qualifiedName.addName((namespace).getName().copy());
|
||||
}
|
||||
|
||||
return super.visit(namespace);
|
||||
}
|
||||
});
|
||||
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
private static boolean checkFileNameAndLocation(final IFile insertFile, final int offset, IASTNode namespace) {
|
||||
boolean fileNameOk = namespace.getFileLocation().getFileName().endsWith(insertFile.getLocation().toOSString());
|
||||
if(!fileNameOk) {
|
||||
if (!fileNameOk) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(IASTNodeLocation nodeLocation : namespace.getNodeLocations()) {
|
||||
for (IASTNodeLocation nodeLocation : namespace.getNodeLocations()) {
|
||||
int nodeOffset = nodeLocation.getNodeOffset();
|
||||
boolean locationOk = offset >= nodeOffset && offset < nodeOffset + nodeLocation.getNodeLength();
|
||||
if(locationOk) {
|
||||
if (locationOk) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -95,11 +92,11 @@ public class NamespaceHelper {
|
|||
parentName = ((ICPPASTCompositeTypeSpecifier) declarationParent).getName().copy(
|
||||
CopyStyle.withLocations);
|
||||
|
||||
if(classHasTemplates(declarationParent)) {
|
||||
if (classHasTemplates(declarationParent)) {
|
||||
CPPASTTemplateId templateId = new CPPASTTemplateId();
|
||||
templateId.setTemplateName(parentName);
|
||||
|
||||
for(ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) declarationParent.getParent().getParent() ).getTemplateParameters()) {
|
||||
for (ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) declarationParent.getParent().getParent() ).getTemplateParameters()) {
|
||||
|
||||
if (templateParameter instanceof CPPASTSimpleTypeTemplateParameter) {
|
||||
CPPASTSimpleTypeTemplateParameter simpleTypeTemplateParameter = (CPPASTSimpleTypeTemplateParameter) templateParameter;
|
||||
|
|
Loading…
Add table
Reference in a new issue