use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class IntroduceFactoryRefactoring method initialize.
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
final String selection = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
if (selection != null) {
int offset = -1;
int length = -1;
final StringTokenizer tokenizer = new StringTokenizer(selection);
if (tokenizer.hasMoreTokens())
offset = Integer.valueOf(tokenizer.nextToken()).intValue();
if (tokenizer.hasMoreTokens())
length = Integer.valueOf(tokenizer.nextToken()).intValue();
if (offset >= 0 && length >= 0) {
fSelectionStart = offset;
fSelectionLength = length;
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION }));
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION));
String handle = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
if (handle != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
if (element == null || !element.exists() || element.getElementType() != IJavaElement.COMPILATION_UNIT)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getName(), IJavaRefactorings.INTRODUCE_FACTORY);
else {
fCUHandle = (ICompilationUnit) element;
initialize();
}
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
handle = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1);
if (handle != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
if (element == null || !element.exists() || element.getElementType() != IJavaElement.TYPE)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getName(), IJavaRefactorings.INTRODUCE_FACTORY);
else {
final IType type = (IType) element;
fFactoryClassName = type.getFullyQualifiedName();
}
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
final String name = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
if (//$NON-NLS-1$
name != null && !"".equals(name))
fNewMethodName = name;
else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
final String protect = arguments.getAttribute(ATTRIBUTE_PROTECT);
if (protect != null) {
fProtectConstructor = Boolean.valueOf(protect).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_PROTECT));
return new RefactoringStatus();
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class IntroduceIndirectionRefactoring method setIntermediaryMethodName.
public RefactoringStatus setIntermediaryMethodName(String newMethodName) {
Assert.isNotNull(newMethodName);
fIntermediaryMethodName = newMethodName;
IJavaElement context = fIntermediaryType != null ? fIntermediaryType : (IMember) fTargetMethod;
RefactoringStatus stat = Checks.checkMethodName(newMethodName, context);
stat.merge(checkOverloading());
return stat;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class ExtractConstantRefactoring method initialize.
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
final String selection = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
if (selection != null) {
int offset = -1;
int length = -1;
final StringTokenizer tokenizer = new StringTokenizer(selection);
if (tokenizer.hasMoreTokens())
offset = Integer.valueOf(tokenizer.nextToken()).intValue();
if (tokenizer.hasMoreTokens())
length = Integer.valueOf(tokenizer.nextToken()).intValue();
if (offset >= 0 && length >= 0) {
fSelectionStart = offset;
fSelectionLength = length;
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION }));
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION));
final String handle = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
if (handle != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
if (element == null || !element.exists() || element.getElementType() != IJavaElement.COMPILATION_UNIT)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getName(), IJavaRefactorings.EXTRACT_CONSTANT);
else
fCu = (ICompilationUnit) element;
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
final String visibility = arguments.getAttribute(ATTRIBUTE_VISIBILITY);
if (visibility != null && !"".equals(visibility)) {
//$NON-NLS-1$
int flag = 0;
try {
flag = Integer.parseInt(visibility);
} catch (NumberFormatException exception) {
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_VISIBILITY));
}
fVisibility = JdtFlags.getVisibilityString(flag);
}
final String name = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
if (//$NON-NLS-1$
name != null && !"".equals(name))
fConstantName = name;
else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
final String replace = arguments.getAttribute(ATTRIBUTE_REPLACE);
if (replace != null) {
fReplaceAllOccurrences = Boolean.valueOf(replace).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_REPLACE));
final String declareFinal = arguments.getAttribute(ATTRIBUTE_QUALIFY);
if (declareFinal != null) {
fQualifyReferencesWithDeclaringClassName = Boolean.valueOf(declareFinal).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_QUALIFY));
return new RefactoringStatus();
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class MethodOverrideTester method getVariableErasure.
private String getVariableErasure(IMember context, String variableName) throws JavaModelException {
IType type;
if (context instanceof IMethod) {
String subst = getMethodSubstitions((IMethod) context).getErasure(variableName);
if (subst != null) {
return subst;
}
type = context.getDeclaringType();
} else {
type = (IType) context;
}
String subst = getTypeSubstitions(type).getErasure(variableName);
if (subst != null) {
return subst;
}
IJavaElement parent = type.getParent();
if (parent instanceof IMethod) {
return getVariableErasure((IMethod) parent, variableName);
} else if (type.getDeclaringType() != null) {
return getVariableErasure(type.getDeclaringType(), variableName);
}
// not a type variable
return variableName;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class AbstractJavaSearchResult method computeContainedMatches.
private Match[] computeContainedMatches(IAdaptable adaptable) {
IJavaElement javaElement = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
Set<Match> matches = new HashSet<Match>();
if (javaElement != null) {
collectMatches(matches, javaElement);
}
IFile file = (IFile) adaptable.getAdapter(IFile.class);
if (file != null) {
collectMatches(matches, file);
}
if (!matches.isEmpty()) {
return matches.toArray(new Match[matches.size()]);
}
return NO_MATCHES;
}
Aggregations