use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class RenameTypeParameterTest method helper2.
private void helper2(String parameterName, String newParameterName, String typeName, String methodName, String[] methodSignature, boolean references) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType declaringType = getType(cu, typeName);
IMethod[] declaringMethods = getMethods(declaringType, new String[] { methodName }, new String[][] { methodSignature });
ITypeParameter typeParameter = declaringMethods[0].getTypeParameter(parameterName);
RenameTypeParameterProcessor processor = new RenameTypeParameterProcessor(typeParameter);
RenameRefactoring refactoring = new RenameRefactoring(processor);
processor.setNewElementName(newParameterName);
processor.setUpdateReferences(references);
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class RenameTypeParameterTest method helper2.
private void helper2(String parameterName, String newParameterName, String typeName, boolean references) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType declaringType = getType(cu, typeName);
ITypeParameter typeParameter = declaringType.getTypeParameter(parameterName);
RenameTypeParameterProcessor processor = new RenameTypeParameterProcessor(typeParameter);
RenameRefactoring refactoring = new RenameRefactoring(processor);
processor.setNewElementName(newParameterName);
processor.setUpdateReferences(references);
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class JavaElementLinks method resolveTypeVariable.
private static ITypeParameter resolveTypeVariable(IJavaElement baseElement, String typeVariableName) throws JavaModelException {
while (baseElement != null) {
switch(baseElement.getElementType()) {
case IJavaElement.METHOD:
IMethod method = (IMethod) baseElement;
ITypeParameter[] typeParameters = method.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter typeParameter = typeParameters[i];
if (typeParameter.getElementName().equals(typeVariableName)) {
return typeParameter;
}
}
break;
case IJavaElement.TYPE:
IType type = (IType) baseElement;
typeParameters = type.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter typeParameter = typeParameters[i];
if (typeParameter.getElementName().equals(typeVariableName)) {
return typeParameter;
}
}
break;
case IJavaElement.JAVA_MODEL:
case IJavaElement.JAVA_PROJECT:
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.CLASS_FILE:
case IJavaElement.COMPILATION_UNIT:
case IJavaElement.PACKAGE_DECLARATION:
case IJavaElement.IMPORT_CONTAINER:
case IJavaElement.IMPORT_DECLARATION:
return null;
default:
break;
}
// look for type parameters in enclosing members:
baseElement = baseElement.getParent();
}
return null;
}
use of org.eclipse.jdt.core.ITypeParameter in project che by eclipse.
the class LazyGenericTypeProposal method mapTypeParameterIndex.
/**
* For the type parameter at <code>paramIndex</code> in the type at <code>path[pathIndex]</code>
* , this method computes the corresponding type parameter index in the type at
* <code>path[0]</code>. If the type parameter does not map to a type parameter of the super
* type, <code>-1</code> is returned.
*
* @param path the type inheritance path, a non-empty array of consecutive sub types
* @param pathIndex an index into <code>path</code> specifying the type to start with
* @param paramIndex the index of the type parameter to map - <code>path[pathIndex]</code> must
* have a type parameter at that index, lest an
* <code>ArrayIndexOutOfBoundsException</code> is thrown
* @return the index of the type parameter in <code>path[0]</code> corresponding to the type
* parameter at <code>paramIndex</code> in <code>path[pathIndex]</code>, or -1 if there
* is no corresponding type parameter
* @throws org.eclipse.jdt.core.JavaModelException if this element does not exist or if an exception occurs while
* accessing its corresponding resource
* @throws ArrayIndexOutOfBoundsException if <code>path[pathIndex]</code> has <=
* <code>paramIndex</code> parameters
*/
private int mapTypeParameterIndex(IType[] path, int pathIndex, int paramIndex) throws JavaModelException, ArrayIndexOutOfBoundsException {
if (pathIndex == 0)
// break condition: we've reached the top of the hierarchy
return paramIndex;
IType subType = path[pathIndex];
IType superType = path[pathIndex - 1];
String superSignature = findMatchingSuperTypeSignature(subType, superType);
ITypeParameter param = subType.getTypeParameters()[paramIndex];
int index = findMatchingTypeArgumentIndex(superSignature, param.getElementName());
if (index == -1) {
// not mapped through
return -1;
}
return mapTypeParameterIndex(path, pathIndex - 1, index);
}
use of org.eclipse.jdt.core.ITypeParameter in project flux by eclipse.
the class MethodOverrideTester method getMethodSubstitions.
/*
* Returns the substitutions for a method's type parameters
*/
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException {
if (fMethodSubstitutions == null) {
fMethodSubstitutions = new LRUMap<IMethod, Substitutions>(3);
}
Substitutions s = fMethodSubstitutions.get(method);
if (s == null) {
ITypeParameter[] typeParameters = method.getTypeParameters();
if (typeParameters.length == 0) {
s = Substitutions.EMPTY_SUBST;
} else {
IType instantiatedType = method.getDeclaringType();
s = new Substitutions();
for (int i = 0; i < typeParameters.length; i++) {
ITypeParameter curr = typeParameters[i];
s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType));
}
}
fMethodSubstitutions.put(method, s);
}
return s;
}
Aggregations