This commit is contained in:
Alexey Kudravtsev
2013-10-01 14:54:48 +04:00
parent 069d1720b2
commit e0bf51985e
8 changed files with 79 additions and 22 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.refactoring.HelpID;
import com.intellij.refactoring.JavaRefactoringSettings;
import com.intellij.refactoring.RefactoringBundle;
@@ -50,20 +51,25 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
init();
}
@Override
protected String getNameLabelText() {
String methodText = PsiFormatUtil.formatMethod(myMethod,
PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, PsiFormatUtil.SHOW_TYPE);
PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
PsiFormatUtilBase.SHOW_TYPE);
return RefactoringBundle.message("inline.method.method.label", methodText);
}
@Override
protected String getBorderTitle() {
return RefactoringBundle.message("inline.method.border.title");
}
@Override
protected String getInlineThisText() {
return RefactoringBundle.message("this.invocation.only.and.keep.the.method");
}
@Override
protected String getInlineAllText() {
final String occurrencesString = myOccurrencesNumber > -1 ? " (" + myOccurrencesNumber + " occurrence" + (myOccurrencesNumber == 1 ? ")" : "s)") : "";
return (myMethod.isWritable()
@@ -71,6 +77,7 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
: RefactoringBundle.message("all.invocations.in.project")) + occurrencesString;
}
@Override
protected void doAction() {
super.doAction();
invokeRefactoring(
@@ -82,15 +89,18 @@ public class InlineMethodDialog extends InlineOptionsWithSearchSettingsDialog {
}
}
@Override
protected void doHelpAction() {
if (myMethod.isConstructor()) HelpManager.getInstance().invokeHelp(HelpID.INLINE_CONSTRUCTOR);
else HelpManager.getInstance().invokeHelp(HelpID.INLINE_METHOD);
}
@Override
protected boolean canInlineThisOnly() {
return InlineMethodHandler.checkRecursive(myMethod) || myAllowInlineThisOnly;
}
@Override
protected boolean isInlineThis() {
return JavaRefactoringSettings.getInstance().INLINE_METHOD_THIS;
}
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Author: dmitrylomov
*/
public abstract class DoWhile {
public abstract class DoWhile {
private final AsyncFutureResult<Boolean> myResult = AsyncFutureFactory.getInstance().createAsyncFutureResult();
private final SameThreadExecutorWithTrampoline myExecutor = new SameThreadExecutorWithTrampoline();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,15 +62,15 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
return processAsync(consumer, Collections.synchronizedSet(new THashSet<M>(myHashingStrategy)));
}
private boolean process(final Processor<T> consumer, final Set<M> processedElements) {
private boolean process(@NotNull Processor<T> consumer, @NotNull Set<M> processedElements) {
return myOriginal.forEach(new MyProcessor(processedElements, consumer));
}
private AsyncFuture<Boolean> processAsync(final Processor<T> consumer, final Set<M> processedElements) {
@NotNull
private AsyncFuture<Boolean> processAsync(@NotNull Processor<T> consumer, @NotNull Set<M> processedElements) {
return myOriginal.forEachAsync(new MyProcessor(processedElements, consumer));
}
@Override
@NotNull
public Collection<T> findAll() {
@@ -102,7 +102,7 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
private final Set<M> myProcessedElements;
private final Processor<T> myConsumer;
public MyProcessor(Set<M> processedElements, Processor<T> consumer) {
public MyProcessor(@NotNull Set<M> processedElements, @NotNull Processor<T> consumer) {
myProcessedElements = processedElements;
myConsumer = consumer;
}
@@ -112,4 +112,10 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
return !myProcessedElements.add(myMapper.fun(t)) || myConsumer.process(t);
}
}
@SuppressWarnings("HardCodedStringLiteral")
@Override
public String toString() {
return "UniqueQuery: "+myOriginal;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,10 +40,11 @@ public class QuerySearchRequest {
this.processor = new ReadActionProcessor<PsiReference>() {
@Override
public boolean processInReadAction(PsiReference psiReference) {
return processor.process(psiReference, collector);
return processor.process(psiReference, collector);
}
};
} else {
}
else {
this.processor = new Processor<PsiReference>() {
@Override
public boolean process(PsiReference psiReference) {
@@ -51,10 +52,14 @@ public class QuerySearchRequest {
}
};
}
}
public void runQuery() {
query.forEach(processor);
}
@Override
public String toString() {
return query + " -> " + collector;
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.search;
import com.intellij.concurrency.AsyncFuture;
@@ -29,4 +44,9 @@ public class SearchRequestQuery extends AbstractQuery<PsiReference> {
protected boolean processResults(@NotNull Processor<PsiReference> consumer) {
return PsiSearchHelper.SERVICE.getInstance(myProject).processRequests(myRequests, consumer);
}
@Override
public String toString() {
return myRequests.toString();
}
}
@@ -1,15 +1,32 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.search.searches;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
/**
* @author max
*/
public class ReferenceDescriptor {
public static final Function<PsiReference, ReferenceDescriptor> MAPPER = new Function<PsiReference, ReferenceDescriptor>() {
@Override
public ReferenceDescriptor fun(PsiReference psiReference) {
final PsiElement element = psiReference.getElement();
final PsiFile file = element.getContainingFile();
@@ -19,7 +36,7 @@ public class ReferenceDescriptor {
private final PsiFile file;
private final int offset;
ReferenceDescriptor(PsiFile file, int offset) {
ReferenceDescriptor(@NotNull PsiFile file, int offset) {
this.file = file;
this.offset = offset;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -133,9 +133,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
final boolean inReadAction,
@NotNull PairProcessor<PsiReference, SearchRequestCollector> processor) {
final SearchRequestCollector nested = new SearchRequestCollector(collector.getSearchSession());
collector.searchQuery(new QuerySearchRequest(search(new SearchParameters(element, searchScope, ignoreAccessScope, nested)), nested,
inReadAction, processor));
Query<PsiReference> query = search(new SearchParameters(element, searchScope, ignoreAccessScope, nested));
collector.searchQuery(new QuerySearchRequest(query, nested, inReadAction, processor));
}
}
@@ -175,13 +175,14 @@ public class StringSearcher {
/**
* @deprecated Use {@link #scan(CharSequence)} instead
* @param text
* @param startOffset
* @param endOffset
* @return
*/
public int scan(char[] text, int startOffset, int endOffset){
final int res = scan(new CharArrayCharSequence(text),text, startOffset, endOffset);
return res >= 0 ? res: -1;
}
@Override
public String toString() {
return "pattern " + myPattern;
}
}