Search in sources :

Example 26 with IJavaElement

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();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) StringTokenizer(java.util.StringTokenizer) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IType(org.eclipse.jdt.core.IType)

Example 27 with IJavaElement

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 28 with IJavaElement

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();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) StringTokenizer(java.util.StringTokenizer) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 29 with IJavaElement

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 30 with IJavaElement

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IFile(org.eclipse.core.resources.IFile) HashSet(java.util.HashSet) Match(org.eclipse.search.ui.text.Match)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)208 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)46 IType (org.eclipse.jdt.core.IType)41 ArrayList (java.util.ArrayList)34 IJavaProject (org.eclipse.jdt.core.IJavaProject)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)31 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)30 IResource (org.eclipse.core.resources.IResource)29 IMethod (org.eclipse.jdt.core.IMethod)28 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)21 IField (org.eclipse.jdt.core.IField)14 IMember (org.eclipse.jdt.core.IMember)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)8