use of org.eclipse.jdt.core.IJavaElement in project xtext-xtend by eclipse.
the class DetectImplHyperlinksTest method testComputeHyperlink_2.
@Test
public void testComputeHyperlink_2() throws Exception {
String content = "package foo class Foo { def bar(String a) { fo|o() } def foo(){}}";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
assertEquals(3, detectHyperlinks.length);
XbaseImplementatorsHyperlink hyperlink = Iterables.filter(Lists.newArrayList(detectHyperlinks), XbaseImplementatorsHyperlink.class).iterator().next();
assertEquals(offset - 2, hyperlink.getHyperlinkRegion().getOffset());
assertEquals(3, hyperlink.getHyperlinkRegion().getLength());
IJavaElement element = hyperlink.getElement();
assertTrue(element instanceof IMethod);
assertEquals("foo", element.getElementName());
}
use of org.eclipse.jdt.core.IJavaElement in project AutoRefactor by JnRouvignac.
the class SuperCallRatherThanUselessOverridingRefactoring method isMethodUsedInItsPackage.
/**
* This method is extremely expensive.
*/
private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) {
final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
final SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
methodIsUsedInPackage.set(true);
}
};
try {
final SearchEngine searchEngine = new SearchEngine();
searchEngine.search(createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, ctx.getProgressMonitor());
return methodIsUsedInPackage.get();
} catch (CoreException e) {
throw new UnhandledException(node, e);
}
}
use of org.eclipse.jdt.core.IJavaElement in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method addAll.
private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements, IProgressMonitor monitor) throws JavaModelException {
final SubMonitor subMonitor = SubMonitor.convert(monitor, javaElements.size());
for (IJavaElement javaElement : javaElements) {
final SubMonitor child = subMonitor.newChild(1);
final JavaProjectOptions options = getJavaProjectOptions(javaElement);
if (javaElement instanceof ICompilationUnit) {
add(results, (ICompilationUnit) javaElement, options);
} else if (javaElement instanceof IPackageFragment) {
final IPackageFragment pf = (IPackageFragment) javaElement;
addAll(results, getSubPackages(pf), child);
addAll(results, pf.getCompilationUnits(), options);
} else if (javaElement instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
addAll(results, Arrays.asList(pfr.getChildren()), child);
} else if (javaElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) javaElement;
for (IPackageFragment pf : javaProject.getPackageFragments()) {
addAll(results, pf.getCompilationUnits(), options);
}
}
}
}
use of org.eclipse.jdt.core.IJavaElement in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method getSubPackages.
private List<IJavaElement> getSubPackages(IPackageFragment motherPackage) throws JavaModelException {
List<IJavaElement> subPackages = new ArrayList<IJavaElement>();
String packageName = motherPackage.getElementName();
IJavaElement[] packages = ((IPackageFragmentRoot) motherPackage.getParent()).getChildren();
for (IJavaElement onePackage : packages) {
if (onePackage instanceof IPackageFragment && onePackage.getElementName().startsWith(packageName + ".")) {
subPackages.add(onePackage);
}
}
return subPackages;
}
use of org.eclipse.jdt.core.IJavaElement in project xtext-xtend by eclipse.
the class DispatchMethodRenameStrategy method initialize.
@Override
public boolean initialize(EObject xtendMethod, IRenameElementContext context) {
Assert.isLegal(xtendMethod instanceof XtendFunction);
Assert.isLegal(((XtendFunction) xtendMethod).isDispatch());
Assert.isLegal(context instanceof DispatchMethodRenameContext);
ResourceSet resourceSet = xtendMethod.eResource().getResourceSet();
Map<URI, IJavaElement> jvm2JavaElements = ((DispatchMethodRenameContext) context).getJvm2JavaElements();
for (URI dispatchOperationURI : jvm2JavaElements.keySet()) {
JvmOperation dispatchOperation = (JvmOperation) resourceSet.getEObject(dispatchOperationURI, true);
XtendFunction xtendDispatchMethod = associations.getXtendFunction(dispatchOperation);
if (xtendDispatchMethod != null) {
if (equal(xtendDispatchMethod.getName(), dispatchOperation.getSimpleName())) {
// synthetic dispatcher
dispatchers.add(dispatchOperation);
} else {
// xtend dispatch method
XtendDispatchMethodChildStrategy xtendChildStrategy = childStrategyProvider.get();
xtendChildStrategy.initialize(xtendDispatchMethod, context);
children.add(xtendChildStrategy);
}
} else {
// a dispatch method form a Java class
JavaDispatchMethodChildStrategy jvmChildStrategy = javaStrategyProvider.get();
jvmChildStrategy.initialize(dispatchOperation, context);
children.add(jvmChildStrategy);
}
}
return !children.isEmpty();
}
Aggregations