Search in sources :

Example 36 with IMethod

use of org.eclipse.jdt.core.IMethod in project che by eclipse.

the class ParametersHints method findHints.

private void findHints(IJavaElement method, IJavaElement parent, List<MethodParameters> result) throws JavaModelException {
    String methodName = method.getElementName();
    for (IMethod iMethod : ((IType) parent).getMethods()) {
        int methodFlag = iMethod.getFlags();
        if (Flags.isPrivate(methodFlag) || !methodName.equals(iMethod.getElementName())) {
            continue;
        }
        MethodParameters methodParameters = DtoFactory.newDto(MethodParameters.class);
        String parameters = getMethodParametersAsString(iMethod);
        methodParameters.setMethodName(methodName);
        methodParameters.setParameters(parameters);
        if (!result.contains(methodParameters)) {
            result.add(methodParameters);
        }
    }
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) IType(org.eclipse.jdt.core.IType)

Example 37 with IMethod

use of org.eclipse.jdt.core.IMethod in project che by eclipse.

the class RenameMethodRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws JavaModelException {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    String input = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
    IMethod method = (IMethod) JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), input);
    if (method == null) {
        status.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoringContribution_could_not_create, new Object[] { BasicElementLabels.getResourceName(arguments.getProject()), input }));
        return null;
    }
    JavaRenameProcessor processor;
    if (MethodChecks.isVirtual(method)) {
        processor = new RenameVirtualMethodProcessor(method, arguments, status);
    } else {
        processor = new RenameNonVirtualMethodProcessor(method, arguments, status);
    }
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IMethod(org.eclipse.jdt.core.IMethod)

Example 38 with IMethod

use of org.eclipse.jdt.core.IMethod in project che by eclipse.

the class RippleMethodFinder2 method createHierarchyOfDeclarations.

private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException {
    IRegion region = JavaCore.newRegion();
    for (Iterator<IMethod> iter = fDeclarations.iterator(); iter.hasNext(); ) {
        IType declaringType = iter.next().getDeclaringType();
        region.add(declaringType);
    }
    fHierarchy = JavaCore.newTypeHierarchy(region, owner, pm);
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) IRegion(org.eclipse.jdt.core.IRegion) IType(org.eclipse.jdt.core.IType)

Example 39 with IMethod

use of org.eclipse.jdt.core.IMethod in project che by eclipse.

the class JavadocTest method binaryMethodDoc.

@Test
public void binaryMethodDoc() throws JavaModelException {
    IType type = project.findType("java.lang.Object");
    assertThat(type).isNotNull();
    IMethod method = type.getMethod("hashCode", null);
    assertThat(method).isNotNull();
    String htmlContent = JavadocContentAccess2.getHTMLContent(method, true, urlPart);
    assertThat(htmlContent).isNotNull().isNotEmpty().contains("Returns a hash code value for the object.");
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 40 with IMethod

use of org.eclipse.jdt.core.IMethod in project che by eclipse.

the class StubCreator method appendMembers.

protected void appendMembers(final IType type, final IProgressMonitor monitor) throws JavaModelException {
    try {
        monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
        final IJavaElement[] children = type.getChildren();
        for (int index = 0; index < children.length; index++) {
            final IMember child = (IMember) children[index];
            final int flags = child.getFlags();
            final boolean isPrivate = Flags.isPrivate(flags);
            final boolean isDefault = !Flags.isPublic(flags) && !Flags.isProtected(flags) && !isPrivate;
            final boolean stub = fStubInvisible || (!isPrivate && !isDefault);
            if (child instanceof IType) {
                if (stub)
                    appendTypeDeclaration((IType) child, new SubProgressMonitor(monitor, 1));
            } else if (child instanceof IField) {
                if (stub && !Flags.isEnum(flags) && !Flags.isSynthetic(flags))
                    appendFieldDeclaration((IField) child);
            } else if (child instanceof IMethod) {
                final IMethod method = (IMethod) child;
                final String name = method.getElementName();
                if (method.getDeclaringType().isEnum()) {
                    final int count = method.getNumberOfParameters();
                    if (//$NON-NLS-1$
                    count == 0 && "values".equals(name))
                        continue;
                    if (//$NON-NLS-1$ //$NON-NLS-2$
                    count == 1 && "valueOf".equals(name) && "Ljava.lang.String;".equals(method.getParameterTypes()[0]))
                        continue;
                    if (method.isConstructor())
                        continue;
                }
                //$NON-NLS-1$
                boolean skip = !stub || name.equals("<clinit>");
                if (method.isConstructor())
                    skip = false;
                skip = skip || Flags.isSynthetic(flags) || Flags.isBridge(flags);
                if (!skip)
                    appendMethodDeclaration(method);
            }
            //$NON-NLS-1$
            fBuffer.append("\n");
        }
    } finally {
        monitor.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Aggregations

IMethod (org.eclipse.jdt.core.IMethod)160 IType (org.eclipse.jdt.core.IType)87 IJavaElement (org.eclipse.jdt.core.IJavaElement)36 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)29 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)28 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)22 IField (org.eclipse.jdt.core.IField)21 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)14 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)13 IMember (org.eclipse.jdt.core.IMember)13 JavaModelException (org.eclipse.jdt.core.JavaModelException)12 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 HashSet (java.util.HashSet)8 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)8 ILocalVariable (org.eclipse.jdt.core.ILocalVariable)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)7 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)7