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