mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Infinite loop in Implement Method command. Bug 312172.
This commit is contained in:
parent
d91b53a16b
commit
86d0c343f9
2 changed files with 59 additions and 51 deletions
|
@ -16,13 +16,17 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||
|
||||
|
@ -33,8 +37,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
|||
*
|
||||
*/
|
||||
public class NameHelper {
|
||||
|
||||
|
||||
private static final String localVariableRegexp = "[a-z_A-Z]\\w*"; //$NON-NLS-1$
|
||||
|
||||
public static boolean isValidLocalVariableName(String name) {
|
||||
|
@ -94,7 +96,6 @@ public class NameHelper {
|
|||
int start = 0;
|
||||
int end = letters.length - 1;
|
||||
try {
|
||||
|
||||
// Trim, non-letters at the beginning
|
||||
while (!Character.isLetterOrDigit(letters[start]) && start < end) {
|
||||
++start;
|
||||
|
@ -113,8 +114,7 @@ public class NameHelper {
|
|||
}
|
||||
lookAhead++;
|
||||
}
|
||||
} else if (start + 1 <= end
|
||||
&& Character.isUpperCase(letters[start + 1])) {
|
||||
} else if (start + 1 <= end && Character.isUpperCase(letters[start + 1])) {
|
||||
start++;
|
||||
}
|
||||
|
||||
|
@ -122,10 +122,10 @@ public class NameHelper {
|
|||
while ((!Character.isLetter(letters[end]) && !Character.isDigit(letters[end])) && start < end) {
|
||||
--end;
|
||||
}
|
||||
}catch(IndexOutOfBoundsException e){}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
}
|
||||
|
||||
return new String(letters, start, end - start + 1);
|
||||
|
||||
}
|
||||
|
||||
public static String makeFirstCharUpper(String name) {
|
||||
|
@ -136,11 +136,18 @@ public class NameHelper {
|
|||
}
|
||||
|
||||
public static String getTypeName(IASTParameterDeclaration parameter) {
|
||||
IASTDeclSpecifier parameterDeclSpecifier = parameter.getDeclSpecifier();
|
||||
if (parameterDeclSpecifier instanceof ICPPASTNamedTypeSpecifier) {
|
||||
return ((ICPPASTNamedTypeSpecifier) parameterDeclSpecifier).getName().getRawSignature();
|
||||
} else {
|
||||
return parameterDeclSpecifier.getRawSignature();
|
||||
IASTName name = parameter.getDeclarator().getName();
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IVariable) {
|
||||
try {
|
||||
IType type = ((IVariable) binding).getType();
|
||||
if (type != null) {
|
||||
return ASTTypeUtil.getType(type);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ public class PseudoNameGenerator {
|
|||
}
|
||||
|
||||
public String generateNewName(String typeName) {
|
||||
|
||||
String[] nameParts = typeName.split("::"); //$NON-NLS-1$
|
||||
typeName = nameParts[nameParts.length - 1];
|
||||
if (typeName.contains("<")) { //$NON-NLS-1$
|
||||
|
@ -57,12 +56,14 @@ public class PseudoNameGenerator {
|
|||
|
||||
do {
|
||||
newNameCandidate = typeName + numberString;
|
||||
if (!NameHelper.isValidLocalVariableName(newNameCandidate)) {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
index++;
|
||||
numberString = Integer.toString(index);
|
||||
} while(names.contains(newNameCandidate) || !NameHelper.isValidLocalVariableName(newNameCandidate) || NameHelper.isKeyword(newNameCandidate));
|
||||
} while (names.contains(newNameCandidate) || NameHelper.isKeyword(newNameCandidate));
|
||||
|
||||
names.add(newNameCandidate);
|
||||
|
||||
return newNameCandidate;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue