use of org.eclipse.jdt.core.IMethod 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.IMethod in project xtext-eclipse by eclipse.
the class Bug403554Test method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
final IJavaProject project = this.getJavaProject(null);
IType type = project.findType(ArrayList.class.getName());
IMethod method = type.getMethod("subList", new String[] { "I", "I" });
while ((!method.exists())) {
{
String superclassName = type.getSuperclassName();
final int idx = superclassName.indexOf("<");
if ((idx != (-1))) {
superclassName = superclassName.substring(0, idx);
}
type = project.findType(superclassName);
method = type.getMethod("subList", new String[] { "I", "I" });
}
}
this.declarator = type.getElementName();
}
use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.
the class AbstractXbaseContentAssistTest method addMethods.
protected static void addMethods(IType type, List<String> features, List<String> staticFeatures, Set<String> featuresOrTypes) throws JavaModelException {
if (featuresOrTypes.add(type.getFullyQualifiedName())) {
for (IMethod method : type.getMethods()) {
List<String> list = features;
if (Flags.isStatic(method.getFlags()))
list = staticFeatures;
String methodName = method.getElementName();
if (Flags.isPublic(method.getFlags()) && !method.isConstructor() && !"<clinit>".equals(methodName) && !"<init>".equals(methodName) && !Flags.isSynthetic(method.getFlags())) {
if (method.getParameterTypes().length == 0) {
if (methodName.startsWith("get") && methodName.length() > 3) {
String propertyName = Strings.toFirstLower(methodName.substring(3));
if (featuresOrTypes.add(propertyName + method.getSignature()))
list.add(propertyName);
} else if (methodName.startsWith("is") && methodName.length() > 2) {
String propertyName = Strings.toFirstLower(methodName.substring(2));
if (featuresOrTypes.add(propertyName + method.getSignature()))
list.add(propertyName);
} else {
if (featuresOrTypes.add(methodName + method.getSignature()))
list.add(methodName);
}
} else if (method.getParameterTypes().length == 1) {
if (methodName.startsWith("set") && methodName.length() > 3) {
String propertyName = Strings.toFirstLower(methodName.substring(3)) + " = value";
if (featuresOrTypes.add(propertyName + method.getSignature()))
list.add(propertyName);
} else {
methodName = methodName + "()";
if (featuresOrTypes.add(methodName + method.getSignature()))
list.add(methodName);
}
} else {
methodName = methodName + "()";
if (featuresOrTypes.add(methodName + method.getSignature()))
list.add(methodName);
}
}
}
String superclassName = type.getSuperclassName();
if (superclassName != null) {
int idx = superclassName.indexOf('<');
if (idx != -1) {
superclassName = superclassName.substring(0, idx);
}
IType superType = type.getJavaProject().findType(superclassName);
addMethods(superType, features, staticFeatures, featuresOrTypes);
}
String[] interfaceNames = type.getSuperInterfaceNames();
for (String interfaceName : interfaceNames) {
int idx = interfaceName.indexOf('<');
if (idx != -1) {
interfaceName = interfaceName.substring(0, idx);
}
IType superInterface = type.getJavaProject().findType(interfaceName);
addMethods(superInterface, features, staticFeatures, featuresOrTypes);
}
}
}
use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.
the class JvmRenameRefactoringProvider method createRenameDescriptor.
/**
* Copied from {@link org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode}. There does not seem to be a
* clean way to initialize a JDT refactoring from the outside.
*/
public RenameJavaElementDescriptor createRenameDescriptor(IJavaElement javaElement, String newName) throws JavaModelException {
String contributionId;
// see RefactoringExecutionStarter#createRenameSupport(..):
int elementType = javaElement.getElementType();
switch(elementType) {
case IJavaElement.JAVA_PROJECT:
contributionId = IJavaRefactorings.RENAME_JAVA_PROJECT;
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
contributionId = IJavaRefactorings.RENAME_SOURCE_FOLDER;
break;
case IJavaElement.PACKAGE_FRAGMENT:
contributionId = IJavaRefactorings.RENAME_PACKAGE;
break;
case IJavaElement.COMPILATION_UNIT:
contributionId = IJavaRefactorings.RENAME_COMPILATION_UNIT;
break;
case IJavaElement.TYPE:
contributionId = IJavaRefactorings.RENAME_TYPE;
break;
case IJavaElement.METHOD:
final IMethod method = (IMethod) javaElement;
if (method.isConstructor())
return createRenameDescriptor(method.getDeclaringType(), newName);
else
contributionId = IJavaRefactorings.RENAME_METHOD;
break;
case IJavaElement.FIELD:
IField field = (IField) javaElement;
if (field.isEnumConstant())
contributionId = IJavaRefactorings.RENAME_ENUM_CONSTANT;
else
contributionId = IJavaRefactorings.RENAME_FIELD;
break;
case IJavaElement.TYPE_PARAMETER:
contributionId = IJavaRefactorings.RENAME_TYPE_PARAMETER;
break;
case IJavaElement.LOCAL_VARIABLE:
contributionId = IJavaRefactorings.RENAME_LOCAL_VARIABLE;
break;
default:
return null;
}
RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) RefactoringCore.getRefactoringContribution(contributionId).createDescriptor();
descriptor.setJavaElement(javaElement);
descriptor.setNewName(newName);
if (elementType != IJavaElement.PACKAGE_FRAGMENT_ROOT)
descriptor.setUpdateReferences(true);
IDialogSettings javaSettings = JavaPlugin.getDefault().getDialogSettings();
// TODO: undocumented API
IDialogSettings refactoringSettings = javaSettings.getSection(RefactoringWizardPage.REFACTORING_SETTINGS);
if (refactoringSettings == null) {
refactoringSettings = javaSettings.addNewSection(RefactoringWizardPage.REFACTORING_SETTINGS);
}
switch(elementType) {
case IJavaElement.METHOD:
case IJavaElement.FIELD:
descriptor.setDeprecateDelegate(refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_DEPRECATION));
descriptor.setKeepOriginal(refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_UPDATING));
}
switch(elementType) {
case IJavaElement.TYPE:
// case IJavaElement.COMPILATION_UNIT: // TODO
descriptor.setUpdateSimilarDeclarations(refactoringSettings.getBoolean(RenameRefactoringWizard.TYPE_UPDATE_SIMILAR_ELEMENTS));
int strategy;
try {
strategy = refactoringSettings.getInt(RenameRefactoringWizard.TYPE_SIMILAR_MATCH_STRATEGY);
} catch (NumberFormatException e) {
strategy = RenamingNameSuggestor.STRATEGY_EXACT;
}
descriptor.setMatchStrategy(strategy);
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
descriptor.setUpdateHierarchy(refactoringSettings.getBoolean(RenameRefactoringWizard.PACKAGE_RENAME_SUBPACKAGES));
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.TYPE:
String fileNamePatterns = refactoringSettings.get(RenameRefactoringWizard.QUALIFIED_NAMES_PATTERNS);
if (fileNamePatterns != null && fileNamePatterns.length() != 0) {
descriptor.setFileNamePatterns(fileNamePatterns);
boolean updateQualifiedNames = refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES);
descriptor.setUpdateQualifiedNames(updateQualifiedNames);
// fShowPreview|= updateQualifiedNames;
}
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.TYPE:
case IJavaElement.FIELD:
boolean updateTextualOccurrences = refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES);
descriptor.setUpdateTextualOccurrences(updateTextualOccurrences);
}
switch(elementType) {
case IJavaElement.FIELD:
descriptor.setRenameGetters(refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_GETTER));
descriptor.setRenameSetters(refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_SETTER));
}
return descriptor;
}
use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.
the class DeltaConverter method traverseType.
/**
* We don't include nested types because structural changes of nested types should not affect Xtend classes which
* use top level types.
*
* @deprecated This method is not used anymore.
*/
@Deprecated
protected void traverseType(IType type, NameBasedEObjectDescriptionBuilder acceptor) {
try {
if (type.exists()) {
for (IField field : type.getFields()) {
if (!Flags.isSynthetic(field.getFlags())) {
String fieldName = field.getElementName();
acceptor.accept(fieldName);
}
}
for (IMethod method : type.getMethods()) {
if (!Flags.isSynthetic(method.getFlags())) {
String methodName = method.getElementName();
acceptor.accept(methodName);
}
}
}
} catch (JavaModelException e) {
if (LOGGER.isDebugEnabled())
LOGGER.debug(e, e);
}
}
Aggregations