Search in sources :

Example 66 with IMethod

use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method getMethodFromType.

@Override
protected JvmOperation getMethodFromType(EObject context, Class<?> type, String method) {
    JvmOperation result = super.getMethodFromType(context, type, method);
    if (result != null) {
        IJavaElement found = elementFinder.findElementFor(result);
        assertEquals(IJavaElement.METHOD, found.getElementType());
        assertEquals(result.getSimpleName(), found.getElementName());
        IMethod foundMethod = (IMethod) found;
        assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters());
    }
    return result;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod)

Example 67 with IMethod

use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.

the class JdtTypeProviderTest method getConstructorFromType.

@Override
protected JvmConstructor getConstructorFromType(EObject context, Class<?> type, String constructor) {
    JvmConstructor result = super.getConstructorFromType(context, type, constructor);
    if (result != null) {
        IJavaElement found = elementFinder.findElementFor(result);
        assertEquals(IJavaElement.METHOD, found.getElementType());
        assertEquals(result.getSimpleName(), found.getElementName());
        IMethod foundMethod = (IMethod) found;
        assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters());
    }
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IMethod(org.eclipse.jdt.core.IMethod)

Example 68 with IMethod

use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.

the class JavaElementFinderTest method doTestFindMethod.

protected void doTestFindMethod(Class<?> declaringType, String methodName, int numberOfParameters) {
    JvmOperation foundOperation = findOperation(declaringType, methodName, numberOfParameters);
    assertNotNull(foundOperation);
    IJavaElement found = elementFinder.findElementFor(foundOperation);
    assertEquals(IJavaElement.METHOD, found.getElementType());
    assertEquals(methodName, found.getElementName());
    IMethod foundMethod = (IMethod) found;
    assertEquals(numberOfParameters, foundMethod.getNumberOfParameters());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod)

Example 69 with IMethod

use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.

the class SourceBasedJdtTypeProviderTest method getMethodFromParameterizedMethods.

@Override
protected JvmOperation getMethodFromParameterizedMethods(String method) {
    JvmOperation result = super.getMethodFromParameterizedMethods(method);
    if (result != null) {
        IJavaElement found = elementFinder.findElementFor(result);
        assertEquals(IJavaElement.METHOD, found.getElementType());
        assertEquals(result.getSimpleName(), found.getElementName());
        IMethod foundMethod = (IMethod) found;
        assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters());
    }
    return result;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod)

Example 70 with IMethod

use of org.eclipse.jdt.core.IMethod in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksForCrossRef.

protected void createHyperlinksForCrossRef(XtextResource resource, INode crossRefNode, final IHyperlinkAcceptor acceptor) {
    EObject containedElementAt = getEObjectAtOffsetHelper().resolveContainedElementAt(resource, crossRefNode.getOffset());
    if (containedElementAt instanceof XAbstractFeatureCall) {
        IResolvedTypes resolveTypes = typeResolver.resolveTypes(resource);
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) containedElementAt;
        final JvmIdentifiableElement targetElement = featureCall.getFeature();
        if (targetElement instanceof JvmType || featureCall.getFeature() instanceof JvmEnumerationLiteral) {
            return;
        }
        IJavaElement javaElement = javaElementFinder.findExactElementFor(targetElement);
        if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
            acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, new Region(crossRefNode.getOffset(), crossRefNode.getLength()), sourceViewer, implOpener));
        }
        LightweightTypeReference typeReference = resolveTypes.getActualType(featureCall);
        if (typeReference == null || typeReference.isPrimitive() || typeReference.isPrimitiveVoid()) {
            return;
        }
        final JvmType type = typeReference.getType();
        if (type != null)
            createHyperlinksTo(resource, crossRefNode, type, new IHyperlinkAcceptor() {

                @Override
                public void accept(IHyperlink hyperlink) {
                    if (hyperlink instanceof AbstractHyperlink) {
                        String target = labelForTargetElement(targetElement);
                        ((AbstractHyperlink) hyperlink).setHyperlinkText("Open " + target + " Type - " + type.getSimpleName());
                    }
                    acceptor.accept(hyperlink);
                }

                private String labelForTargetElement(final JvmIdentifiableElement targetElement) {
                    String target = "Return";
                    if (targetElement instanceof JvmField) {
                        target = "Field";
                    } else if (targetElement instanceof JvmFormalParameter) {
                        // special case for variables in switch and for loops
                        if (targetElement.eContainer() instanceof XSwitchExpression || targetElement.eContainer() instanceof XForLoopExpression) {
                            target = "Variable";
                        } else {
                            target = "Parameter";
                        }
                    } else if (targetElement instanceof XVariableDeclaration) {
                        target = "Variable";
                    }
                    return target;
                }
            });
    }
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) IJavaElement(org.eclipse.jdt.core.IJavaElement) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) AbstractHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.AbstractHyperlink) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IHyperlinkAcceptor(org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) EObject(org.eclipse.emf.ecore.EObject) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IMethod(org.eclipse.jdt.core.IMethod) JvmField(org.eclipse.xtext.common.types.JvmField) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression)

Aggregations

IMethod (org.eclipse.jdt.core.IMethod)217 IType (org.eclipse.jdt.core.IType)112 IJavaElement (org.eclipse.jdt.core.IJavaElement)56 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)37 ArrayList (java.util.ArrayList)35 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)29 IField (org.eclipse.jdt.core.IField)27 Test (org.junit.Test)22 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)19 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)19 IMember (org.eclipse.jdt.core.IMember)15 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)14 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)12 HashSet (java.util.HashSet)11 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)10 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)10 ISourceRange (org.eclipse.jdt.core.ISourceRange)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9