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;
}
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;
}
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());
}
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;
}
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;
}
});
}
}
Aggregations