1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2009-05-09 03:31:07 +00:00
parent 1c93d8ad9e
commit 9742045d4a
2 changed files with 27 additions and 38 deletions

View file

@ -96,8 +96,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
try { try {
return performNavigation(monitor); return performNavigation(monitor);
} } catch (CoreException e) {
catch (CoreException e) {
return e.getStatus(); return e.getStatus();
} }
} }
@ -114,13 +113,12 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
* Creates a new action with the given editor * Creates a new action with the given editor
*/ */
public OpenDeclarationsAction(CEditor editor) { public OpenDeclarationsAction(CEditor editor) {
super( editor ); super(editor);
setText(CEditorMessages.OpenDeclarations_label); setText(CEditorMessages.OpenDeclarations_label);
setToolTipText(CEditorMessages.OpenDeclarations_tooltip); setToolTipText(CEditorMessages.OpenDeclarations_tooltip);
setDescription(CEditorMessages.OpenDeclarations_description); setDescription(CEditorMessages.OpenDeclarations_description);
} }
protected IStatus performNavigation(IProgressMonitor monitor) throws CoreException { protected IStatus performNavigation(IProgressMonitor monitor) throws CoreException {
clearStatusLine(); clearStatusLine();
@ -158,25 +156,24 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
IASTName searchName= nodeSelector.findEnclosingName(selectionStart, selectionLength); IASTName searchName= nodeSelector.findEnclosingName(selectionStart, selectionLength);
if (searchName == null) { if (searchName == null) {
IASTName implicit = nodeSelector.findEnclosingImplicitName(selectionStart, selectionLength); IASTName implicit = nodeSelector.findEnclosingImplicitName(selectionStart, selectionLength);
if(implicit != null) { if (implicit != null) {
IASTImplicitNameOwner owner = (IASTImplicitNameOwner) implicit.getParent(); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) implicit.getParent();
IASTImplicitName[] implicits = owner.getImplicitNames(); IASTImplicitName[] implicits = owner.getImplicitNames();
// there may be more than one name in the same spot // there may be more than one name in the same spot
if(implicits.length > 0) { if (implicits.length > 0) {
List<IName> allNames = new ArrayList<IName>(); List<IName> allNames = new ArrayList<IName>();
for(IASTImplicitName name : implicits) { for (IASTImplicitName name : implicits) {
if(((ASTNode)name).getOffset() == ((ASTNode)implicit).getOffset()) { if (((ASTNode)name).getOffset() == ((ASTNode) implicit).getOffset()) {
IBinding binding = name.resolveBinding(); // guaranteed to resolve IBinding binding = name.resolveBinding(); // guaranteed to resolve
IName[] declNames = findDeclNames(ast, KIND_OTHER, binding); IName[] declNames = findDeclNames(ast, KIND_OTHER, binding);
allNames.addAll(Arrays.asList(declNames)); allNames.addAll(Arrays.asList(declNames));
} }
} }
if(navigateViaCElements(fWorkingCopy.getCProject(), fIndex, allNames.toArray(new IName[0]))) if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, allNames.toArray(new IName[0])))
return Status.OK_STATUS; return Status.OK_STATUS;
} }
} }
} } else {
else {
boolean found= false; boolean found= false;
final IASTNode parent = searchName.getParent(); final IASTNode parent = searchName.getParent();
if (parent instanceof IASTPreprocessorIncludeStatement) { if (parent instanceof IASTPreprocessorIncludeStatement) {
@ -196,8 +193,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
IName[] declNames = findDeclNames(ast, isKind, binding); IName[] declNames = findDeclNames(ast, isKind, binding);
if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, declNames)) { if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, declNames)) {
found= true; found= true;
} } else {
else {
// leave old method as fallback for local variables, parameters and // leave old method as fallback for local variables, parameters and
// everything else not covered by ICElementHandle. // everything else not covered by ICElementHandle.
found = navigateOneLocation(declNames); found = navigateOneLocation(declNames);
@ -221,7 +217,6 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
return Status.OK_STATUS; return Status.OK_STATUS;
} }
private IName[] findDeclNames(IASTTranslationUnit ast, int isKind, IBinding binding) throws CoreException { private IName[] findDeclNames(IASTTranslationUnit ast, int isKind, IBinding binding) throws CoreException {
IName[] declNames = findNames(fIndex, ast, isKind, binding); IName[] declNames = findNames(fIndex, ast, isKind, binding);
if (declNames.length == 0) { if (declNames.length == 0) {
@ -266,7 +261,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
for (IASTName astName : candidates) { for (IASTName astName : candidates) {
try { try {
IBinding b= astName.resolveBinding(); IBinding b= astName.resolveBinding();
if (b!=null && !(b instanceof IProblemBinding)) { if (b != null && !(b instanceof IProblemBinding)) {
if (bindings.add(b)) { if (bindings.add(b)) {
ignoreIndexBindings.add(fIndex.adaptBinding(b)); ignoreIndexBindings.add(fIndex.adaptBinding(b));
} }
@ -358,7 +353,6 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
return navigateCElements(elements); return navigateCElements(elements);
} }
private void convertToCElements(ICProject project, IIndex index, IName[] declNames, List<ICElement> elements) { private void convertToCElements(ICProject project, IIndex index, IName[] declNames, List<ICElement> elements) {
for (IName declName : declNames) { for (IName declName : declNames) {
try { try {
@ -382,8 +376,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
ISourceReference target= null; ISourceReference target= null;
if (elements.size() == 1) { if (elements.size() == 1) {
target= (ISourceReference) elements.get(0); target= (ISourceReference) elements.get(0);
} } else {
else {
if (sIsJUnitTest) { if (sIsJUnitTest) {
throw new RuntimeException("ambiguous input"); //$NON-NLS-1$ throw new RuntimeException("ambiguous input"); //$NON-NLS-1$
} }
@ -491,8 +484,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
private void runInUIThread(Runnable runnable) { private void runInUIThread(Runnable runnable) {
if (Display.getCurrent() != null) { if (Display.getCurrent() != null) {
runnable.run(); runnable.run();
} } else {
else {
Display.getDefault().asyncExec(runnable); Display.getDefault().asyncExec(runnable);
} }
} }
@ -508,15 +500,13 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
} }
} }
private void computeSelectedWord() { private void computeSelectedWord() {
fTextSelection = getSelectedStringFromEditor(); fTextSelection = getSelectedStringFromEditor();
fSelectedText= null; fSelectedText= null;
if (fTextSelection != null) { if (fTextSelection != null) {
if (fTextSelection.getLength() > 0) { if (fTextSelection.getLength() > 0) {
fSelectedText= fTextSelection.getText(); fSelectedText= fTextSelection.getText();
} } else {
else {
IDocument document= fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); IDocument document= fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
IRegion reg= CWordFinder.findWord(document, fTextSelection.getOffset()); IRegion reg= CWordFinder.findWord(document, fTextSelection.getOffset());
if (reg != null && reg.getLength() > 0) { if (reg != null && reg.getLength() > 0) {
@ -530,4 +520,3 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
} }
} }
} }

View file

@ -47,15 +47,15 @@ public class SelectionParseAction extends Action {
super(); super();
} }
public SelectionParseAction( CEditor editor ) { public SelectionParseAction(CEditor editor) {
super(); super();
fEditor=editor; fEditor= editor;
fSite=editor.getSite(); fSite= editor.getSite();
} }
public SelectionParseAction(IWorkbenchSite site){ public SelectionParseAction(IWorkbenchSite site) {
super(); super();
fSite=site; fSite= site;
} }
public IWorkbenchSite getSite() { public IWorkbenchSite getSite() {
@ -65,13 +65,14 @@ public class SelectionParseAction extends Action {
protected void showStatusLineMessage(final String message) { protected void showStatusLineMessage(final String message) {
StatusLineHandler.showStatusLineMessage(fSite, message); StatusLineHandler.showStatusLineMessage(fSite, message);
} }
protected void clearStatusLine() { protected void clearStatusLine() {
StatusLineHandler.clearStatusLine(fSite); StatusLineHandler.clearStatusLine(fSite);
} }
protected ISelection getSelection() { protected ISelection getSelection() {
ISelection sel = null; ISelection sel = null;
if (fSite != null && fSite.getSelectionProvider() != null ){ if (fSite != null && fSite.getSelectionProvider() != null) {
sel = fSite.getSelectionProvider().getSelection(); sel = fSite.getSelectionProvider().getSelection();
} }
@ -80,10 +81,10 @@ public class SelectionParseAction extends Action {
protected ITextSelection getSelectedStringFromEditor() { protected ITextSelection getSelectedStringFromEditor() {
ISelection selection = getSelection(); ISelection selection = getSelection();
if( selection == null || !(selection instanceof ITextSelection) ) if (!(selection instanceof ITextSelection))
return null; return null;
return (ITextSelection)selection; return (ITextSelection) selection;
} }
/** /**
@ -112,7 +113,7 @@ public class SelectionParseAction extends Action {
IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement()); IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement());
if (editor instanceof ITextEditor) { if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor; ITextEditor textEditor = (ITextEditor) editor;
textEditor.selectAndReveal(currentOffset, currentLength); textEditor.selectAndReveal(currentOffset, currentLength);
} else { } else {
reportSourceFileOpenFailure(path); reportSourceFileOpenFailure(path);
@ -122,7 +123,7 @@ public class SelectionParseAction extends Action {
protected void reportSourceFileOpenFailure(IPath path) { protected void reportSourceFileOpenFailure(IPath path) {
showStatusLineMessage(MessageFormat.format( showStatusLineMessage(MessageFormat.format(
CSearchMessages.SelectionParseAction_FileOpenFailure_format, CSearchMessages.SelectionParseAction_FileOpenFailure_format,
new Object[] {path.toOSString()})); new Object[] { path.toOSString() }));
} }
protected void reportSelectionMatchFailure() { protected void reportSelectionMatchFailure() {
@ -132,13 +133,12 @@ public class SelectionParseAction extends Action {
protected void reportSymbolLookupFailure(String symbol) { protected void reportSymbolLookupFailure(String symbol) {
showStatusLineMessage(MessageFormat.format( showStatusLineMessage(MessageFormat.format(
CSearchMessages.SelectionParseAction_SymbolNotFoundInIndex_format, CSearchMessages.SelectionParseAction_SymbolNotFoundInIndex_format,
new Object[] {symbol})); new Object[] { symbol }));
} }
protected void reportIncludeLookupFailure(String filename) { protected void reportIncludeLookupFailure(String filename) {
showStatusLineMessage(MessageFormat.format( showStatusLineMessage(MessageFormat.format(
CSearchMessages.SelectionParseAction_IncludeNotFound_format, CSearchMessages.SelectionParseAction_IncludeNotFound_format,
new Object[] {filename})); new Object[] { filename }));
} }
} }