use of org.eclipse.jdt.core.dom.SimpleName in project xtext-eclipse by eclipse.
the class XbaseHoverDocumentationProvider method handleParamTag.
protected void handleParamTag(TagElement tag) {
@SuppressWarnings("unchecked") List<? extends ASTNode> fragments = tag.fragments();
int i = 0;
int size = fragments.size();
if (size > 0) {
Object first = fragments.get(0);
buffer.append(PARAM_NAME_START);
if (first instanceof SimpleName) {
String name = ((SimpleName) first).getIdentifier();
buffer.append(name);
i++;
} else if (first instanceof TextElement) {
String firstText = ((TextElement) first).getText();
if ("<".equals(firstText)) {
// $NON-NLS-1$
// $NON-NLS-1$
buffer.append("<");
i++;
if (size > 1) {
Object second = fragments.get(1);
if (second instanceof SimpleName) {
String name = ((SimpleName) second).getIdentifier();
buffer.append(name);
i++;
if (size > 2) {
Object third = fragments.get(2);
String thirdText = ((TextElement) third).getText();
if (">".equals(thirdText)) {
// $NON-NLS-1$
// $NON-NLS-1$
buffer.append(">");
i++;
}
}
}
}
}
}
buffer.append(PARAM_NAME_END);
handleContentElements(fragments.subList(i, fragments.size()));
}
}
use of org.eclipse.jdt.core.dom.SimpleName in project xtext-eclipse by eclipse.
the class JvmImplementationOpener method openImplementations.
/**
* Main parts of the logic is taken from {@link org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink}
*
* @param element - Element to show implementations for
* @param textviewer - Viewer to show hierarchy view on
* @param region - Region where to show hierarchy view
*/
public void openImplementations(final IJavaElement element, ITextViewer textviewer, IRegion region) {
if (element instanceof IMethod) {
ITypeRoot typeRoot = ((IMethod) element).getTypeRoot();
CompilationUnit ast = SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);
if (ast == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
try {
ISourceRange nameRange = ((IMethod) element).getNameRange();
ASTNode node = NodeFinder.perform(ast, nameRange);
ITypeBinding parentTypeBinding = null;
if (node instanceof SimpleName) {
ASTNode parent = node.getParent();
if (parent instanceof MethodInvocation) {
Expression expression = ((MethodInvocation) parent).getExpression();
if (expression == null) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
} else {
parentTypeBinding = expression.resolveTypeBinding();
}
} else if (parent instanceof SuperMethodInvocation) {
// Directly go to the super method definition
openEditor(element);
return;
} else if (parent instanceof MethodDeclaration) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
}
}
final IType type = parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null;
if (type == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
final String earlyExitIndicator = "EarlyExitIndicator";
final ArrayList<IJavaElement> links = Lists.newArrayList();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
String methodLabel = JavaElementLabels.getElementLabel(element, JavaElementLabels.DEFAULT_QUALIFIED);
monitor.beginTask(Messages.format("Searching for implementors of ''{0}''", methodLabel), 100);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
IJavaElement element = (IJavaElement) match.getElement();
if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod) element)) {
links.add(element);
if (links.size() > 1) {
throw new OperationCanceledException(earlyExitIndicator);
}
}
}
}
};
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
SearchPattern pattern = SearchPattern.createPattern(element, limitTo);
Assert.isNotNull(pattern);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
SearchEngine engine = new SearchEngine();
engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, SubMonitor.convert(monitor, 100));
if (monitor.isCanceled()) {
throw new InterruptedException();
}
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, Messages.format("An error occurred while searching for implementations of method ''{0}''. See error log for details.", element.getElementName()), e.getCause());
JavaPlugin.log(status);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Implementation", "Problems finding implementations.", status);
} catch (InterruptedException e) {
if (e.getMessage() != earlyExitIndicator) {
return;
}
}
if (links.size() == 1) {
openEditor(links.get(0));
} else {
openQuickHierarchy(textviewer, element, region);
}
} catch (JavaModelException e) {
log.error("An error occurred while searching for implementations", e.getCause());
} catch (PartInitException e) {
log.error("An error occurred while searching for implementations", e.getCause());
}
}
}
use of org.eclipse.jdt.core.dom.SimpleName in project AutoRefactor by JnRouvignac.
the class PrimitiveWrapperCreationRefactoring method replaceMethodName.
private boolean replaceMethodName(MethodInvocation node, String methodName) {
final SimpleName name = this.ctx.getASTBuilder().simpleName(methodName);
this.ctx.getRefactorings().set(node, MethodInvocation.NAME_PROPERTY, name);
return DO_NOT_VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.SimpleName in project AutoRefactor by JnRouvignac.
the class RemoveUnneededThisExpressionRefactoring method thisExpressionRefersToEnclosingType.
private static boolean thisExpressionRefersToEnclosingType(Name thisQualifierName, ASTNode node) {
if (thisQualifierName == null) {
return true;
}
final ASTNode enclosingType = getEnclosingType(node);
if (enclosingType instanceof AnonymousClassDeclaration) {
return false;
}
final AbstractTypeDeclaration ancestor = (AbstractTypeDeclaration) enclosingType;
if (thisQualifierName instanceof SimpleName) {
return isEqual((SimpleName) thisQualifierName, ancestor.getName());
} else if (thisQualifierName instanceof QualifiedName) {
final QualifiedName qn = (QualifiedName) thisQualifierName;
return isEqual(qn.getName(), ancestor.getName()) && thisExpressionRefersToEnclosingType(qn.getQualifier(), ancestor);
}
throw new NotImplementedException(thisQualifierName);
}
use of org.eclipse.jdt.core.dom.SimpleName in project AutoRefactor by JnRouvignac.
the class AbstractClassSubstituteRefactoring method canVarOccurrenceBeRefactored0.
private boolean canVarOccurrenceBeRefactored0(final Block node, final List<VariableDeclaration> varDecls, final List<MethodInvocation> methodCallsToRefactor, final List<VariableDeclaration> otherVarDecls) {
for (final VariableDeclaration varDecl : varDecls) {
final VarOccurrenceVisitor varOccurrenceVisitor = new VarOccurrenceVisitor(varDecl);
final Statement parent = getAncestorOrNull(varDecl, Statement.class);
Statement nextSibling = getNextSibling(parent);
while (nextSibling != null) {
varOccurrenceVisitor.visitNode(nextSibling);
nextSibling = getNextSibling(nextSibling);
}
if (varOccurrenceVisitor.isUsedInAnnonymousClass()) {
return false;
}
for (final SimpleName varOccurrence : varOccurrenceVisitor.getVarOccurrences()) {
final List<VariableDeclaration> subVarDecls = new ArrayList<VariableDeclaration>();
if (!canBeRefactored(node, varOccurrence, varOccurrence.resolveTypeBinding(), subVarDecls, methodCallsToRefactor)) {
return false;
}
otherVarDecls.addAll(subVarDecls);
}
}
return true;
}
Aggregations