Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Likhodedov
2010-10-21 17:55:47 +04:00
23 changed files with 228 additions and 51 deletions
@@ -931,10 +931,20 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
}
@NotNull
public SuggestedNameInfo suggestUniqueVariableName(@NotNull final SuggestedNameInfo baseNameInfo, PsiElement place, boolean lookForward) {
public SuggestedNameInfo suggestUniqueVariableName(@NotNull final SuggestedNameInfo baseNameInfo,
PsiElement place,
boolean ignorePlaceName,
boolean lookForward) {
final String[] names = baseNameInfo.names;
final LinkedHashSet<String> uniqueNames = new LinkedHashSet<String>(names.length);
for (String name : names) {
if (ignorePlaceName && place instanceof PsiNamedElement) {
final String placeName = ((PsiNamedElement)place).getName();
if (Comparing.strEqual(placeName, name)) {
uniqueNames.add(name);
continue;
}
}
uniqueNames.add(suggestUniqueVariableName(name, place, lookForward));
}
@@ -462,6 +462,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
final IntroduceVariableSettings settings =
getSettings(project, editor, expr, occurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, choice);
if (!settings.isOK()) return;
final SuggestedNameInfo suggestedName = getSuggestedName(typeSelectorManager.getDefaultType(), expr);
final Runnable runnable =
introduce(project, expr, editor, anchorStatement, tempContainer, occurrences, anchorStatementIfAll, settings, variable);
CommandProcessor.getInstance().executeCommand(
@@ -473,7 +474,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
PsiVariable elementToRename = variable.get().getElement();
if (elementToRename != null) {
editor.getCaretModel().moveToOffset(elementToRename.getTextOffset());
new VariableInplaceRenamer(elementToRename, editor).performInplaceRename(false);
new VariableInplaceRenamer(elementToRename, editor).performInplaceRename(false, new LinkedHashSet<String>(Arrays.asList(suggestedName.names)));
}
}
}
@@ -170,11 +170,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
myNameSuggestionsManager = new NameSuggestionsManager(myTypeSelector, myNameField,
new NameSuggestionsGenerator() {
public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, myExpression, type);
final String[] strings = JavaCompletionUtil.completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo);
final SuggestedNameInfo.Delegate delegate = new SuggestedNameInfo.Delegate(strings, nameInfo);
return codeStyleManager.suggestUniqueVariableName(delegate, myExpression, true);
return IntroduceVariableBase.getSuggestedName(type, myExpression);
}
});
myNameSuggestionsManager.setLabelsFor(type, namePrompt);
@@ -38,7 +38,7 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider {
String initialName = UsageViewUtil.getShortName(element);
SuggestedNameInfo info = suggestNamesForElement(element);
if (info != null) {
info = JavaCodeStyleManager.getInstance(element.getProject()).suggestUniqueVariableName(info, element, true);
info = JavaCodeStyleManager.getInstance(element.getProject()).suggestUniqueVariableName(info, element, true, true);
}
String parameterName = null;
@@ -148,7 +148,26 @@ public abstract class JavaCodeStyleManager {
* @param lookForward if true, the existing variables are searched in both directions; if false - only backward
* @return the generated unique name,
*/
@NotNull public abstract SuggestedNameInfo suggestUniqueVariableName(@NotNull SuggestedNameInfo baseNameInfo, PsiElement place, boolean lookForward);
@NotNull
public SuggestedNameInfo suggestUniqueVariableName(@NotNull SuggestedNameInfo baseNameInfo,
PsiElement place,
boolean lookForward) {
return suggestUniqueVariableName(baseNameInfo, place, false, lookForward);
}
/**
* Suggests a unique name for the variable used at the specified location.
*
*
* @param baseNameInfo the base name info for the variable.
* @param place the location where the variable will be used.
* @param ignorePlaceName if true and place is PsiNamedElement, place.getName() would be still treated as unique name
* @param lookForward if true, the existing variables are searched in both directions; if false - only backward @return the generated unique name,
*/
@NotNull public abstract SuggestedNameInfo suggestUniqueVariableName(@NotNull SuggestedNameInfo baseNameInfo,
PsiElement place,
boolean ignorePlaceName,
boolean lookForward);
/**
* Replaces all references to Java classes in the contents of the specified element,
@@ -172,4 +191,4 @@ public abstract class JavaCodeStyleManager {
@Nullable
public abstract Collection<PsiImportStatementBase> findRedundantImports(PsiJavaFile file);
}
}
@@ -146,5 +146,10 @@ public abstract class LocalInspectionTool extends InspectionProfileEntry {
public void inspectionStarted(LocalInspectionToolSession session) {}
public void inspectionFinished(LocalInspectionToolSession session, ProblemsHolder problemsHolder) {
inspectionFinished(session);
}
@Deprecated()
public void inspectionFinished(LocalInspectionToolSession session) {}
}
@@ -285,7 +285,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
advanceProgress(1);
tool.inspectionFinished(session);
tool.inspectionFinished(session, holder);
if (holder.hasResults()) {
appendDescriptors(myFile, holder.getResults(), tool);
@@ -73,7 +73,7 @@ public final class LocalInspectionToolWrapper extends DescriptorProviderInspecti
}
});
myTool.inspectionFinished(session);
myTool.inspectionFinished(session, holder);
addProblemDescriptors(holder.getResults(), filterSuppressed);
}
@@ -85,7 +85,7 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
for (PsiElement el : elementsInRange) {
el.accept(visitor);
}
localInspectionTool.inspectionFinished(session);
localInspectionTool.inspectionFinished(session, holder);
if (holder.hasResults()) {
final List<ProblemDescriptor> list = holder.getResults();
final int idx = offlineProblemDescriptor.getProblemIndex();
@@ -48,7 +48,7 @@ public abstract class ScriptingIndexableSetContributor extends IndexableSetContr
LibraryTable libTable = manager.getLibraryTable(true);
if (libTable != null) {
for (Library lib : libTable.getLibraries()) {
for (VirtualFile libFile : lib.getFiles(OrderRootType.CLASSES)) {
for (VirtualFile libFile : lib.getFiles(OrderRootType.SOURCES)) {
libFile.putUserData(getIndexKey(), "");
libFiles.add(libFile);
}
@@ -97,17 +97,8 @@ public class VariableInplaceRenameHandler implements RenameHandler {
@Nullable
public VariableInplaceRenamer doRename(final PsiElement elementToRename, final Editor editor, final DataContext dataContext) {
return doRename(elementToRename, editor, dataContext, true);
}
@Nullable
public VariableInplaceRenamer doRename(final PsiElement elementToRename,
final Editor editor,
final DataContext dataContext,
boolean processTextOccurrences) {
VariableInplaceRenamer renamer = createRenamer(elementToRename, editor);
boolean startedRename = renamer == null ? false : renamer.performInplaceRename(processTextOccurrences);
boolean startedRename = renamer == null ? false : renamer.performInplaceRename();
if (!startedRename) {
try {
@@ -94,10 +94,10 @@ public class VariableInplaceRenamer {
}
public boolean performInplaceRename() {
return performInplaceRename(true);
return performInplaceRename(true, null);
}
public boolean performInplaceRename(boolean processTextOccurrences) {
public boolean performInplaceRename(boolean processTextOccurrences, LinkedHashSet<String> nameSuggestions) {
if (InjectedLanguageUtil.isInInjectedLanguagePrefixSuffix(myElementToRename)) {
return false;
}
@@ -170,9 +170,9 @@ public class VariableInplaceRenamer {
PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, offset);
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myElementToRename)) return true;
if (nameIdentifier != null) addVariable(nameIdentifier, selectedElement, builder);
if (nameIdentifier != null) addVariable(nameIdentifier, selectedElement, builder, nameSuggestions);
for (PsiReference ref : refs) {
addVariable(ref, selectedElement, builder, offset);
addVariable(ref, selectedElement, builder, offset, nameSuggestions);
}
final PsiElement scope1 = scope;
@@ -391,10 +391,14 @@ public class VariableInplaceRenamer {
return range.getStartOffset() <= offset && offset <= range.getEndOffset();
}
private void addVariable(final PsiReference reference, final PsiElement selectedElement, final TemplateBuilderImpl builder, int offset) {
private void addVariable(final PsiReference reference,
final PsiElement selectedElement,
final TemplateBuilderImpl builder,
int offset,
final LinkedHashSet<String> names) {
if (reference.getElement() == selectedElement &&
contains(reference.getRangeInElement().shiftRight(selectedElement.getTextRange().getStartOffset()), offset)) {
Expression expression = new MyExpression(myElementToRename.getName());
Expression expression = new MyExpression(myElementToRename.getName(), names);
builder.replaceElement(reference, PRIMARY_VARIABLE_NAME, expression, true);
}
else {
@@ -402,9 +406,12 @@ public class VariableInplaceRenamer {
}
}
private void addVariable(final PsiElement element, final PsiElement selectedElement, final TemplateBuilderImpl builder) {
private void addVariable(final PsiElement element,
final PsiElement selectedElement,
final TemplateBuilderImpl builder,
final LinkedHashSet<String> names) {
if (element == selectedElement) {
Expression expression = new MyExpression(myElementToRename.getName());
Expression expression = new MyExpression(myElementToRename.getName(), names);
builder.replaceElement(element, PRIMARY_VARIABLE_NAME, expression, true);
}
else {
@@ -416,11 +423,13 @@ public class VariableInplaceRenamer {
private final String myName;
private final LookupElement[] myLookupItems;
private MyExpression(String name) {
private MyExpression(String name, LinkedHashSet<String> names) {
myName = name;
Set<String> names = new HashSet<String>();
for(NameSuggestionProvider provider: Extensions.getExtensions(NameSuggestionProvider.EP_NAME)) {
provider.getSuggestedNames(myElementToRename, myElementToRename, names);
if (names == null) {
names = new LinkedHashSet<String>();
for(NameSuggestionProvider provider: Extensions.getExtensions(NameSuggestionProvider.EP_NAME)) {
provider.getSuggestedNames(myElementToRename, myElementToRename, names);
}
}
myLookupItems = new LookupElement[names.size()];
final Iterator<String> iterator = names.iterator();
@@ -97,6 +97,8 @@ public class MacFileChooserDialogImpl implements MacFileChooserDialog {
invoke(chooser, "setCanChooseFiles:", myChooserDescriptor.isChooseFiles());
invoke(chooser, "setCanChooseDirectories:", myChooserDescriptor.isChooseFolders());
invoke(chooser, "setAllowsMultipleSelection:", myChooserDescriptor.isChooseMultiple());
invoke(chooser, "setTreatsFilePackagesAsDirectories:", myChooserDescriptor.isChooseFolders());
//invoke(chooser, "setCanCreateDirectories:", true);
if (Foundation.isClassRespondsToSelector(Foundation.getClass("NSOpenPanel"), Foundation.createSelector("_setIncludeNewFolderButton:"))) {
invoke(chooser, "_setIncludeNewFolderButton:", true);
}
@@ -108,10 +110,18 @@ public class MacFileChooserDialogImpl implements MacFileChooserDialog {
invoke(chooser, "setDelegate:", self);
Object directory = null;
Object file = null;
final String toSelectPath = toSelect.intValue() == 0 ? null : Foundation.toStringViaUTF8(toSelect);
final VirtualFile toSelectFile = toSelectPath == null ? null : LocalFileSystem.getInstance().findFileByPath(toSelectPath);
final ID directory = toSelectFile == null ? null : toSelectFile.isDirectory() ? toSelect : null;
final ID file = toSelectFile == null ? null : !toSelectFile.isDirectory() ? toSelect : null;
if (toSelectFile != null) {
if (toSelectFile.isDirectory()) {
directory = toSelect;
} else {
directory = Foundation.cfString(toSelectFile.getParent().getPath());
file = Foundation.cfString(toSelectFile.getName());
}
}
if (mySheetCallback != null) {
final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
@@ -290,10 +290,9 @@ import java.util.Map;
@Override
public void closeFile(@NotNull VirtualFile file) {
Editor editor = myVirtualFile2Editor.get(file);
Editor editor = myVirtualFile2Editor.remove(file);
if (editor != null){
EditorFactory.getInstance().releaseEditor(editor);
myVirtualFile2Editor.remove(file);
}
if (file == myActiveFile) myActiveFile = null;
}
@@ -113,8 +113,4 @@ public class RemoteObject implements Remote, Unreferenced {
return false;
}
public RuntimeException rethrowException(Throwable e) {
Throwable wrap = wrapException(e);
throw wrap instanceof RuntimeException ? (RuntimeException)wrap : new RuntimeException(wrap);
}
}
@@ -260,8 +260,8 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
}
@Override
public void inspectionFinished(LocalInspectionToolSession session) {
super.inspectionFinished(session);
public void inspectionFinished(LocalInspectionToolSession session, ProblemsHolder problemsHolder) {
super.inspectionFinished(session, problemsHolder);
if (InspectionGadgetsPlugin.TELEMETRY_ENABLED) {
if (timeStamp < 0) {
System.out.println("finish reported without corresponding start");
@@ -115,9 +115,9 @@ public class TooBroadScopeInspection extends BaseInspection
ProblemDescriptor descriptor)
throws IncorrectOperationException
{
final PsiElement variableIdentifier =
descriptor.getPsiElement();
if (!(variableIdentifier instanceof PsiVariable)) {
final PsiElement variableIdentifier = descriptor.getPsiElement();
if (!(variableIdentifier instanceof PsiIdentifier))
{
return;
}
final PsiVariable variable =
@@ -202,4 +202,6 @@ android.inspections.group.name=Android
android.inspections.dom.name=Android Resources Validation
android.inspections.unknown.attribute.name=Unknown Android XML attribute
android.inspections.unknown.attribute.message=Unknown attribute {0}
android.facet.settings.generate.unsigned.apk=Generate unsigned APK
android.facet.settings.generate.unsigned.apk=Generate unsigned APK
android.compile.messages.generating.r.java=Generating R.java...
android.actions.regenerate.r.java.file.title=Force regenerate R.java file
+4
View File
@@ -53,6 +53,10 @@
<action id="GotoAndroidResourceDefinition" class="org.jetbrains.android.actions.GotoResourceAction">
<keyboard-shortcut first-keystroke="control shift alt R" keymap="$default"/>
</action>
<action id="RegenerateRJavaFile" class="org.jetbrains.android.actions.AndroidRegenerateRJavaFileAction">
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>
</actions>
<depends>JUnit</depends>
@@ -0,0 +1,122 @@
/*
* Copyright 2000-2010 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 org.jetbrains.android.actions;
import com.intellij.facet.ProjectFacetManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import org.jetbrains.android.compiler.AndroidAptCompiler;
import org.jetbrains.android.compiler.AndroidCompileUtil;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.android.util.AndroidUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author Eugene.Kudelevsky
*/
public class AndroidRegenerateRJavaFileAction extends AnAction {
public AndroidRegenerateRJavaFileAction() {
super(AndroidBundle.message("android.actions.regenerate.r.java.file.title"), null, AndroidUtils.ANDROID_ICON);
}
@Override
public void update(AnActionEvent e) {
final Module module = e.getData(DataKeys.MODULE);
final Project project = e.getData(DataKeys.PROJECT);
e.getPresentation().setEnabled(isAvailable(module, project));
}
private static boolean isAvailable(Module module, Project project) {
if (module != null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
return AndroidAptCompiler.isToCompileModule(module, facet.getConfiguration());
}
}
else if (project != null) {
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
for (AndroidFacet facet : facets) {
if (AndroidAptCompiler.isToCompileModule(facet.getModule(), facet.getConfiguration())) {
return true;
}
}
}
return false;
}
@Override
public void actionPerformed(AnActionEvent e) {
final Module module = e.getData(DataKeys.MODULE);
final Project project = e.getData(DataKeys.PROJECT);
ApplicationManager.getApplication().saveAll();
ProgressManager.getInstance().run(
new Task.Backgroundable(project, AndroidBundle.message("android.compile.messages.generating.r.java"), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
doRun(indicator, module, project);
}
});
}
private static void doRun(ProgressIndicator indicator, Module module, Project project) {
if (module != null) {
if (indicator.isCanceled()) {
return;
}
AndroidCompileUtil.generate(module, new AndroidAptCompiler(), false);
return;
}
assert project != null;
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
List<Module> modulesToProcess = new ArrayList<Module>();
for (AndroidFacet facet : facets) {
if (indicator.isCanceled()) {
return;
}
module = facet.getModule();
if (AndroidAptCompiler.isToCompileModule(module, facet.getConfiguration())) {
modulesToProcess.add(module);
}
}
if (modulesToProcess.size() == 0) {
return;
}
if (modulesToProcess.size() == 1) {
AndroidCompileUtil.generate(modulesToProcess.get(0), new AndroidAptCompiler(), false);
return;
}
double step = 1.0 / modulesToProcess.size();
double progress = 0.0;
indicator.setText(AndroidBundle.message("android.compile.messages.generating.r.java"));
indicator.setFraction(progress);
for (int i = 0, n = modulesToProcess.size(); i < n; i++) {
AndroidCompileUtil.generate(modulesToProcess.get(i), new AndroidAptCompiler(), false);
progress = i < n - 1 ? progress + step : 1.0;
indicator.setFraction(progress);
}
}
}
@@ -34,6 +34,7 @@ import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.facet.AndroidFacetConfiguration;
import org.jetbrains.android.facet.AndroidRootUtil;
import org.jetbrains.android.maven.AndroidMavenUtil;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.android.util.AndroidUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -73,7 +74,7 @@ public class AndroidAptCompiler implements SourceGeneratingCompiler {
public GenerationItem[] generate(final CompileContext context, final GenerationItem[] items, VirtualFile outputRootDirectory) {
if (items != null && items.length > 0) {
context.getProgressIndicator().setText("Generating " + AndroidUtils.R_JAVA_FILENAME + "...");
context.getProgressIndicator().setText(AndroidBundle.message("android.compile.messages.generating.r.java"));
Computable<GenerationItem[]> computation = new Computable<GenerationItem[]>() {
public GenerationItem[] compute() {
if (context.getProject().isDisposed()) {
@@ -22,4 +22,9 @@ public class MavenRemoteObject extends RemoteObject{
protected boolean isKnownException(Throwable ex) {
return ex.getClass().getName().startsWith(MavenRemoteObject.class.getPackage().getName());
}
public RuntimeException rethrowException(Throwable e) {
Throwable wrap = wrapException(e);
throw wrap instanceof RuntimeException ? (RuntimeException)wrap : new RuntimeException(wrap);
}
}
@@ -160,6 +160,8 @@ public class SpellCheckingInspection extends LocalInspectionTool {
};
}
private static final boolean magicEvaluator = ApplicationManager.getApplication().isUnitTestMode();
/**
* Splits element text in tokens according to spell checker strategy of given language
* @param element Psi element
@@ -170,6 +172,11 @@ public class SpellCheckingInspection extends LocalInspectionTool {
public static Token[] tokenize(@NotNull final PsiElement element, @NotNull final Language language) {
final SpellcheckingStrategy factoryByLanguage = getFactoryByLanguage(language);
final Tokenizer tokenizer = factoryByLanguage.getTokenizer(element);
String magicWord;
if (magicEvaluator && element.getText().indexOf(magicWord = "xmxmxm") != -1) {
System.out.println("~~~~~~"+tokenizer);
System.out.println(SpellCheckerManager.getInstance(element.getProject()).getUserDictionary().contains(magicWord));
}
return tokenizer.tokenize(element);
}