mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+12
-1
@@ -39,4 +39,15 @@ idea.xdebug.key=-Xdebug
|
||||
#-----------------------------------------------------------------------
|
||||
# This option controls console cyclic buffer: keeps the console output size not higher than the specified buffer size (Kb). Older lines are deleted.
|
||||
# In order to disable cycle buffer use idea.cycle.buffer.size=disabled
|
||||
idea.cycle.buffer.size=1024
|
||||
idea.cycle.buffer.size=1024
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Disabling this property may lead to visual glitches like blinking and fail to repaint
|
||||
# on certain display adapter cards.
|
||||
#----------------------------------------------------------------------
|
||||
sun.java2d.noddraw=true
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Removing this property may lead to editor performance degradation under Windows.
|
||||
#----------------------------------------------------------------------
|
||||
sun.java2d.d3d=false
|
||||
+5
-5
@@ -9,7 +9,7 @@
|
||||
# Before you run IntelliJ IDEA specify the location of the
|
||||
# JDK 1.6 installation directory which will be used for running IDEA
|
||||
# ---------------------------------------------------------------------
|
||||
[[ `uname -s` = "Darwin" ]] && OS_TYPE="MAC" || OS_TYPE="NOT_MAC"
|
||||
[ `uname -s` = "Darwin" ] && OS_TYPE="MAC" || OS_TYPE="NOT_MAC"
|
||||
|
||||
if [ -z "$IDEA_JDK" ]; then
|
||||
IDEA_JDK=$JDK_HOME
|
||||
@@ -23,7 +23,7 @@ if [ -z "$IDEA_JDK" ]; then
|
||||
|
||||
if [ -n "$JAVA_BIN_PATH" ]; then
|
||||
# Mac readlink doesn't support -f option.
|
||||
[[ "$OS_TYPE" = "MAC" ]] && CANONICALIZE_OPTION="" || CANONICALIZE_OPTION="-f"
|
||||
[ "$OS_TYPE" = "MAC" ] && CANONICALIZE_OPTION="" || CANONICALIZE_OPTION="-f"
|
||||
|
||||
JAVA_LOCATION=`readlink $CANONICALIZE_OPTION $JAVA_BIN_PATH | xargs dirname | xargs dirname | xargs dirname`
|
||||
if [ "$OS_TYPE" = "MAC" ]; then
|
||||
@@ -100,7 +100,7 @@ if [ -z "$IDEA_VM_OPTIONS" ]; then
|
||||
IDEA_VM_OPTIONS="$IDEA_HOME/bin/idea.vmoptions"
|
||||
fi
|
||||
|
||||
[[ -e $IDEA_HOME/Contents/Info.plist ]] && BUNDLE_TYPE="MAC" || BUNDLE_TYPE="NOT_MAC"
|
||||
[ -e $IDEA_HOME/Contents/Info.plist ] && BUNDLE_TYPE="MAC" || BUNDLE_TYPE="NOT_MAC"
|
||||
|
||||
# If vmoptions file exists - use it
|
||||
if [ -e "$IDEA_VM_OPTIONS" ]; then
|
||||
@@ -109,11 +109,11 @@ if [ -e "$IDEA_VM_OPTIONS" ]; then
|
||||
# don't extract vm options from Info.plist in mac bundle
|
||||
INFO_PLIST_PARSER_OPTIONS=""
|
||||
else
|
||||
[[ "$BUNDLE_TYPE" = "MAC" ]] && [[ "$BITS" == "64" ]] && INFO_PLIST_PARSER_OPTIONS=" 64" || INFO_PLIST_PARSER_OPTIONS=" 32"
|
||||
[ "$BUNDLE_TYPE" = "MAC" ] && [ "$BITS" == "64" ] && INFO_PLIST_PARSER_OPTIONS=" 64" || INFO_PLIST_PARSER_OPTIONS=" 32"
|
||||
fi
|
||||
|
||||
# In MacOS ./Contents/Info.plist describes all vm options & system properties
|
||||
[[ "$OS_TYPE" = "MAC" ]] && [[ "$BUNDLE_TYPE" = "MAC" ]] && [[ -z "$IDEA_PROPERTIES_PROPERTY" ]] && MAC_IDEA_PROPERTIES="`osascript \"$IDEA_BIN_HOME/info_plist_parser.scpt\"$INFO_PLIST_PARSER_OPTIONS`" || MAC_IDEA_PROPERTIES=""
|
||||
[ "$OS_TYPE" = "MAC" ] && [ "$BUNDLE_TYPE" = "MAC" ] && [ -z "$IDEA_PROPERTIES_PROPERTY" ] && MAC_IDEA_PROPERTIES="`osascript \"$IDEA_BIN_HOME/info_plist_parser.scpt\"$INFO_PLIST_PARSER_OPTIONS`" || MAC_IDEA_PROPERTIES=""
|
||||
REQUIRED_JVM_ARGS="-Xbootclasspath/a:../lib/boot.jar -Didea.paths.selector=@@system_selector@@ $IDEA_PROPERTIES_PROPERTY $REQUIRED_JVM_ARGS $MAC_IDEA_PROPERTIES"
|
||||
|
||||
JVM_ARGS=`eval echo $JVM_ARGS $REQUIRED_JVM_ARGS`
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@
|
||||
export DEFAULT_PROJECT_PATH=`pwd`
|
||||
|
||||
# Launch inspection tool
|
||||
IDEA_BIN_HOME=$(cd `dirname $0` && pwd)
|
||||
IDEA_BIN_HOME="$( cd "$( dirname "$0" )" && pwd )"
|
||||
$IDEA_BIN_HOME/idea.sh inspect $*
|
||||
@@ -92,16 +92,6 @@ binding.setVariable("loadProject", {
|
||||
}
|
||||
}
|
||||
IdeaProjectLoader.loadFromPath(project, "${home}")
|
||||
|
||||
binding.ant.patternset(id: "idea.compiler.resources") {
|
||||
exclude(name: "**/*.java")
|
||||
exclude(name: "**/*.form")
|
||||
exclude(name: "**/*.class")
|
||||
exclude(name: "**/*.scala")
|
||||
exclude(name: "**/*.groovy")
|
||||
}
|
||||
|
||||
project["compiler.resources.id"] = "idea.compiler.resources"
|
||||
})
|
||||
|
||||
boolean hasSourceRoots(Module module) {
|
||||
|
||||
+2
-3
@@ -282,7 +282,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
return IndexInfrastructure.findFileById((PersistentFS)ManagingFS.getInstance(), id);
|
||||
}
|
||||
|
||||
public void update(final CompileContext context, final String outputRoot, final Collection<TranslatingCompiler.OutputItem> successfullyCompiled, final VirtualFile[] filesToRecompile)
|
||||
public void update(final CompileContext context, @Nullable final String outputRoot, final Collection<TranslatingCompiler.OutputItem> successfullyCompiled, final VirtualFile[] filesToRecompile)
|
||||
throws IOException {
|
||||
final Project project = context.getProject();
|
||||
final int projectId = getProjectId(project);
|
||||
@@ -316,11 +316,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
final VirtualFile outputFile = lfs.findFileByPath(outputPath);
|
||||
|
||||
//assert outputFile != null : "Virtual file was not found for \"" + outputPath + "\"";
|
||||
assert outputRoot != null;
|
||||
|
||||
if (outputFile != null) {
|
||||
if (!sourceFile.equals(outputFile)) {
|
||||
final String className = MakeUtil.relativeClassPathToQName(outputPath.substring(outputRoot.length()), '/');
|
||||
final String className = outputRoot == null? null : MakeUtil.relativeClassPathToQName(outputPath.substring(outputRoot.length()), '/');
|
||||
if (isSourceValid) {
|
||||
srcInfo.addOutputPath(projectId, outputPath);
|
||||
saveOutputInfo(outputFile, new OutputFileInfo(sourceFile.getPath(), className));
|
||||
|
||||
+5
-2
@@ -115,9 +115,12 @@ public class AnnotationProcessingCompiler implements TranslatingCompiler{
|
||||
}
|
||||
|
||||
private boolean isExcludedFromAnnotationProcessing(VirtualFile file, CompileContext context) {
|
||||
if (!context.isAnnotationProcessorsEnabled()) {
|
||||
return true;
|
||||
}
|
||||
final Module module = context.getModuleByFile(file);
|
||||
if (module != null) {
|
||||
if (!context.isAnnotationProcessorsEnabled()) {
|
||||
if (!myConfig.isAnnotationProcessingEnabled(module)) {
|
||||
return true;
|
||||
}
|
||||
final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module);
|
||||
@@ -141,7 +144,7 @@ public class AnnotationProcessingCompiler implements TranslatingCompiler{
|
||||
}
|
||||
|
||||
private JavacCompiler getBackEndCompiler() {
|
||||
CompilerConfigurationImpl configuration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject);
|
||||
CompilerConfigurationImpl configuration = (CompilerConfigurationImpl)myConfig;
|
||||
return configuration.getJavacCompiler();
|
||||
}
|
||||
|
||||
|
||||
+3
-13
@@ -44,7 +44,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -205,20 +204,11 @@ public class JavaMarkObjectActionHandler extends MarkObjectActionHandler {
|
||||
}
|
||||
|
||||
private static List<ObjectReference> getReferringObjects(ObjectReference value) {
|
||||
// invoke the following method using Reflection in order to remain compilable on jdk 1.5
|
||||
// java.util.List<com.sun.jdi.ObjectReference> referringObjects(long l);
|
||||
try {
|
||||
final Method apiMethod = ObjectReference.class.getMethod("referringObjects", long.class);
|
||||
//noinspection unchecked
|
||||
return (List<ObjectReference>)apiMethod.invoke(value, AUTO_MARKUP_REFERRING_OBJECTS_LIMIT);
|
||||
return value.referringObjects(AUTO_MARKUP_REFERRING_OBJECTS_LIMIT);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
LOG.error(e); // should not happen
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (NoSuchMethodException ignored) {
|
||||
catch (UnsupportedOperationException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,6 +65,6 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB
|
||||
}
|
||||
|
||||
public boolean isMarkAdditionalFields() {
|
||||
return myCbMarkAdditionalFields.isSelected();
|
||||
return mySuggestAdditionalMarkup && myCbMarkAdditionalFields.isSelected();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class SuspendContextImpl implements SuspendContext {
|
||||
myKeptReferences.clear();
|
||||
}
|
||||
|
||||
for(SuspendContextCommandImpl cmd = myPostponedCommands.poll(); cmd != null; cmd = myPostponedCommands.poll()) {
|
||||
for(SuspendContextCommandImpl cmd = pollPostponedCommand(); cmd != null; cmd = pollPostponedCommand()) {
|
||||
cmd.notifyCancelled();
|
||||
}
|
||||
|
||||
@@ -199,8 +199,11 @@ public abstract class SuspendContextImpl implements SuspendContext {
|
||||
}
|
||||
}
|
||||
|
||||
public void postponeCommand(final SuspendContextCommandImpl command) {
|
||||
public final void postponeCommand(final SuspendContextCommandImpl command) {
|
||||
if (!isResumed()) {
|
||||
// Important! when postponing increment the holds counter, so that the action is not released too early.
|
||||
// This will ensure that the counter becomes zero only when the command is actually executed or canceled
|
||||
command.hold();
|
||||
myPostponedCommands.add(command);
|
||||
}
|
||||
else {
|
||||
@@ -208,7 +211,7 @@ public abstract class SuspendContextImpl implements SuspendContext {
|
||||
}
|
||||
}
|
||||
|
||||
public SuspendContextCommandImpl pollPostponedCommand() {
|
||||
public final SuspendContextCommandImpl pollPostponedCommand() {
|
||||
return myPostponedCommands.poll();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -23,13 +23,12 @@ import com.intellij.psi.PsiExpressionCodeFragment;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TextWithImportsImpl implements TextWithImports{
|
||||
public final class TextWithImportsImpl implements TextWithImports{
|
||||
|
||||
private final CodeFragmentKind myKind;
|
||||
private String myText;
|
||||
private final String myImports;
|
||||
|
||||
|
||||
public TextWithImportsImpl (PsiExpression expression) {
|
||||
myKind = CodeFragmentKind.EXPRESSION;
|
||||
final String text = expression.getText();
|
||||
@@ -92,9 +91,13 @@ public class TextWithImportsImpl implements TextWithImports{
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
public String toExternalForm() {
|
||||
return "".equals(myImports) ? myText : myText + DebuggerEditorImpl.SEPARATOR + myImports;
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return myText.hashCode();
|
||||
}
|
||||
|
||||
@@ -19,21 +19,22 @@ package com.intellij.debugger.impl;
|
||||
* @author lex
|
||||
*/
|
||||
public abstract class DebuggerTaskImpl implements DebuggerTask {
|
||||
private boolean myOnHold = false;
|
||||
private int myHolds = 0;
|
||||
|
||||
public synchronized final void release() {
|
||||
if (myOnHold) {
|
||||
myOnHold = false;
|
||||
notifyAll();
|
||||
if (myHolds > 0) {
|
||||
if (--myHolds == 0) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized final void hold() {
|
||||
myOnHold = true;
|
||||
myHolds++;
|
||||
}
|
||||
|
||||
public synchronized final void waitFor() {
|
||||
while (myOnHold) {
|
||||
while (myHolds > 0) {
|
||||
try {
|
||||
wait();
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
|
||||
public Element writeTextWithImports(TextWithImports text) {
|
||||
Element element = new Element("TextWithImports");
|
||||
|
||||
element.setAttribute("text", text.toString());
|
||||
element.setAttribute("text", text.toExternalForm());
|
||||
element.setAttribute("type", text.getKind() == CodeFragmentKind.EXPRESSION ? "expression" : "code fragment");
|
||||
return element;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
|
||||
|
||||
public void writeTextWithImports(Element root, String name, TextWithImports value) {
|
||||
LOG.assertTrue(value.getKind() == CodeFragmentKind.EXPRESSION);
|
||||
JDOMExternalizerUtil.writeField(root, name, value.toString());
|
||||
JDOMExternalizerUtil.writeField(root, name, value.toExternalForm());
|
||||
}
|
||||
|
||||
public TextWithImports readTextWithImports(Element root, String name) {
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ public class CompoundRendererConfigurable implements UnnamedConfigurable{
|
||||
exprColumn.setCellRenderer(new DefaultTableCellRenderer() {
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
final TextWithImports textWithImports = (TextWithImports)value;
|
||||
String text = (textWithImports != null)? textWithImports.toString() : "";
|
||||
final String text = (textWithImports != null)? textWithImports.getText() : "";
|
||||
return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -260,7 +260,7 @@ public abstract class Breakpoint extends FilteredRequestor implements ClassPrepa
|
||||
|
||||
public void writeExternal(Element parentNode) throws WriteExternalException {
|
||||
super.writeExternal(parentNode);
|
||||
JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toString());
|
||||
JDOMExternalizerUtil.writeField(parentNode, LOG_MESSAGE_OPTION_NAME, getLogMessage().toExternalForm());
|
||||
}
|
||||
|
||||
public TextWithImports getLogMessage() {
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class FilteredRequestor implements LocatableEventRequestor, JDOM
|
||||
|
||||
public void writeExternal(Element parentNode) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, parentNode);
|
||||
JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toString());
|
||||
JDOMExternalizerUtil.writeField(parentNode, CONDITION_OPTION_NAME, getCondition().toExternalForm());
|
||||
DebuggerUtilsEx.writeFilters(parentNode, FILTER_OPTION_NAME, myClassFilters);
|
||||
DebuggerUtilsEx.writeFilters(parentNode, EXCLUSION_FILTER_OPTION_NAME, myClassExclusionFilters);
|
||||
DebuggerUtilsEx.writeFilters(parentNode, INSTANCE_ID_OPTION_NAME, InstanceFilter.createClassFilters(myInstanceFilters));
|
||||
|
||||
+8
-1
@@ -19,8 +19,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TextWithImports {
|
||||
String getText();
|
||||
|
||||
void setText(String newText);
|
||||
@NotNull String getImports();
|
||||
|
||||
@NotNull
|
||||
String getImports();
|
||||
|
||||
CodeFragmentKind getKind();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
String toExternalForm();
|
||||
}
|
||||
|
||||
@@ -61,12 +61,8 @@ public class JavaIndentOptionsEditor extends SmartIndentOptionsEditor {
|
||||
|
||||
public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) {
|
||||
super.apply(settings, options);
|
||||
try {
|
||||
options.LABEL_INDENT_SIZE = Integer.parseInt(myLabelIndent.getText());
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
//stay with default
|
||||
}
|
||||
options.LABEL_INDENT_SIZE = getFieldValue(myLabelIndent, 0, options.LABEL_INDENT_SIZE);
|
||||
|
||||
options.LABEL_INDENT_ABSOLUTE = myLabelIndentAbsolute.isSelected();
|
||||
settings.DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS = myCbDontIndentTopLevelMembers.isSelected();
|
||||
options.USE_RELATIVE_INDENTS = myCbUseRelativeIndent.isSelected();
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
|
||||
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
|
||||
import com.intellij.codeInsight.guess.GuessManager;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -44,6 +45,8 @@ import com.intellij.psi.filters.element.ExcludeDeclaredFilter;
|
||||
import com.intellij.psi.filters.element.ExcludeSillyAssignment;
|
||||
import com.intellij.psi.html.HtmlTag;
|
||||
import com.intellij.psi.impl.source.PsiImmediateClassType;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.scope.BaseScopeProcessor;
|
||||
import com.intellij.psi.scope.ElementClassFilter;
|
||||
@@ -764,7 +767,7 @@ public class JavaCompletionUtil {
|
||||
assert document != null;
|
||||
document.replaceString(startOffset, endOffset, name);
|
||||
|
||||
final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, "#");
|
||||
final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, " ");
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
@@ -781,9 +784,15 @@ public class JavaCompletionUtil {
|
||||
? ((PsiImportStaticReferenceElement)ref).bindToTargetClass(psiClass)
|
||||
: ref.bindToElement(psiClass);
|
||||
|
||||
RangeMarker marker = document.createRangeMarker(newElement.getTextRange());
|
||||
ASTNode newNode = newElement.getNode();
|
||||
CodeEditUtil.disablePostponedFormatting(newNode);
|
||||
ASTNode next = TreeUtil.nextLeaf(newNode);
|
||||
if (next != null) {
|
||||
CodeEditUtil.disablePostponedFormatting(next);
|
||||
}
|
||||
|
||||
newElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newElement);
|
||||
newStartOffset = marker.getStartOffset();
|
||||
newStartOffset = newElement.getTextRange().getStartOffset();
|
||||
|
||||
if (!staticImport &&
|
||||
newElement instanceof PsiJavaCodeReferenceElement &&
|
||||
|
||||
+8
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -29,6 +29,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -109,11 +110,16 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
expressions[i] = factory.createExpressionFromText(value, parameter);
|
||||
}
|
||||
expressions[parameters.length] = factory.createExpressionFromText(getField().getName(), constructor);
|
||||
if (constructor.isVarArgs()) {
|
||||
ArrayUtil.swap(expressions, expressions.length - 1, expressions.length - 2);
|
||||
}
|
||||
final SmartPointerManager manager = SmartPointerManager.getInstance(getField().getProject());
|
||||
final SmartPsiElementPointer constructorPointer = manager.createSmartPsiElementPointer(constructor);
|
||||
|
||||
final ChangeMethodSignatureFromUsageFix addParamFix = new ChangeMethodSignatureFromUsageFix(constructor, expressions, PsiSubstitutor.EMPTY, constructor, true, 1);
|
||||
addParamFix.invoke(project, editor, file);
|
||||
if (addParamFix.isAvailable(project, editor, file)) {
|
||||
addParamFix.invoke(project, editor, file);
|
||||
}
|
||||
return ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
|
||||
public Boolean compute() {
|
||||
return doCreate(project, editor, parameters, constructorPointer, addParamFix);
|
||||
|
||||
+9
-1
@@ -145,7 +145,9 @@ public abstract class ImportClassFixBase<T extends PsiElement & PsiReference> im
|
||||
&& (JspPsiUtil.isInJspFile(psiFile) ?
|
||||
CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY :
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY)
|
||||
&& codeAnalyzer.canChangeFileSilently(psiFile)) {
|
||||
&& codeAnalyzer.canChangeFileSilently(psiFile)
|
||||
&& !autoImportWillInsertUnexpectedCharacters(classes[0])
|
||||
) {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
public void run() {
|
||||
action.execute();
|
||||
@@ -165,6 +167,12 @@ public abstract class ImportClassFixBase<T extends PsiElement & PsiReference> im
|
||||
return Result.POPUP_NOT_SHOWN;
|
||||
}
|
||||
|
||||
private static boolean autoImportWillInsertUnexpectedCharacters(PsiClass aClass) {
|
||||
PsiClass containingClass = aClass.getContainingClass();
|
||||
// when importing inner class, the reference might be qualified with outer class name and it can be confusing
|
||||
return containingClass != null;
|
||||
}
|
||||
|
||||
private boolean canImportHere(boolean allowCaretNearRef, Editor editor, PsiFile psiFile, String exampleClassName) {
|
||||
return (allowCaretNearRef || !isCaretNearRef(editor, myRef)) &&
|
||||
!hasUnresolvedImportWhichCanImport(psiFile, exampleClassName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -46,7 +46,7 @@ public class PsiGenerationInfo<T extends PsiMember> extends GenerationInfo {
|
||||
return myMember;
|
||||
}
|
||||
|
||||
public void insert(PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException {
|
||||
public void insert(final PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException {
|
||||
final PsiMember existingMember;
|
||||
if (myMember instanceof PsiField) {
|
||||
existingMember = aClass.findFieldByName(myMember.getName(), false);
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.intention.impl;
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
|
||||
import com.intellij.javaee.ExternalResourceManager;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -49,6 +50,7 @@ public class ConvertToBasicLatinAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) {
|
||||
if (!element.getLanguage().isKindOf(StdLanguages.JAVA)) return false;
|
||||
final Pair<PsiElement, Handler> pair = findHandler(element);
|
||||
if (pair == null) return false;
|
||||
|
||||
|
||||
@@ -987,7 +987,7 @@ public class JavaDocInfoGenerator {
|
||||
}
|
||||
}
|
||||
else {
|
||||
buffer.append(element.getText());
|
||||
buffer.append(StringUtil.unescapeStringCharacters(element.getText()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -142,17 +143,23 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
final FileTemplateConfigurable configurable = new FileTemplateConfigurable();
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run() {
|
||||
configurable.setTemplate(myTemplateToEdit, null);
|
||||
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myReplaceTemplateFix.applyFix(project, descriptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
myReplaceTemplateFix.applyFix(project, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -37,21 +37,20 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool {
|
||||
|
||||
private PsiMethod myHashCode;
|
||||
private PsiMethod myEquals;
|
||||
private JavaPsiFacade myPsiFacade;
|
||||
private final AtomicBoolean myInitialized = new AtomicBoolean();
|
||||
|
||||
public void projectOpened(Project project) {
|
||||
myPsiFacade = JavaPsiFacade.getInstance(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
|
||||
if (!myInitialized.getAndSet(true)) {
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(holder.getProject());
|
||||
final PsiClass psiObjectClass = ApplicationManager.getApplication().runReadAction(
|
||||
new Computable<PsiClass>() {
|
||||
@Nullable
|
||||
public PsiClass compute() {
|
||||
return myPsiFacade.findClass("java.lang.Object");
|
||||
return psiFacade.findClass("java.lang.Object");
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -124,6 +123,5 @@ public class EqualsAndHashcode extends BaseJavaLocalInspectionTool {
|
||||
public void projectClosed(Project project) {
|
||||
myEquals = null;
|
||||
myHashCode = null;
|
||||
myPsiFacade = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInspection.javaDoc;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
@@ -327,6 +328,7 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiDocTag myTag = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiDocTag.class);
|
||||
if (myTag == null) return;
|
||||
if (!CodeInsightUtilBase.preparePsiElementForWrite(myTag)) return;
|
||||
myTag.delete();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.jsp.JspFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -43,7 +44,7 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv
|
||||
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
|
||||
for (final AbstractTreeNode child : children) {
|
||||
Object o = child.getValue();
|
||||
if (o instanceof PsiClassOwner) {
|
||||
if (o instanceof PsiClassOwner && !(o instanceof JspFile)) {
|
||||
final ViewSettings settings1 = ((ProjectViewNode)parent).getSettings();
|
||||
final PsiClassOwner classOwner = (PsiClassOwner)o;
|
||||
final VirtualFile file = classOwner.getVirtualFile();
|
||||
@@ -64,8 +65,8 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv
|
||||
}
|
||||
}
|
||||
|
||||
PsiClass[] classes = classOwner.getClasses();
|
||||
if (fileInRoots(file)) {
|
||||
PsiClass[] classes = classOwner.getClasses();
|
||||
if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) &&
|
||||
(file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) {
|
||||
result.add(new ClassTreeNode(myProject, classes[0], settings1));
|
||||
|
||||
@@ -39,10 +39,7 @@ import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.ex.PathUtilEx;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.SourceFolder;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -62,6 +59,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -280,13 +278,21 @@ public class JavadocConfiguration implements ModuleRunProfile, JDOMExternalizabl
|
||||
}
|
||||
writer.println("-sourcepath");
|
||||
final PathsList pathsList = OrderEnumerator.orderEntries(myProject).withoutSdk().withoutLibraries().getSourcePathsList();
|
||||
final String sourcePath = StringUtil.join(pathsList.getPathList(), new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String path) {
|
||||
return FileUtil.toSystemIndependentName(path);
|
||||
final List<VirtualFile> files = pathsList.getRootDirs();
|
||||
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
final StringBuilder sourcePath = new StringBuilder();
|
||||
boolean start = true;
|
||||
for (VirtualFile file : files) {
|
||||
if (!myGenerationOptions.isIncludeTestSource() && fileIndex.isInTestSourceContent(file)) continue;
|
||||
if (start) {
|
||||
start = false;
|
||||
}
|
||||
}, File.pathSeparator);
|
||||
writer.println(GeneralCommandLine.quote(sourcePath));
|
||||
else {
|
||||
sourcePath.append(File.pathSeparator);
|
||||
}
|
||||
sourcePath.append(file.getPath());
|
||||
}
|
||||
writer.println(GeneralCommandLine.quote(sourcePath.toString()));
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
|
||||
@@ -85,8 +85,7 @@ public class ClassLiteralGetter {
|
||||
try {
|
||||
resultSet.consume(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(new ClassLiteralLookupElement((PsiClassType)type, context)));
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
catch (IncorrectOperationException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -32,6 +32,7 @@ import com.intellij.psi.impl.source.DummyHolder;
|
||||
import com.intellij.psi.impl.source.DummyHolderFactory;
|
||||
import com.intellij.psi.impl.source.JavaDummyElement;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.FileElement;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
@@ -234,7 +235,7 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
|
||||
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
|
||||
if (!(element instanceof PsiMethod)) {
|
||||
throw new IncorrectOperationException("Incorrect method \"" + text + "\" (" + element + ").");
|
||||
throw newException("Incorrect method \"" + text + "\".", holder);
|
||||
}
|
||||
return (PsiMethod)element;
|
||||
}
|
||||
@@ -453,4 +454,17 @@ public class PsiJavaParserFacadeImpl extends PsiParserFacadeImpl implements PsiJ
|
||||
private static LanguageLevel level(@Nullable final PsiElement context) {
|
||||
return context != null ? PsiUtil.getLanguageLevel(context) : LanguageLevel.HIGHEST;
|
||||
}
|
||||
|
||||
private static IncorrectOperationException newException(final String msg, final DummyHolder holder) {
|
||||
final FileElement root = holder.getTreeElement();
|
||||
if (root instanceof JavaDummyElement) {
|
||||
final Throwable cause = ((JavaDummyElement)root).getParserError();
|
||||
if (cause != null) {
|
||||
return new IncorrectOperationException(msg) {
|
||||
@Override public Throwable getCause() { return cause; }
|
||||
};
|
||||
}
|
||||
}
|
||||
return new IncorrectOperationException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -19,6 +19,7 @@ import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.InheritanceImplUtil;
|
||||
import com.intellij.psi.impl.PsiClassImplUtil;
|
||||
@@ -395,43 +396,64 @@ public class ClsClassImpl extends ClsRepositoryPsiElement<PsiClassStub<?>> imple
|
||||
public void setMirror(@NotNull TreeElement element) {
|
||||
setMirrorCheckingType(element, null);
|
||||
|
||||
PsiClass mirror = (PsiClass)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
PsiClass mirror = SourceTreeToPsiMap.treeToPsiNotNull(element);
|
||||
|
||||
final PsiDocComment docComment = getDocComment();
|
||||
PsiDocComment docComment = getDocComment();
|
||||
if (docComment != null) {
|
||||
((ClsElementImpl)docComment).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
((ClsElementImpl)docComment).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getDocComment()));
|
||||
}
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
((ClsElementImpl)getModifierList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getModifierList()));
|
||||
((ClsElementImpl)getNameIdentifier()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameIdentifier()));
|
||||
if (!isAnnotationType() && !isEnum()) {
|
||||
((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
((ClsElementImpl)getExtendsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getExtendsList()));
|
||||
}
|
||||
((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
((ClsElementImpl)getImplementsList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getImplementsList()));
|
||||
((ClsElementImpl)getTypeParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getTypeParameterList()));
|
||||
|
||||
Ref<Boolean> extLog = Ref.create(true);
|
||||
|
||||
PsiField[] fields = getFields();
|
||||
PsiField[] mirrorFields = mirror.getFields();
|
||||
if (LOG.assertTrue(fields.length == mirrorFields.length)) {
|
||||
if (fields.length == mirrorFields.length) {
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
((ClsElementImpl)fields[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorFields[i]));
|
||||
((ClsElementImpl)fields[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorFields[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(this, mirror, "fields:" + fields.length + "!=" + mirrorFields.length, extLog);
|
||||
}
|
||||
|
||||
PsiMethod[] methods = getMethods();
|
||||
PsiMethod[] mirrorMethods = mirror.getMethods();
|
||||
if (LOG.assertTrue(methods.length == mirrorMethods.length)) {
|
||||
if (methods.length == mirrorMethods.length) {
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
((ClsElementImpl)methods[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorMethods[i]));
|
||||
((ClsElementImpl)methods[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorMethods[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(this, mirror, "methods:" + methods.length + "!=" + mirrorMethods.length, extLog);
|
||||
}
|
||||
|
||||
PsiClass[] classes = getInnerClasses();
|
||||
PsiClass[] mirrorClasses = mirror.getInnerClasses();
|
||||
if (LOG.assertTrue(classes.length == mirrorClasses.length)) {
|
||||
if (classes.length == mirrorClasses.length) {
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
((ClsElementImpl)classes[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorClasses[i]));
|
||||
((ClsElementImpl)classes[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorClasses[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
log(this, mirror, "classes:" + classes.length + "!=" + mirrorClasses.length, extLog);
|
||||
}
|
||||
}
|
||||
|
||||
private static void log(@NotNull ClsClassImpl stub, @NotNull PsiClass mirror, @NotNull String message, @NotNull Ref<Boolean> verbose) {
|
||||
LOG.error(message + "; file:" + stub.getContainingFile().getName());
|
||||
if (verbose.get()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
stub.appendMirrorText(0, builder);
|
||||
LOG.error("\nStub:\n" + builder.toString() + "\nMirror:\n" + mirror.getText());
|
||||
verbose.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -30,6 +30,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ClsElementImpl extends PsiElementBase implements PsiCompiledElement {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClsElementImpl");
|
||||
@@ -233,7 +234,7 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setMirrorCheckingType(@NotNull TreeElement element, IElementType type) {
|
||||
protected void setMirrorCheckingType(@NotNull TreeElement element, @Nullable IElementType type) {
|
||||
if (CHECK_MIRROR_ENABLED) {
|
||||
LOG.assertTrue(myMirror == null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -31,6 +31,7 @@ public class JavaDummyElement extends FileElement {
|
||||
private final JavaParserUtil.ParserWrapper myParser;
|
||||
private final LanguageLevel myLanguageLevel;
|
||||
private final boolean myConsumeAll;
|
||||
private Throwable myParserError = null;
|
||||
|
||||
public JavaDummyElement(@Nullable final CharSequence text,
|
||||
@NotNull final JavaParserUtil.ParserWrapper parser,
|
||||
@@ -68,6 +69,7 @@ public class JavaDummyElement extends FileElement {
|
||||
return super.getFirstChildNode();
|
||||
}
|
||||
catch (AssertionError e) {
|
||||
myParserError = e;
|
||||
return null; // masquerade parser errors
|
||||
}
|
||||
}
|
||||
@@ -78,7 +80,13 @@ public class JavaDummyElement extends FileElement {
|
||||
return super.getLastChildNode();
|
||||
}
|
||||
catch (AssertionError e) {
|
||||
myParserError = e;
|
||||
return null; // masquerade parser errors
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Throwable getParserError() {
|
||||
return myParserError;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -559,9 +559,8 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
}
|
||||
|
||||
final boolean preserveQualification = CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES && isFullyQualified();
|
||||
final PsiManager manager = aClass.getManager();
|
||||
final PsiReferenceParameterList parameterList = getParameterList();
|
||||
String text = (parameterList != null ? qName + parameterList.getText() : qName);
|
||||
String text = parameterList == null ? qName : qName + parameterList.getText();
|
||||
PsiJavaCodeReferenceElement ref = facade.getParserFacade().createReferenceFromText(text, getParent());
|
||||
getTreeParent().replaceChildInternal(this, (TreeElement)ref.getNode());
|
||||
if (!preserveQualification /*&& (TreeUtil.findParent(ref, ElementType.DOC_COMMENT) == null)*/) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -158,7 +158,7 @@ public class CopyClassesHandler implements CopyHandlerDelegate {
|
||||
public void doClone(PsiElement element) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.copyClass");
|
||||
PsiClass[] classes = getTopLevelClasses(element);
|
||||
LOG.assertTrue(classes != null && classes.length == 1);
|
||||
LOG.assertTrue(classes != null && classes.length == 1, Arrays.toString(classes));
|
||||
Project project = element.getProject();
|
||||
|
||||
CopyClassDialog dialog = new CopyClassDialog(classes[0], null, project, true);
|
||||
|
||||
+53
-31
@@ -29,8 +29,10 @@ import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -47,6 +49,8 @@ import com.intellij.refactoring.util.occurences.OccurenceManager;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.ui.TitlePanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -131,12 +135,6 @@ public class InplaceIntroduceConstantPopup {
|
||||
myWholePanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0 , 0, 0), 0, 0);
|
||||
|
||||
final TitlePanel titlePanel = new TitlePanel();
|
||||
titlePanel.setBorder(null);
|
||||
titlePanel.setText(IntroduceConstantHandler.REFACTORING_NAME);
|
||||
gc.gridwidth = 2;
|
||||
myWholePanel.add(titlePanel, gc);
|
||||
|
||||
gc.gridwidth = 1;
|
||||
gc.gridy = 1;
|
||||
myWholePanel.add(createLeftPanel(), gc);
|
||||
@@ -206,8 +204,12 @@ public class InplaceIntroduceConstantPopup {
|
||||
|
||||
private JPanel createLeftPanel() {
|
||||
final JPanel left = new JPanel(new GridBagLayout());
|
||||
String initialVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY;
|
||||
if (initialVisibility == null) {
|
||||
initialVisibility = PsiModifier.PUBLIC;
|
||||
}
|
||||
myVisibilityCombo = createVisibilityCombo(left, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(6,5,0,0), 0, 0),
|
||||
myProject);
|
||||
myProject, initialVisibility);
|
||||
myMoveToAnotherClassCb = new JCheckBox("Move to another class");
|
||||
myMoveToAnotherClassCb.setMnemonic('m');
|
||||
myMoveToAnotherClassCb.setFocusable(false);
|
||||
@@ -217,7 +219,8 @@ public class InplaceIntroduceConstantPopup {
|
||||
|
||||
public static JComboBox createVisibilityCombo(final JPanel left,
|
||||
final GridBagConstraints lgc,
|
||||
final Project project) {
|
||||
final Project project,
|
||||
@NotNull final String initialVisibility) {
|
||||
|
||||
final JLabel label = new JLabel("Visibility:");
|
||||
label.setDisplayedMnemonic('V');
|
||||
@@ -231,50 +234,64 @@ public class InplaceIntroduceConstantPopup {
|
||||
}
|
||||
});
|
||||
label.setLabelFor(visibilityCombo);
|
||||
visibilityCombo.setSelectedItem(JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY);
|
||||
visibilityCombo.setSelectedItem(initialVisibility);
|
||||
|
||||
appendActions(visibilityCombo, project);
|
||||
lgc.gridx++;
|
||||
lgc.insets.top = 2;
|
||||
lgc.insets.left = 0;
|
||||
lgc.insets.left = 2;
|
||||
left.add(visibilityCombo, lgc);
|
||||
return visibilityCombo;
|
||||
}
|
||||
|
||||
public static void appendActions(final JComboBox visibilityCombo, final Project project) {
|
||||
public static void appendActions(final JComboBox comboBox, final Project project) {
|
||||
final boolean toggleStrategy = !UIUtil.isUnderAquaLookAndFeel();
|
||||
final boolean[] moveFocusBack = new boolean[] {true};
|
||||
visibilityCombo.addFocusListener(new FocusAdapter() {
|
||||
comboBox.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (!moveFocusBack[0]) {
|
||||
moveFocusBack[0] = true;
|
||||
return;
|
||||
}
|
||||
final int size = visibilityCombo.getModel().getSize();
|
||||
int next = visibilityCombo.getSelectedIndex() + 1;
|
||||
if (next < 0 || next >= size) {
|
||||
if (!UISettings.getInstance().CYCLE_SCROLLING) {
|
||||
return;
|
||||
|
||||
if (toggleStrategy) {
|
||||
final int size = comboBox.getModel().getSize();
|
||||
int next = comboBox.getSelectedIndex() + 1;
|
||||
if (next < 0 || next >= size) {
|
||||
if (!UISettings.getInstance().CYCLE_SCROLLING) {
|
||||
return;
|
||||
}
|
||||
next = (next + size) % size;
|
||||
}
|
||||
comboBox.setSelectedIndex(next);
|
||||
ToolWindowManager.getInstance(project).activateEditorComponent();
|
||||
}
|
||||
else {
|
||||
JBPopupFactory popupFactory = JBPopupFactory.getInstance();
|
||||
boolean fromTheSameBalloon = popupFactory.getParentBalloonFor(e.getComponent()) == popupFactory.getParentBalloonFor(e.getOppositeComponent());
|
||||
if (!fromTheSameBalloon) {
|
||||
comboBox.showPopup();
|
||||
}
|
||||
next = (next + size) % size;
|
||||
}
|
||||
visibilityCombo.setSelectedIndex(next);
|
||||
ToolWindowManager.getInstance(project).activateEditorComponent();
|
||||
}
|
||||
});
|
||||
visibilityCombo.addMouseListener(new MouseAdapter() {
|
||||
comboBox.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
moveFocusBack[0] = false;
|
||||
}
|
||||
});
|
||||
visibilityCombo.addKeyListener(new KeyAdapter() {
|
||||
comboBox.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
moveFocusBack[0] = true;
|
||||
if (!toggleStrategy && e.getKeyCode() == KeyEvent.VK_ESCAPE && e.getModifiers() == 0) {
|
||||
ToolWindowManager.getInstance(project).activateEditorComponent();
|
||||
}
|
||||
}
|
||||
});
|
||||
visibilityCombo.addActionListener(new ActionListener() {
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
moveFocusBack[0] = true;
|
||||
@@ -382,7 +399,7 @@ public class InplaceIntroduceConstantPopup {
|
||||
myEditor, field, false,
|
||||
myTypeSelectorManager.getTypesForAll().length > 1,
|
||||
myExpr != null && myExpr.isPhysical() ? myEditor.getDocument().createRangeMarker(myExpr.getTextRange()) : null, InplaceIntroduceConstantPopup.this.getOccurrenceMarkers(),
|
||||
IntroduceConstantHandler.REFACTORING_NAME);
|
||||
IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME);
|
||||
|
||||
myDefaultParameterTypePointer =
|
||||
SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType());
|
||||
@@ -437,7 +454,7 @@ public class InplaceIntroduceConstantPopup {
|
||||
@Override
|
||||
protected void moveOffsetAfter(boolean success) {
|
||||
if (success) {
|
||||
if (myLocalVariable == null && myExpr == null) {
|
||||
if (myLocalVariable == null && myExpr == null || myConstantName == null) {
|
||||
super.moveOffsetAfter(false);
|
||||
return;
|
||||
}
|
||||
@@ -549,12 +566,17 @@ public class InplaceIntroduceConstantPopup {
|
||||
myReplaceAllCb.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences);
|
||||
startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
Runnable restartTemplateRunnable = new Runnable() {
|
||||
public void run() {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences);
|
||||
startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
}
|
||||
};
|
||||
CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceConstantHandler.REFACTORING_NAME, IntroduceConstantHandler.REFACTORING_NAME);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+20
-14
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.intellij.refactoring.introduceField;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.intention.impl.TypeExpression;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
@@ -36,7 +39,6 @@ import com.intellij.refactoring.introduceParameter.AbstractInplaceIntroducer;
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.occurences.OccurenceManager;
|
||||
import com.intellij.ui.TitlePanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -125,15 +127,10 @@ public class InplaceIntroduceFieldPopup {
|
||||
myWholePanel = new JPanel(new GridBagLayout());
|
||||
myWholePanel.setBorder(null);
|
||||
|
||||
final TitlePanel titlePanel = new TitlePanel();
|
||||
titlePanel.setBorder(null);
|
||||
titlePanel.setText(IntroduceFieldHandler.REFACTORING_NAME);
|
||||
|
||||
GridBagConstraints gc =
|
||||
new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0,0,0,0), 0, 0);
|
||||
|
||||
myWholePanel.add(titlePanel, gc);
|
||||
|
||||
gc.gridy++;
|
||||
gc.insets.top = 5;
|
||||
@@ -253,7 +250,7 @@ public class InplaceIntroduceFieldPopup {
|
||||
myEditor, psiVariable, false,
|
||||
myTypeSelectorManager.getTypesForAll().length > 1,
|
||||
myInitializerExpression != null && myInitializerExpression.isPhysical() ? myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null, InplaceIntroduceFieldPopup.this.getOccurrenceMarkers(),
|
||||
IntroduceFieldHandler.REFACTORING_NAME);
|
||||
IntroduceFieldHandler.REFACTORING_NAME, IntroduceFieldHandler.REFACTORING_NAME);
|
||||
myDefaultParameterTypePointer =
|
||||
SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType());
|
||||
myFieldRangeStart = myEditor.getDocument().createRangeMarker(psiVariable.getTextRange());
|
||||
@@ -315,12 +312,21 @@ public class InplaceIntroduceFieldPopup {
|
||||
myIntroduceFieldPanel.addOccurrenceListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences);
|
||||
startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
final Runnable restartTemplate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final TemplateState templateState =
|
||||
TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences);
|
||||
startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
}
|
||||
};
|
||||
CommandProcessor.getInstance().executeCommand(myProject, restartTemplate,
|
||||
IntroduceFieldHandler.REFACTORING_NAME,
|
||||
IntroduceFieldHandler.REFACTORING_NAME);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -344,7 +350,7 @@ public class InplaceIntroduceFieldPopup {
|
||||
@Override
|
||||
protected void moveOffsetAfter(boolean success) {
|
||||
if (success) {
|
||||
if (myLocalVariable == null && myInitializerExpression == null) {
|
||||
if (myLocalVariable == null && myInitializerExpression == null || myFieldName == null) {
|
||||
super.moveOffsetAfter(false);
|
||||
return;
|
||||
}
|
||||
|
||||
+6
-8
@@ -52,13 +52,6 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel {
|
||||
occurrences, allowInitInMethod, allowInitInMethodIfAll, typeSelectorManager);
|
||||
}
|
||||
|
||||
protected void initializeControls(PsiExpression initializerExpression, BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) {
|
||||
super.initializeControls(initializerExpression, ourLastInitializerPlace);
|
||||
|
||||
String ourLastVisibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY;
|
||||
setVisibility(ourLastVisibility);
|
||||
}
|
||||
|
||||
protected void initializeInitializerPlace(PsiExpression initializerExpression,
|
||||
BaseExpressionToFieldHandler.InitializationPlace ourLastInitializerPlace) {
|
||||
if (initializerExpression != null) {
|
||||
@@ -179,7 +172,12 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel {
|
||||
gridBagConstraints.gridy = 1;
|
||||
gridBagConstraints.insets.top = 8;
|
||||
gridBagConstraints.insets.left = 5;
|
||||
myVisibilityCombo = InplaceIntroduceConstantPopup.createVisibilityCombo(groupPanel, gridBagConstraints, myParentClass.getProject());
|
||||
String visibility = JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY;
|
||||
if (visibility == null) {
|
||||
visibility = PsiModifier.PRIVATE;
|
||||
}
|
||||
myVisibilityCombo = InplaceIntroduceConstantPopup.createVisibilityCombo(groupPanel, gridBagConstraints, myParentClass.getProject(),
|
||||
visibility);
|
||||
|
||||
mainPanel.add(groupPanel, BorderLayout.CENTER);
|
||||
|
||||
|
||||
+2
-2
@@ -57,8 +57,8 @@ public abstract class AbstractInplaceIntroducer extends VariableInplaceIntroduce
|
||||
boolean cantChangeFinalModifier,
|
||||
boolean hasTypeSuggestion,
|
||||
RangeMarker exprMarker,
|
||||
List<RangeMarker> occurrenceMarkers, String commandName) {
|
||||
super(project, expression, editor, elementToRename, cantChangeFinalModifier, hasTypeSuggestion, exprMarker, occurrenceMarkers, commandName);
|
||||
List<RangeMarker> occurrenceMarkers, String commandName, String title) {
|
||||
super(project, expression, editor, elementToRename, cantChangeFinalModifier, hasTypeSuggestion, exprMarker, occurrenceMarkers, commandName, title);
|
||||
}
|
||||
|
||||
protected abstract boolean isReplaceAllOccurrences();
|
||||
|
||||
+24
-23
@@ -111,12 +111,6 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
final GridBagConstraints gc =
|
||||
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
|
||||
|
||||
final TitlePanel titlePanel = new TitlePanel();
|
||||
titlePanel.setBorder(null);
|
||||
titlePanel.setText(IntroduceParameterHandler.REFACTORING_NAME);
|
||||
gc.gridwidth = 2;
|
||||
myWholePanel.add(titlePanel, gc);
|
||||
|
||||
gc.insets = new Insets(0, 5, 0, 0);
|
||||
gc.gridwidth = 1;
|
||||
gc.fill = GridBagConstraints.NONE;
|
||||
@@ -255,7 +249,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()),
|
||||
myEditor, parameter, myMustBeFinal,
|
||||
myTypeSelectorManager.getTypesForAll().length > 1, myExprMarker, InplaceIntroduceParameterPopup.this.getOccurrenceMarkers(),
|
||||
IntroduceParameterHandler.REFACTORING_NAME);
|
||||
IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME);
|
||||
myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(parameter.getType());
|
||||
}
|
||||
|
||||
@@ -263,12 +257,14 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
protected JComponent getComponent() {
|
||||
if (!myInitialized) {
|
||||
myInitialized = true;
|
||||
myWholePanel.add(myCanBeFinal,
|
||||
new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
|
||||
GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0));
|
||||
if (myHasWriteAccess) {
|
||||
myCanBeFinal.setSelected(false);
|
||||
myCanBeFinal.setEnabled(false);
|
||||
if (myCanBeFinalCb != null) {
|
||||
myWholePanel.add(myCanBeFinalCb,
|
||||
new GridBagConstraints(0, myCbReplaceAllOccurences == null ? 2 : 3, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
|
||||
GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0));
|
||||
if (myHasWriteAccess) {
|
||||
myCanBeFinalCb.setSelected(false);
|
||||
myCanBeFinalCb.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return myWholePanel;
|
||||
@@ -304,7 +300,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
protected void saveSettings(PsiVariable psiVariable) {
|
||||
final JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
|
||||
InplaceIntroduceParameterPopup.super.saveSettings(settings);
|
||||
if (myCanBeFinal.isEnabled()) {
|
||||
if (myCanBeFinalCb != null && myCanBeFinalCb.isEnabled()) {
|
||||
settings.INTRODUCE_PARAMETER_CREATE_FINALS = psiVariable.hasModifierProperty(PsiModifier.FINAL);
|
||||
}
|
||||
TypeSelectorManagerImpl.typeSelected(psiVariable.getType(), myDefaultParameterTypePointer.getType());
|
||||
@@ -323,7 +319,7 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
isDeleteLocalVariable = isDeleteLocalVariable();
|
||||
}
|
||||
|
||||
if (!myMethod.isValid() || myLocalVar == null && myExpr == null) {
|
||||
if (!myMethod.isValid() || myParameterName == null || myLocalVar == null && myExpr == null) {
|
||||
super.moveOffsetAfter(false);
|
||||
return;
|
||||
}
|
||||
@@ -430,14 +426,19 @@ class InplaceIntroduceParameterPopup extends IntroduceParameterSettingsUI {
|
||||
protected void updateControls(JCheckBox[] removeParamsCb) {
|
||||
super.updateControls(removeParamsCb);
|
||||
if (myParameterIndex < 0) return;
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
|
||||
final PsiParameter parameter = getParameter();
|
||||
final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL);
|
||||
templateState.gotoEnd(true);
|
||||
startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier);
|
||||
}
|
||||
Runnable restartTemplateRunnable = new Runnable() {
|
||||
public void run() {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
|
||||
final PsiParameter parameter = getParameter();
|
||||
final boolean hasFinalModifier = parameter.hasModifierProperty(PsiModifier.FINAL);
|
||||
templateState.gotoEnd(true);
|
||||
startIntroduceTemplate(isReplaceAllOccurences(), hasFinalModifier);
|
||||
}
|
||||
}
|
||||
};
|
||||
CommandProcessor.getInstance().executeCommand(myProject, restartTemplateRunnable, IntroduceParameterHandler.REFACTORING_NAME, IntroduceParameterHandler.REFACTORING_NAME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -476,10 +476,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
final PsiVariable elementToRename = variable.get().getElement();
|
||||
if (elementToRename != null) {
|
||||
editor.getCaretModel().moveToOffset(elementToRename.getTextOffset());
|
||||
final boolean cantChangeFinalModifier = hasWriteAccess || (inFinalContext && choice == OccurrencesChooser.ReplaceChoice.ALL);
|
||||
final boolean cantChangeFinalModifier = (hasWriteAccess || inFinalContext) && choice == OccurrencesChooser.ReplaceChoice.ALL;
|
||||
final VariableInplaceRenamer renamer =
|
||||
new VariableInplaceIntroducer(project, expression, editor, elementToRename, cantChangeFinalModifier,
|
||||
typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME);
|
||||
typeSelectorManager.getTypesForAll().length > 1, exprMarker, occurrenceMarkers, IntroduceVariableBase.REFACTORING_NAME, IntroduceVariableBase.REFACTORING_NAME);
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
||||
renamer.performInplaceRename(false, new LinkedHashSet<String>(Arrays.asList(suggestedName.names)));
|
||||
}
|
||||
@@ -771,9 +771,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
final String variableName = suggestedName.names[0];
|
||||
final boolean replaceAll =
|
||||
replaceChoice == OccurrencesChooser.ReplaceChoice.ALL || replaceChoice == OccurrencesChooser.ReplaceChoice.NO_WRITE;
|
||||
final boolean declareFinal =
|
||||
!anyAssignmentLHS && (replaceAll &&
|
||||
declareFinalIfAll || createFinals(project));
|
||||
final boolean declareFinal = replaceAll && (declareFinalIfAll || !anyAssignmentLHS) || createFinals(project);
|
||||
final boolean replaceWrite = anyAssignmentLHS && replaceChoice == OccurrencesChooser.ReplaceChoice.ALL;
|
||||
return new IntroduceVariableSettings() {
|
||||
@Override
|
||||
|
||||
+8
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -104,11 +104,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
|
||||
}
|
||||
|
||||
public boolean isDeclareFinal() {
|
||||
if (myCbFinal.isEnabled()) {
|
||||
return myCbFinalState;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return myCbFinal.isEnabled() && myCbFinalState;
|
||||
}
|
||||
|
||||
public boolean isReplaceLValues() {
|
||||
@@ -207,6 +203,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
|
||||
gbConstraints.insets = new Insets(0, 8, 0, 0);
|
||||
gbConstraints.gridy++;
|
||||
panel.add(myCbReplaceWrite, gbConstraints);
|
||||
myCbReplaceWrite.addItemListener(myReplaceAllListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +249,11 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
|
||||
if (myDeclareFinalIfAll && myCbReplaceAll != null && myCbReplaceAll.isSelected()) {
|
||||
myCbFinal.setEnabled(false);
|
||||
myCbFinal.setSelected(true);
|
||||
} else {
|
||||
} else if (myCbReplaceWrite != null && myCbReplaceWrite.isEnabled() && myCbReplaceWrite.isSelected()) {
|
||||
myCbFinal.setEnabled(false);
|
||||
myCbFinal.setSelected(false);
|
||||
}
|
||||
else {
|
||||
myCbFinal.setEnabled(true);
|
||||
myCbFinal.setSelected(myCbFinalState);
|
||||
}
|
||||
|
||||
+26
-18
@@ -74,8 +74,9 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
private final List<RangeMarker> myOccurrenceMarkers;
|
||||
private final SmartTypePointer myDefaultType;
|
||||
|
||||
protected JCheckBox myCanBeFinal;
|
||||
protected JCheckBox myCanBeFinalCb;
|
||||
private Balloon myBalloon;
|
||||
private String myTitle;
|
||||
|
||||
public VariableInplaceIntroducer(final Project project,
|
||||
final TypeExpression expression,
|
||||
@@ -85,12 +86,14 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
final boolean hasTypeSuggestion,
|
||||
final RangeMarker exprMarker,
|
||||
final List<RangeMarker> occurrenceMarkers,
|
||||
final String commandName) {
|
||||
final String commandName,
|
||||
final String title) {
|
||||
super(elementToRename, editor);
|
||||
myProject = project;
|
||||
myEditor = editor;
|
||||
myElementToRename = elementToRename;
|
||||
myExpression = expression;
|
||||
myTitle = title;
|
||||
|
||||
myExprMarker = exprMarker;
|
||||
myOccurrenceMarkers = occurrenceMarkers;
|
||||
@@ -105,10 +108,10 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()]));
|
||||
setAdvertisementText(getAdvertisementText(declarationStatement, defaultType, hasTypeSuggestion));
|
||||
if (!cantChangeFinalModifier) {
|
||||
myCanBeFinal = new NonFocusableCheckBox("Declare final");
|
||||
myCanBeFinal.setSelected(createFinals());
|
||||
myCanBeFinal.setMnemonic('f');
|
||||
myCanBeFinal.addActionListener(new FinalListener(project, commandName));
|
||||
myCanBeFinalCb = new NonFocusableCheckBox("Declare final");
|
||||
myCanBeFinalCb.setSelected(createFinals());
|
||||
myCanBeFinalCb.setMnemonic('f');
|
||||
myCanBeFinalCb.addActionListener(new FinalListener(project, commandName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +151,11 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
@Nullable
|
||||
protected PsiVariable getVariable() {
|
||||
final PsiDeclarationStatement declarationStatement = myPointer.getElement();
|
||||
return declarationStatement != null ? (PsiVariable)declarationStatement.getDeclaredElements()[0] : null;
|
||||
if (declarationStatement != null) {
|
||||
PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
|
||||
return declaredElements.length == 0 ? null : (PsiVariable)declaredElements[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,16 +243,12 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
|
||||
@Nullable
|
||||
protected JComponent getComponent() {
|
||||
if (myCanBeFinalCb == null) return null;
|
||||
final JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBorder(null);
|
||||
|
||||
final TitlePanel titlePanel = new TitlePanel();
|
||||
titlePanel.setBorder(null);
|
||||
titlePanel.setText(IntroduceVariableBase.REFACTORING_NAME);
|
||||
panel.add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
|
||||
|
||||
if (myCanBeFinal != null) {
|
||||
panel.add(myCanBeFinal, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
if (myCanBeFinalCb != null) {
|
||||
panel.add(myCanBeFinalCb, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
}
|
||||
|
||||
panel.add(Box.createVerticalBox(), new GridBagConstraints(0, 2, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0));
|
||||
@@ -359,18 +362,23 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
}
|
||||
|
||||
|
||||
protected String getTitle() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
private void showBalloon() {
|
||||
final JComponent component = getComponent();
|
||||
if (component == null) return;
|
||||
if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
|
||||
final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(component);
|
||||
balloonBuilder.setFadeoutTime(0)
|
||||
.setFillColor(IdeTooltipManager.GRAPHITE_COLOR.brighter().brighter())
|
||||
.setAnimationCycle(0)
|
||||
.setFillColor(UIManager.getColor("Panel.background"))
|
||||
.setAnimationCycle(100)
|
||||
.setHideOnClickOutside(false)
|
||||
.setHideOnKeyOutside(false)
|
||||
.setHideOnAction(false)
|
||||
.setCloseButtonEnabled(true);
|
||||
.setCloseButtonEnabled(true)
|
||||
.setTitle(getTitle());
|
||||
|
||||
final RelativePoint target = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor);
|
||||
final Point screenPoint = target.getScreenPoint();
|
||||
@@ -393,7 +401,7 @@ public class VariableInplaceIntroducer extends VariableInplaceRenamer {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
perform(myCanBeFinal.isSelected());
|
||||
perform(myCanBeFinalCb.isSelected());
|
||||
}
|
||||
|
||||
public void perform(final boolean generateFinal) {
|
||||
|
||||
+21
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.introduceparameterobject.usageInfo;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -103,9 +104,26 @@ public class MergeMethodArguments extends FixableUsageInfo {
|
||||
parametersInfo.add(new ParameterInfoImpl(i, parameters[i].getName(), parameters[i].getType()));
|
||||
}
|
||||
}
|
||||
final SmartPsiElementPointer<PsiMethod> meth = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(method);
|
||||
|
||||
new ChangeSignatureProcessor(method.getProject(), method, myKeepMethodAsDelegate, null, method.getName(), method.getReturnType(),
|
||||
parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()])).run();
|
||||
Runnable performChangeSignatureRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiMethod psiMethod = meth.getElement();
|
||||
if (psiMethod == null) return;
|
||||
final ChangeSignatureProcessor changeSignatureProcessor =
|
||||
new ChangeSignatureProcessor(psiMethod.getProject(), psiMethod,
|
||||
myKeepMethodAsDelegate, null, psiMethod.getName(),
|
||||
psiMethod.getReturnType(),
|
||||
parametersInfo.toArray(new ParameterInfoImpl[parametersInfo.size()]));
|
||||
changeSignatureProcessor.run();
|
||||
}
|
||||
};
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
performChangeSignatureRunnable.run();
|
||||
} else {
|
||||
ApplicationManager.getApplication().invokeLater(performChangeSignatureRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isParameterToMerge(int index) {
|
||||
|
||||
+1
@@ -156,6 +156,7 @@ public class BaseGenerateTestSupportMethodAction extends BaseGenerateAction {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
|
||||
PsiMethod method = generateDummyMethod(editor, file);
|
||||
if (method == null) return;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public final class IdeaAntLogger2 extends DefaultLogger {
|
||||
static SegmentedOutputStream ourOut;
|
||||
static SegmentedOutputStream ourErr;
|
||||
public static final char MESSAGE_CONTENT = 'M';
|
||||
public static final char EXCEPTION_CONTENT = 'X';
|
||||
@@ -116,19 +115,16 @@ public final class IdeaAntLogger2 extends DefaultLogger {
|
||||
}
|
||||
|
||||
public static void guardStreams() {
|
||||
if (ourErr != null && ourOut != null) return;
|
||||
PrintStream out = System.out;
|
||||
if (ourErr != null) {
|
||||
return;
|
||||
}
|
||||
PrintStream err = System.err;
|
||||
ourOut = new SegmentedOutputStream(out);
|
||||
ourErr = new SegmentedOutputStream(err);
|
||||
System.setOut(new PrintStream(ourOut));
|
||||
System.setErr(new PrintStream(ourErr));
|
||||
ourOut.sendStart();
|
||||
ourErr.sendStart();
|
||||
}
|
||||
|
||||
private void send(PacketWriter packet) {
|
||||
packet.sendThrough(ourOut);
|
||||
packet.sendThrough(ourErr);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,32 +30,42 @@ import java.util.Vector;
|
||||
*/
|
||||
public class IdeaInputHandler implements InputHandler {
|
||||
public void handleInput(InputRequest request) throws BuildException {
|
||||
String prompt = request.getPrompt();
|
||||
if (prompt == null) throw new BuildException("Prompt is null");
|
||||
SegmentedOutputStream out = IdeaAntLogger2.ourOut;
|
||||
SegmentedOutputStream err = IdeaAntLogger2.ourErr;
|
||||
if (out == null || err == null)
|
||||
final String prompt = request.getPrompt();
|
||||
if (prompt == null) {
|
||||
throw new BuildException("Prompt is null");
|
||||
}
|
||||
final SegmentedOutputStream err = IdeaAntLogger2.ourErr;
|
||||
if (err == null) {
|
||||
throw new BuildException("Selected InputHandler should be used by Intellij IDEA");
|
||||
PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
|
||||
}
|
||||
final PacketWriter packet = PacketFactory.ourInstance.createPacket(IdeaAntLogger2.INPUT_REQUEST);
|
||||
packet.appendLimitedString(prompt);
|
||||
if (request instanceof MultipleChoiceInputRequest) {
|
||||
Vector choices = ((MultipleChoiceInputRequest)request).getChoices();
|
||||
if (choices != null && choices.size() > 0) {
|
||||
int count = choices.size();
|
||||
packet.appendLong(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
for (int i = 0; i < count; i++) {
|
||||
packet.appendLimitedString((String)choices.elementAt(i));
|
||||
} else packet.appendLong(0);
|
||||
} else packet.appendLong(0);
|
||||
packet.sendThrough(out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
packet.appendLong(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
packet.appendLong(0);
|
||||
}
|
||||
packet.sendThrough(err);
|
||||
try {
|
||||
byte[] replayLength = readBytes(4);
|
||||
int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3];
|
||||
byte[] replay = readBytes(length);
|
||||
String input = new String(replay);
|
||||
final byte[] replayLength = readBytes(4);
|
||||
final int length = ((int)replayLength[0] << 24) | ((int)replayLength[1] << 16) | ((int)replayLength[2] << 8) | replayLength[3];
|
||||
final byte[] replay = readBytes(length);
|
||||
final String input = new String(replay);
|
||||
request.setInput(input);
|
||||
if (!request.isInputValid()) throw new BuildException("Invalid input: " + input);
|
||||
if (!request.isInputValid()) {
|
||||
throw new BuildException("Invalid input: " + input);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new BuildException(e);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class FooOCSomething {}
|
||||
class FooObjectCollector {}
|
||||
|
||||
class Foo {
|
||||
{
|
||||
FooOC<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add constructor parameter" "true"
|
||||
class A {
|
||||
private final int field;
|
||||
A(int field, String... strs) {
|
||||
this.field = field;<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add constructor parameter" "true"
|
||||
class A {
|
||||
private final int <caret>field;
|
||||
A(String... strs) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -761,7 +761,26 @@ public class Bar {
|
||||
assert myFixture.lookupElementStrings.containsAll(['private', 'protected'])
|
||||
}
|
||||
|
||||
public void testExactMatchesFirst() {
|
||||
myFixture.configureByText("a.java", """
|
||||
public class UTest {
|
||||
void nextWord() {}
|
||||
|
||||
void foo() {
|
||||
n<caret>
|
||||
}
|
||||
}""")
|
||||
type 'ew'
|
||||
assert myFixture.lookupElementStrings == ['new', 'nextWord']
|
||||
}
|
||||
|
||||
public void testUpdatePrefixMatchingOnTyping() {
|
||||
myFixture.addClass("class CertificateEncodingException {}")
|
||||
myFixture.addClass("class CertificateException {}")
|
||||
myFixture.configureByText 'a.java', 'class Foo {<caret>}'
|
||||
type 'CertificateExce'
|
||||
assert myFixture.lookupElementStrings == ['CertificateException', 'CertificateEncodingException']
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -209,6 +209,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "else", "element");
|
||||
}
|
||||
|
||||
public void testPreferMoreMatching() {
|
||||
checkPreferredItems(0, "FooOCSomething", "FooObjectCollector");
|
||||
}
|
||||
|
||||
public void testPreferSamePackageOverImported() {
|
||||
myFixture.addClass("package bar; public class Bar1 {}");
|
||||
myFixture.addClass("package bar; public class Bar2 {}");
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -68,16 +70,18 @@ public class WordCompletionTest extends CompletionTestCase {
|
||||
}};
|
||||
}
|
||||
};
|
||||
PsiReferenceRegistrarImpl registrar =
|
||||
ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
|
||||
try {
|
||||
ReferenceProvidersRegistry.getInstance().registerReferenceProvider(PsiLiteralExpression.class, softProvider);
|
||||
ReferenceProvidersRegistry.getInstance().registerReferenceProvider(PsiLiteralExpression.class, hardProvider);
|
||||
registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider);
|
||||
registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider);
|
||||
|
||||
configureByFile(BASE_PATH + "3.java");
|
||||
checkResultByFile(BASE_PATH + "3_after.java");
|
||||
}
|
||||
finally {
|
||||
ReferenceProvidersRegistry.getInstance().unregisterReferenceProvider(PsiLiteralExpression.class, softProvider);
|
||||
ReferenceProvidersRegistry.getInstance().unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider);
|
||||
registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider);
|
||||
registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -368,4 +368,27 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testAutoInsertImportForInnerClass() throws Throwable {
|
||||
@NonNls String text = "package x; class S { void f(ReadLock r){} } <caret> ";
|
||||
configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
|
||||
|
||||
try {
|
||||
List<HighlightInfo> errs = filter(doHighlighting(), HighlightSeverity.ERROR);
|
||||
assertEquals(1, errs.size());
|
||||
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
type("/* */");
|
||||
doHighlighting();
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-2
@@ -24,7 +24,6 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
|
||||
|
||||
public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
private String myIntention;
|
||||
|
||||
@Override
|
||||
@@ -54,5 +53,4 @@ public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/codeInsight/convertToBasicLatin/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.impl.win32.Win32LocalFileSystem;
|
||||
@@ -19,6 +20,22 @@ import java.util.Arrays;
|
||||
public class LocalFileSystemTest extends IdeaTestCase{
|
||||
private static final String KEY = "filesystem.useNative";
|
||||
|
||||
public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
stream.write(bom);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, charset);
|
||||
writer.write(content);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException {
|
||||
File temp = FileUtil.createTempFile("copy", "." + ext);
|
||||
setContentOnDisk(temp, bom, content, charset);
|
||||
|
||||
myFilesToDelete.add(temp);
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp);
|
||||
}
|
||||
|
||||
public void testChildrenAccessedButNotCached() throws Exception{
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
@@ -116,7 +133,7 @@ public class LocalFileSystemTest extends IdeaTestCase{
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
try {
|
||||
File fromDir = createTempDirectory();
|
||||
File toDir = createTempDirectory();
|
||||
|
||||
@@ -132,7 +149,7 @@ public class LocalFileSystemTest extends IdeaTestCase{
|
||||
assertEquals(newName, copy.getName());
|
||||
assertTrue(Arrays.equals(byteContent, copy.contentsToByteArray()));
|
||||
}
|
||||
catch(Exception e){
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
@@ -222,22 +239,22 @@ public class LocalFileSystemTest extends IdeaTestCase{
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void setContentOnDisk(File file, byte[] bom, String content, Charset charset) throws IOException {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
stream.write(bom);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, charset);
|
||||
writer.write(content);
|
||||
writer.close();
|
||||
}
|
||||
public void testFindRoot() {
|
||||
VirtualFile file = LocalFileSystem.getInstance().findFileByPath("wrong_path");
|
||||
assertNull(file);
|
||||
|
||||
public static VirtualFile createTempFile(@NonNls String ext, byte[] bom, @NonNls String content, Charset charset) throws IOException {
|
||||
File temp = FileUtil.createTempFile("copy", "." + ext);
|
||||
setContentOnDisk(temp, bom, content, charset);
|
||||
if (SystemInfo.isWindows && new File("c:").exists()) {
|
||||
VirtualFile root = LocalFileSystem.getInstance().findFileByPath("c:");
|
||||
assertNotNull(root);
|
||||
}
|
||||
if (SystemInfo.isUnix) {
|
||||
VirtualFile root = LocalFileSystem.getInstance().findFileByPath("/");
|
||||
assertNotNull(root);
|
||||
}
|
||||
|
||||
myFilesToDelete.add(temp);
|
||||
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp);
|
||||
VirtualFile root = LocalFileSystem.getInstance().findFileByPath("");
|
||||
assertNotNull(root);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -57,7 +57,10 @@ abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCa
|
||||
|
||||
protected void joinCompletion() {
|
||||
for (j in 1..4000) {
|
||||
LookupImpl l = LookupManager.getInstance(project).activeLookup
|
||||
LookupImpl l = null
|
||||
edt {
|
||||
l = LookupManager.getInstance(project).activeLookup
|
||||
}
|
||||
if (!l || !l.calculating) {
|
||||
joinAlarm() // for invokeLater in CompletionProgressIndicator.stop()
|
||||
return
|
||||
|
||||
+10
-4
@@ -23,6 +23,7 @@ import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -61,7 +62,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
final String relativePath = quickFixTestCase.getBasePath() + "/" + BEFORE_PREFIX + testName;
|
||||
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
|
||||
final File testFile = new File(testFullPath);
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
CommandProcessor.getInstance().executeCommand(quickFixTestCase.getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -263,17 +264,22 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
|
||||
@Override
|
||||
public void configureFromFileText(String name, String contents) throws IOException {
|
||||
LightCodeInsightTestCase.configureFromFileText(name, contents);
|
||||
LightQuickFixTestCase.configureFromFileText(name, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiFile getFile() {
|
||||
return LightCodeInsightTestCase.getFile();
|
||||
return LightQuickFixTestCase.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return LightQuickFixTestCase.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bringRealEditorBack() {
|
||||
LightCodeInsightTestCase.bringRealEditorBack();
|
||||
LightQuickFixTestCase.bringRealEditorBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
||||
@@ -57,4 +58,6 @@ public interface QuickFixTestCase {
|
||||
void configureFromFileText(String name, String contents) throws Throwable;
|
||||
|
||||
PsiFile getFile();
|
||||
|
||||
Project getProject();
|
||||
}
|
||||
|
||||
@@ -34,18 +34,14 @@ public class Extensions {
|
||||
public static final ExtensionPointName<AreaListener> AREA_LISTENER_EXTENSION_POINT = new ExtensionPointName<AreaListener>("com.intellij.arealistener");
|
||||
|
||||
private static final Map<AreaInstance,ExtensionsAreaImpl> ourAreaInstance2area = new HashMap<AreaInstance, ExtensionsAreaImpl>();
|
||||
private static ExtensionsAreaImpl ourRootArea = createRootArea();
|
||||
private static final MultiMap<String, AreaInstance> ourAreaClass2instances = new MultiMap<String, AreaInstance>();
|
||||
private static final Map<AreaInstance,String> ourAreaInstance2class = new HashMap<AreaInstance, String>();
|
||||
private static final Map<String,AreaClassConfiguration> ourAreaClass2Configuration = new HashMap<String, AreaClassConfiguration>();
|
||||
|
||||
static {
|
||||
createRootArea();
|
||||
}
|
||||
|
||||
private static ExtensionsAreaImpl createRootArea() {
|
||||
ExtensionsAreaImpl rootArea = new ExtensionsAreaImpl(null, null, null, ourLogger);
|
||||
rootArea.registerExtensionPoint(AREA_LISTENER_EXTENSION_POINT.getName(), AreaListener.class.getName());
|
||||
ourAreaInstance2area.put(null, rootArea);
|
||||
return rootArea;
|
||||
}
|
||||
|
||||
@@ -53,11 +49,14 @@ public class Extensions {
|
||||
}
|
||||
|
||||
public static ExtensionsArea getRootArea() {
|
||||
return getArea(null);
|
||||
return ourRootArea;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ExtensionsArea getArea(@Nullable AreaInstance areaInstance) {
|
||||
if (areaInstance == null) {
|
||||
return ourRootArea;
|
||||
}
|
||||
ExtensionsAreaImpl area = ourAreaInstance2area.get(areaInstance);
|
||||
if (area == null) {
|
||||
throw new IllegalArgumentException("No area instantiated for: " + areaInstance);
|
||||
@@ -69,10 +68,11 @@ public class Extensions {
|
||||
public static void cleanRootArea(@NotNull Disposable parentDisposable) {
|
||||
final ExtensionsAreaImpl oldRootArea = (ExtensionsAreaImpl)getRootArea();
|
||||
final ExtensionsAreaImpl newArea = createRootArea();
|
||||
ourRootArea = newArea;
|
||||
oldRootArea.notifyAreaReplaced();
|
||||
Disposer.register(parentDisposable, new Disposable() {
|
||||
public void dispose() {
|
||||
ourAreaInstance2area.put(null, oldRootArea);
|
||||
ourRootArea = oldRootArea;
|
||||
newArea.notifyAreaReplaced();
|
||||
}
|
||||
});
|
||||
@@ -123,7 +123,7 @@ public class Extensions {
|
||||
if (!ourAreaClass2Configuration.containsKey(areaClass)) {
|
||||
throw new IllegalArgumentException("Area class is not registered: " + areaClass);
|
||||
}
|
||||
if (ourAreaInstance2area.containsKey(areaInstance)) {
|
||||
if ((areaInstance == null && ourRootArea != null) || ourAreaInstance2area.containsKey(areaInstance)) {
|
||||
throw new IllegalArgumentException("Area already instantiated for: " + areaInstance);
|
||||
}
|
||||
ExtensionsArea parentArea = getArea(parentAreaInstance);
|
||||
|
||||
@@ -41,17 +41,21 @@ public class IndentOptionsEditor extends OptionGroup {
|
||||
protected void addComponents() {
|
||||
addTabOptions();
|
||||
|
||||
myTabSizeField = new JTextField(4);
|
||||
myTabSizeField.setMinimumSize(myTabSizeField.getPreferredSize());
|
||||
myTabSizeField = createIndentTextField();
|
||||
myTabSizeLabel = new JLabel(ApplicationBundle.message("editbox.indent.tab.size"));
|
||||
add(myTabSizeLabel, myTabSizeField);
|
||||
|
||||
myIndentField = new JTextField(4);
|
||||
myIndentField.setMinimumSize(myTabSizeField.getPreferredSize());
|
||||
myIndentField = createIndentTextField();
|
||||
myIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.indent"));
|
||||
add(myIndentLabel, myIndentField);
|
||||
}
|
||||
|
||||
protected JTextField createIndentTextField() {
|
||||
JTextField field = new JTextField(4);
|
||||
field.setMinimumSize(field.getPreferredSize());
|
||||
return field;
|
||||
}
|
||||
|
||||
protected void addTabOptions() {
|
||||
myCbUseTab = new JCheckBox(ApplicationBundle.message("checkbox.indent.use.tab.character"));
|
||||
add(myCbUseTab);
|
||||
@@ -71,6 +75,15 @@ public class IndentOptionsEditor extends OptionGroup {
|
||||
}
|
||||
}
|
||||
|
||||
protected int getFieldValue(JTextField field, int minValue, int defValue) {
|
||||
try {
|
||||
return Math.max(Integer.parseInt(field.getText()), minValue);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return defValue;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModified(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) {
|
||||
boolean isModified;
|
||||
isModified = isFieldModified(myTabSizeField, options.TAB_SIZE);
|
||||
@@ -81,26 +94,11 @@ public class IndentOptionsEditor extends OptionGroup {
|
||||
}
|
||||
|
||||
protected int getUIIndent() {
|
||||
final String indentText = myIndentField.getText();
|
||||
try {
|
||||
return Math.max(Integer.parseInt(indentText), 1);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
//stay with default
|
||||
}
|
||||
|
||||
return 4;
|
||||
return getFieldValue(myIndentField, 1, 4);
|
||||
}
|
||||
|
||||
protected int getUITabSize() {
|
||||
try {
|
||||
return Math.max(Integer.parseInt(myTabSizeField.getText()), 1);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
//stay with default
|
||||
}
|
||||
|
||||
return 4;
|
||||
return getFieldValue(myTabSizeField, 1, 4);
|
||||
}
|
||||
|
||||
public void apply(final CodeStyleSettings settings, CodeStyleSettings.IndentOptions options) {
|
||||
|
||||
+2
-8
@@ -40,8 +40,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor {
|
||||
protected void addComponents() {
|
||||
super.addComponents();
|
||||
|
||||
myContinuationIndentField = new JTextField(4);
|
||||
myContinuationIndentField.setMinimumSize(myContinuationIndentField.getPreferredSize());
|
||||
myContinuationIndentField = createIndentTextField();
|
||||
myContinuationIndentLabel = new JLabel(ApplicationBundle.message("editbox.indent.continuation.indent"));
|
||||
add(myContinuationIndentLabel, myContinuationIndentField);
|
||||
}
|
||||
@@ -55,12 +54,7 @@ public class SmartIndentOptionsEditor extends IndentOptionsEditor {
|
||||
|
||||
public void apply(final CodeStyleSettings settings, final CodeStyleSettings.IndentOptions options) {
|
||||
super.apply(settings, options);
|
||||
try {
|
||||
options.CONTINUATION_INDENT_SIZE = Math.max(Integer.parseInt(myContinuationIndentField.getText()), 0);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
//stay with default
|
||||
}
|
||||
options.CONTINUATION_INDENT_SIZE = getFieldValue(myContinuationIndentField, 0, options.CONTINUATION_INDENT_SIZE);
|
||||
options.SMART_TABS = isSmartTabValid(options.INDENT_SIZE, options.TAB_SIZE) && myCbSmartTabs.isSelected();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public abstract class SmartEnterProcessor {
|
||||
|
||||
final Document doc = editor.getDocument();
|
||||
CharSequence chars = doc.getCharsSequence();
|
||||
int offset = CharArrayUtil.shiftBackward(chars, caret - 1, " \t");
|
||||
int offset = caret == 0 ? 0 : CharArrayUtil.shiftBackward(chars, caret - 1, " \t");
|
||||
if (doc.getLineNumber(offset) < doc.getLineNumber(caret)) {
|
||||
offset = CharArrayUtil.shiftForward(chars, caret, " \t");
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public abstract class FacetType<F extends Facet, C extends FacetConfiguration> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final String getPresentableName() {
|
||||
public String getPresentableName() {
|
||||
return myPresentableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default name wich will be used then user creates a facet of this type
|
||||
* Default name which will be used then user creates a facet of this type
|
||||
* @return
|
||||
*/
|
||||
@NotNull @NonNls
|
||||
|
||||
@@ -252,6 +252,21 @@ public abstract class Indent {
|
||||
return myFactory.getIndent(type, relativeToDirectParent, enforceIndentToChildren);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base factory method for {@link Indent} objects construction, i.e. all other methods may be expressed in terms of this method.
|
||||
*
|
||||
* @param type indent type
|
||||
* @param spaces the number of spaces in the indent
|
||||
* @param relativeToDirectParent flag the indicates if current indent object anchors direct block parent (feel free
|
||||
* to get more information about that at class-level javadoc)
|
||||
* @param enforceIndentToChildren flag the indicates if current indent object should be enforced for multiline block children
|
||||
* (feel free to get more information about that at class-level javadoc)
|
||||
* @return newly created indent configured in accordance with the given arguments
|
||||
*/
|
||||
public static Indent getIndent(@NotNull Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) {
|
||||
return myFactory.getIndent(type, spaces, relativeToDirectParent, enforceIndentToChildren);
|
||||
}
|
||||
|
||||
public static class Type {
|
||||
private final String myName;
|
||||
|
||||
|
||||
@@ -32,5 +32,6 @@ interface IndentFactory {
|
||||
Indent getContinuationIndent(boolean relativeToDirectParent);
|
||||
Indent getContinuationWithoutFirstIndent(boolean relativeToDirectParent);
|
||||
Indent getSpaceIndent(final int spaces, boolean relativeToDirectParent);
|
||||
Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceParentIndent);
|
||||
Indent getIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren);
|
||||
Indent getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren);
|
||||
}
|
||||
|
||||
+6
@@ -53,4 +53,10 @@ public class LanguageLineWrapPositionStrategy extends LanguageExtension<LineWrap
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LineWrapPositionStrategy getDefaultImplementation() {
|
||||
return super.getDefaultImplementation();
|
||||
}
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.openapi.editor;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* {@link LineWrapPositionStrategy} implementation that uses
|
||||
* {@link LanguageLineWrapPositionStrategy#getDefaultImplementation() default line wrap strategy} but restricts its scope
|
||||
* by {@link #PsiAwareDefaultLineWrapPositionStrategy(IElementType...) target tokens/elements}.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 5/12/11 12:50 PM
|
||||
*/
|
||||
public class PsiAwareDefaultLineWrapPositionStrategy extends PsiAwareLineWrapPositionStrategy {
|
||||
|
||||
public PsiAwareDefaultLineWrapPositionStrategy(@NotNull IElementType ... enabledTypes) {
|
||||
super(enabledTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doCalculateWrapPosition(@NotNull Document document,
|
||||
@Nullable Project project,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
int maxPreferredOffset,
|
||||
boolean allowToBeyondMaxPreferredOffset)
|
||||
{
|
||||
LineWrapPositionStrategy implementation = LanguageLineWrapPositionStrategy.INSTANCE.getDefaultImplementation();
|
||||
return implementation.calculateWrapPosition(document, project, startOffset, endOffset, maxPreferredOffset,
|
||||
allowToBeyondMaxPreferredOffset);
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.openapi.editor;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Base super-class for {@link LineWrapPositionStrategy} implementations that want to restrict wrap positions
|
||||
* only for particular elements/tokens (e.g. we may want to avoid line wrap in the middle of xml tag name etc).
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 5/12/11 12:30 PM
|
||||
*/
|
||||
public abstract class PsiAwareLineWrapPositionStrategy implements LineWrapPositionStrategy {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + PsiAwareLineWrapPositionStrategy.class.getName());
|
||||
|
||||
private final TokenSet myEnabledTypes;
|
||||
|
||||
/**
|
||||
* Creates new <code>PsiAwareLineWrapPositionStrategy</code> object.
|
||||
*
|
||||
* @param enabledTypes target element/token types where line wrapping is allowed
|
||||
*/
|
||||
public PsiAwareLineWrapPositionStrategy(@NotNull IElementType ... enabledTypes) {
|
||||
myEnabledTypes = TokenSet.create(enabledTypes);
|
||||
if (enabledTypes.length <= 0) {
|
||||
LOG.warn(String.format("%s instance is created with empty token/element types. That will lead to inability to perform line wrap",
|
||||
getClass().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateWrapPosition(@NotNull Document document,
|
||||
@Nullable Project project,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
int maxPreferredOffset,
|
||||
boolean allowToBeyondMaxPreferredOffset) {
|
||||
if (project == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
if (documentManager == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PsiFile psiFile = documentManager.getPsiFile(document);
|
||||
if (psiFile == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PsiElement element = psiFile.findElementAt(maxPreferredOffset);
|
||||
if (element == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; element != null && element.getTextRange().getEndOffset() > startOffset; element = getPrevious(element)) {
|
||||
if (allowToWrapInside(element)) {
|
||||
TextRange textRange = element.getTextRange();
|
||||
int start = textRange.getStartOffset();
|
||||
int end = textRange.getEndOffset();
|
||||
int result = doCalculateWrapPosition(document, project, start, end, end, false);
|
||||
if (result >= 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Assume that it's possible to wrap on token boundary (makes sense at least for the tokens that occupy one symbol only).
|
||||
if (end <= maxPreferredOffset) {
|
||||
return end;
|
||||
}
|
||||
|
||||
if (start > startOffset) {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves for the same purposes as {@link #calculateWrapPosition(Document, Project, int, int, int, boolean)} but ensures that given
|
||||
* offsets target {@link #PsiAwareLineWrapPositionStrategy(IElementType...) enabled token/element types}.
|
||||
*
|
||||
* @param document target document which text is being processed
|
||||
* @param project target project
|
||||
* @param startOffset start offset to use with the given text holder (inclusive)
|
||||
* @param endOffset end offset to use with the given text holder (exclusive)
|
||||
* @param maxPreferredOffset this method is expected to do its best to return offset that belongs to
|
||||
* <code>(startOffset; maxPreferredOffset]</code> interval. However, it's allowed
|
||||
* to return value from <code>(maxPreferredOffset; endOffset]</code> interval
|
||||
* unless <code>'allowToBeyondMaxPreferredOffset'</code> if <code>'false'</code>
|
||||
* @param allowToBeyondMaxPreferredOffset indicates if it's allowed to return value from
|
||||
* <code>(maxPreferredOffset; endOffset]</code> interval in case of inability to
|
||||
* find appropriate offset from <code>(startOffset; maxPreferredOffset]</code> interval
|
||||
* @return offset from <code>(startOffset; endOffset]</code> interval where
|
||||
* target line should be wrapped OR <code>-1</code> if no wrapping should be performed
|
||||
*/
|
||||
protected abstract int doCalculateWrapPosition(
|
||||
@NotNull Document document, @Nullable Project project, int startOffset, int endOffset, int maxPreferredOffset,
|
||||
boolean allowToBeyondMaxPreferredOffset
|
||||
);
|
||||
|
||||
/**
|
||||
* Allows to check if line wrap at the text range defined by the given element is allowed.
|
||||
*
|
||||
* @param element element that defines target text range
|
||||
* @return <code>true</code> if wrapping at the text range defined by the given element is allowed;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
private boolean allowToWrapInside(@NotNull PsiElement element) {
|
||||
TextRange textRange = element.getTextRange();
|
||||
for (PsiElement parent = element; parent != null && parent.getTextRange().equals(textRange); parent = parent.getParent()) {
|
||||
ASTNode parentNode = parent.getNode();
|
||||
if (parentNode != null && myEnabledTypes.contains(parentNode.getElementType())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiElement getPrevious(@NotNull PsiElement element) {
|
||||
PsiElement result = element.getPrevSibling();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement parentSibling = null;
|
||||
for (; parent != null && parentSibling == null; parent = parent.getParent()) {
|
||||
parentSibling = parent.getPrevSibling();
|
||||
}
|
||||
|
||||
if (parentSibling == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
result = parentSibling.getLastChild();
|
||||
return result == null ? parentSibling : result;
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,12 @@ import com.intellij.ide.highlighter.InternalFileType;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.roots.JdkOrderEntry;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFilePathWrapper;
|
||||
import com.intellij.util.SystemProperties;
|
||||
@@ -87,6 +91,23 @@ public class ProjectUtil {
|
||||
}
|
||||
}
|
||||
final Module module = ModuleUtil.findModuleForFile(file, project);
|
||||
|
||||
if (SystemInfo.isMac && file.getFileSystem() instanceof JarFileSystem) {
|
||||
final VirtualFile fileForJar = ((JarFileSystem)file.getFileSystem()).getVirtualFileForJar(file);
|
||||
if (fileForJar != null) {
|
||||
final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
|
||||
if (libraryEntry != null) {
|
||||
if (libraryEntry instanceof JdkOrderEntry) {
|
||||
url = new StringBuilder(url).append(" - [").append(((JdkOrderEntry)libraryEntry).getJdkName()).append("]").toString();
|
||||
} else {
|
||||
url = new StringBuilder(url).append(" - [").append(libraryEntry.getPresentableName()).append("]").toString();
|
||||
}
|
||||
} else {
|
||||
url = new StringBuilder(url).append(" - [").append(fileForJar.getName()).append("]").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (module == null) return url;
|
||||
return SystemInfo.isMac ? new StringBuffer().append(url).append(" - [").append(module.getName()).append("]").toString() :
|
||||
new StringBuffer().append("[").append(module.getName()).append("] - ").append(url).toString();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.patterns;
|
||||
|
||||
import com.intellij.patterns.compiler.PatternCompilerFactory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Text;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Tag("pattern")
|
||||
public class ElementPatternBean {
|
||||
|
||||
@Attribute("type")
|
||||
public String type;
|
||||
|
||||
@Text
|
||||
public String text;
|
||||
|
||||
@Nullable
|
||||
public ElementPattern<PsiElement> compilePattern() {
|
||||
return PatternCompilerFactory.getFactory().<PsiElement>getPatternCompiler(type).compileElementPattern(text);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.pom;
|
||||
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
|
||||
public interface PomElement extends UserDataHolder, Presentable, Navigatable {
|
||||
PomModel getModel();
|
||||
|
||||
long getModificationStamp();
|
||||
boolean isValid();
|
||||
}
|
||||
@@ -15,7 +15,10 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
* Some elements return them from {@link PsiElement#getReferences()} directly though, but one should not rely on that
|
||||
* behavior since it may be changed in the future.
|
||||
*
|
||||
* The alternative way to register {@link PsiReferenceProvider} is by using {@link PsiReferenceProviderBean}.
|
||||
*
|
||||
* @author peter
|
||||
* @see PsiReferenceProviderBean
|
||||
*/
|
||||
public abstract class PsiReferenceContributor implements Disposable {
|
||||
public static final ExtensionPointName<PsiReferenceContributor> EP_NAME = ExtensionPointName.create("com.intellij.psi.referenceContributor");
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Register it via {@link PsiReferenceContributor} or {@link PsiReferenceProviderBean#EP_NAME}
|
||||
*
|
||||
* @author ik
|
||||
*/
|
||||
public abstract class PsiReferenceProvider {
|
||||
|
||||
+46
-18
@@ -16,30 +16,52 @@
|
||||
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.AbstractExtensionPointBean;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.ElementPatternBean;
|
||||
import com.intellij.patterns.StandardPatterns;
|
||||
import com.intellij.patterns.compiler.PatternCompilerFactory;
|
||||
import com.intellij.util.xmlb.annotations.*;
|
||||
import com.intellij.util.KeyedLazyInstance;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Property;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PsiReferenceProviderBean extends AbstractExtensionPointBean {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.PsiReferenceProviderBean");
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Registers a {@link PsiReferenceProvider} in plugin.xml
|
||||
*/
|
||||
public class PsiReferenceProviderBean extends AbstractExtensionPointBean implements KeyedLazyInstance<PsiReferenceProviderBean> {
|
||||
|
||||
public static final ExtensionPointName<PsiReferenceProviderBean> EP_NAME =
|
||||
new ExtensionPointName<PsiReferenceProviderBean>("com.intellij.psi.referenceProvider");
|
||||
|
||||
@Attribute("language")
|
||||
public String language = Language.ANY.getID();
|
||||
|
||||
@Attribute("providerClass")
|
||||
public String className;
|
||||
|
||||
@Tag("description")
|
||||
public String description;
|
||||
|
||||
@Property(surroundWithTag = false)
|
||||
@AbstractCollection(surroundWithTag = false)
|
||||
public Info[] patterns;
|
||||
public ElementPatternBean[] patterns;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.PsiReferenceProviderBean");
|
||||
|
||||
public PsiReferenceProvider instantiate() {
|
||||
try {
|
||||
return (PsiReferenceProvider)instantiate(className, ApplicationManager.getApplication().getPicoContainer());
|
||||
@@ -50,18 +72,22 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final NullableFunction<ElementPatternBean,ElementPattern<? extends PsiElement>> PATTERN_NULLABLE_FUNCTION = new NullableFunction<ElementPatternBean, ElementPattern<? extends PsiElement>>() {
|
||||
@Override
|
||||
public ElementPattern<? extends PsiElement> fun(ElementPatternBean elementPatternBean) {
|
||||
return elementPatternBean.compilePattern();
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
public ElementPattern<PsiElement> createElementPattern() {
|
||||
final PatternCompilerFactory factory = PatternCompilerFactory.getFactory();
|
||||
if (patterns.length > 1) {
|
||||
final ElementPattern[] result = new ElementPattern[this.patterns.length];
|
||||
for (int i = 0, len = this.patterns.length; i < len; i++) {
|
||||
result[i] = factory.getPatternCompiler(patterns[i].type).compileElementPattern(patterns[i].text);
|
||||
}
|
||||
return StandardPatterns.or(result);
|
||||
List<ElementPattern<? extends PsiElement>> list = ContainerUtil.mapNotNull(patterns, PATTERN_NULLABLE_FUNCTION);
|
||||
//noinspection unchecked
|
||||
return StandardPatterns.or(list.toArray(new ElementPattern[list.size()]));
|
||||
}
|
||||
else if (patterns.length == 1) {
|
||||
return factory.<PsiElement>getPatternCompiler(patterns[0].type).compileElementPattern(patterns[0].text);
|
||||
return patterns[0].compilePattern();
|
||||
}
|
||||
else {
|
||||
LOG.error("At least one pattern should be specified");
|
||||
@@ -69,11 +95,13 @@ public class PsiReferenceProviderBean extends AbstractExtensionPointBean {
|
||||
}
|
||||
}
|
||||
|
||||
@Tag("pattern")
|
||||
public static class Info {
|
||||
@Attribute("type")
|
||||
public String type;
|
||||
@Text
|
||||
public String text;
|
||||
@Override
|
||||
public String getKey() {
|
||||
return language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiReferenceProviderBean getInstance() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -50,10 +50,11 @@ public abstract class SmartPointerManager {
|
||||
@NotNull public abstract <E extends PsiElement> SmartPsiElementPointer<E> createLazyPointer(@NotNull E element);
|
||||
|
||||
/**
|
||||
* This method is cheaper than dereferencing both pointers and comparing the result.
|
||||
*
|
||||
* @param pointer1 smart pointer to compare
|
||||
* @param pointer2 smart pointer to compare
|
||||
* @return true if both pointers point to the same PSI element.
|
||||
* This method is cheaper than dereferencing both pointers and comparing the result.
|
||||
*/
|
||||
public abstract boolean pointToTheSameElement(@NotNull SmartPsiElementPointer pointer1, @NotNull SmartPsiElementPointer pointer2);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ public interface CodeStyleSettingsCustomizable {
|
||||
String SPACES_WITHIN_TYPE_ARGUMENTS = ApplicationBundle.message("group.spaces.in.type.arguments");
|
||||
String SPACES_OTHER = ApplicationBundle.message("group.spaces.other");
|
||||
|
||||
String BLANK_LINES = ApplicationBundle.message("title.blank.lines");
|
||||
String BLANK_LINES_KEEP = ApplicationBundle.message("title.keep.blank.lines");
|
||||
String BLANK_LINES = ApplicationBundle.message("title.minimum.blank.lines");
|
||||
|
||||
String WRAPPING_KEEP = ApplicationBundle.message("wrapping.keep.when.reformatting");
|
||||
String WRAPPING_BRACES = ApplicationBundle.message("wrapping.brace.placement");
|
||||
|
||||
@@ -302,10 +302,10 @@ public class PsiTreeUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean instanceOf(final PsiElement child, final Class<?>... classes) {
|
||||
public static boolean instanceOf(final Object object, final Class<?>... classes) {
|
||||
if (classes != null) {
|
||||
for (final Class<?> each : classes) {
|
||||
if (each.isInstance(child)) return true;
|
||||
for (final Class<?> c : classes) {
|
||||
if (c.isInstance(object)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.usageView;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -164,6 +165,13 @@ public class UsageInfo {
|
||||
if (element == null) return null;
|
||||
TextRange range = element.getTextRange();
|
||||
ProperTextRange.assertProperRange(range, element);
|
||||
if (element instanceof PsiFile) {
|
||||
// hack: it's actually a range inside file, use document for range checking since during the "find|replace all" operation, file range might have been changed
|
||||
Document document = PsiDocumentManager.getInstance(getProject()).getDocument((PsiFile)element);
|
||||
if (document != null) {
|
||||
range = new ProperTextRange(0, document.getTextLength());
|
||||
}
|
||||
}
|
||||
ProperTextRange rangeInElement = getRangeInElement();
|
||||
if (rangeInElement == null) return null;
|
||||
return new ProperTextRange(Math.min(range.getEndOffset(), range.getStartOffset() + rangeInElement.getStartOffset()),
|
||||
|
||||
+18
-25
@@ -15,41 +15,34 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class PrefixMatchingWeigher extends CompletionWeigher {
|
||||
|
||||
public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
public static int getPrefixMatchingDegree(LookupElement item, CompletionLocation location) {
|
||||
final String prefix = location.getCompletionParameters().getLookup().itemPattern(item);
|
||||
|
||||
if (prefix.isEmpty()) {
|
||||
return 0;
|
||||
final int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
|
||||
final NameUtil.MatchingCaseSensitivity sensitivity =
|
||||
setting == CodeInsightSettings.NONE ? NameUtil.MatchingCaseSensitivity.NONE :
|
||||
setting == CodeInsightSettings.FIRST_LETTER ? NameUtil.MatchingCaseSensitivity.FIRST_LETTER : NameUtil.MatchingCaseSensitivity.ALL;
|
||||
final NameUtil.MinusculeMatcher matcher = new NameUtil.MinusculeMatcher(prefix, sensitivity);
|
||||
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (String lookupString : item.getAllLookupStrings()) {
|
||||
max = Math.max(max, matcher.matchingDegree(lookupString));
|
||||
}
|
||||
|
||||
final Set<String> strings = item.getAllLookupStrings();
|
||||
final String prefixHumps = StringUtil.capitalsOnly(prefix);
|
||||
|
||||
if (StringUtil.isNotEmpty(prefixHumps)) {
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.capitalsOnly(lookupString).startsWith(prefixHumps)) return 100;
|
||||
}
|
||||
}
|
||||
|
||||
for (String lookupString : strings) {
|
||||
if (lookupString.startsWith(prefix)) return 5;
|
||||
}
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.startsWithIgnoreCase(lookupString, prefix)) return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-11
@@ -16,10 +16,7 @@
|
||||
package com.intellij.codeInsight.completion.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.*;
|
||||
import com.intellij.codeInsight.lookup.Classifier;
|
||||
import com.intellij.codeInsight.lookup.ClassifierFactory;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementWeigher;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
@@ -262,13 +259,31 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
}
|
||||
|
||||
for (final Weigher weigher : WeighingService.getWeighers(CompletionService.RELEVANCE_KEY)) {
|
||||
sorter = sorter.weigh(new LookupElementWeigher(weigher.toString()) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
return new NegatingComparable(weigher.weigh(element, location));
|
||||
}
|
||||
});
|
||||
final String id = weigher.toString();
|
||||
if ("prefix".equals(id)) {
|
||||
sorter = sorter.withClassifier(new ClassifierFactory<LookupElement>(id) {
|
||||
@Override
|
||||
public Classifier<LookupElement> createClassifier(Classifier<LookupElement> next) {
|
||||
return new ComparingClassifier<LookupElement>(next, id) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Comparable getWeight(LookupElement element) {
|
||||
return -PrefixMatchingWeigher.getPrefixMatchingDegree(element, location);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
sorter = sorter.weigh(new LookupElementWeigher(id) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
return new NegatingComparable(weigher.weigh(element, location));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sorter.withClassifier("priority", true, new ClassifierFactory<LookupElement>("liftShorter") {
|
||||
|
||||
+1
-7
@@ -39,13 +39,7 @@ public class CompletionSorterImpl extends CompletionSorter {
|
||||
return new ClassifierFactory<LookupElement>(id) {
|
||||
@Override
|
||||
public Classifier<LookupElement> createClassifier(Classifier<LookupElement> next) {
|
||||
return new ComparingClassifier<LookupElement>(next, id) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Comparable getWeight(LookupElement element) {
|
||||
return weigher.weigh(element);
|
||||
}
|
||||
};
|
||||
return new CachingComparingClassifier(next, weigher);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+4
-1
@@ -20,6 +20,8 @@ import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -76,7 +78,7 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
}
|
||||
|
||||
private Iterable<List<LookupElement>> liftShorterElements(List<LookupElement> source, Set<LookupElement> lifted) {
|
||||
final Set<LookupElement> srcSet = new HashSet<LookupElement>(source);
|
||||
final Set<LookupElement> srcSet = new THashSet<LookupElement>(source, TObjectHashingStrategy.IDENTITY);
|
||||
final Iterable<List<LookupElement>> classified = myNext.classify(source);
|
||||
final Set<LookupElement> processed = new HashSet<LookupElement>();
|
||||
|
||||
@@ -84,6 +86,7 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
for (List<LookupElement> list : classified) {
|
||||
final ArrayList<LookupElement> group = new ArrayList<LookupElement>();
|
||||
for (LookupElement element : list) {
|
||||
assert srcSet.contains(element) : myNext;
|
||||
if (processed.add(element)) {
|
||||
final List<String> prefixes = new SmartList<String>();
|
||||
for (String string : getAllLookupStrings(element)) {
|
||||
|
||||
@@ -115,6 +115,11 @@ public class ControlFlowBuilder {
|
||||
pending.add(i, Pair.create(pendingScope, instruction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates edges from the pending list to the specified instruction.
|
||||
*
|
||||
* @param instruction target instruction for pending edges
|
||||
*/
|
||||
public void checkPending(@NotNull final Instruction instruction) {
|
||||
final PsiElement element = instruction.getElement();
|
||||
if (element == null) {
|
||||
@@ -125,7 +130,7 @@ public class ControlFlowBuilder {
|
||||
pending.clear();
|
||||
}
|
||||
else {
|
||||
// else we just all the pending with scope containing in element
|
||||
// else we just process all the pending with scope containing in element
|
||||
// reverse order is just an optimization
|
||||
for (int i = pending.size() - 1; i >= 0; i--) {
|
||||
final Pair<PsiElement, Instruction> pair = pending.get(i);
|
||||
|
||||
+5
-9
@@ -227,22 +227,18 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
myHighlights.addAll(toApplyInside);
|
||||
gotHighlights.clear();
|
||||
gotHighlights.addAll(outsideResult);
|
||||
|
||||
final long modificationStamp = myDocument.getModificationStamp();
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myProject.isDisposed()) return;
|
||||
if (myProject.isDisposed() || modificationStamp != myDocument.getModificationStamp()) return;
|
||||
MarkupModel markupModel = myDocument.getMarkupModel(myProject);
|
||||
|
||||
UpdateHighlightersUtil.setHighlightersInRange(myProject, myDocument, priorityIntersection, getColorsScheme(), toApplyInside,
|
||||
(MarkupModelEx)markupModel, Pass.UPDATE_ALL);
|
||||
}
|
||||
});
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myProject.isDisposed() || myEditor == null) return;
|
||||
new ShowAutoImportPass(myProject, myFile, myEditor).applyInformationToEditor();
|
||||
if (myEditor != null) {
|
||||
new ShowAutoImportPass(myProject, myFile, myEditor).applyInformationToEditor();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+8
-9
@@ -73,7 +73,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||
*/
|
||||
public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass implements DumbAware {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.LocalInspectionsPass");
|
||||
private static final int NUM_ELEMENTS_PER_CHECK_CANCELLED = 5;
|
||||
public static final TextRange EMPTY_PRIORITY_RANGE = TextRange.EMPTY_RANGE;
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
@@ -255,7 +254,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
}
|
||||
}
|
||||
};
|
||||
PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, indicator);
|
||||
PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements);
|
||||
|
||||
synchronized (init) {
|
||||
init.add(Trinity.create(tool, holder, visitor));
|
||||
@@ -277,8 +276,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
@NotNull ProblemsHolder holder,
|
||||
boolean isOnTheFly,
|
||||
@NotNull LocalInspectionToolSession session,
|
||||
@NotNull List<PsiElement> elements,
|
||||
@NotNull ProgressIndicator indicator) {
|
||||
@NotNull List<PsiElement> elements) {
|
||||
PsiElementVisitor visitor = tool.buildVisitor(holder, isOnTheFly, session);
|
||||
//noinspection ConstantConditions
|
||||
if(visitor == null) {
|
||||
@@ -288,7 +286,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
: "The visitor returned from LocalInspectionTool.buildVisitor() must not be recursive. "+tool;
|
||||
|
||||
tool.inspectionStarted(session, isOnTheFly);
|
||||
acceptElements(elements, visitor, indicator);
|
||||
acceptElements(elements, visitor);
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@@ -310,7 +308,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
|
||||
ProblemsHolder holder = trinity.second;
|
||||
PsiElementVisitor elementVisitor = trinity.third;
|
||||
acceptElements(elements, elementVisitor, indicator);
|
||||
acceptElements(elements, elementVisitor);
|
||||
|
||||
advanceProgress(1);
|
||||
|
||||
@@ -329,11 +327,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
inspectInjectedPsi(elements, tools, isOnTheFly, indicator, iManager, false);
|
||||
}
|
||||
|
||||
private static void acceptElements(@NotNull List<PsiElement> elements, @NotNull PsiElementVisitor elementVisitor, @NotNull ProgressIndicator indicator) {
|
||||
private static void acceptElements(@NotNull List<PsiElement> elements,
|
||||
@NotNull PsiElementVisitor elementVisitor) {
|
||||
for (int i = 0, elementsSize = elements.size(); i < elementsSize; i++) {
|
||||
PsiElement element = elements.get(i);
|
||||
element.accept(elementVisitor);
|
||||
if (i % NUM_ELEMENTS_PER_CHECK_CANCELLED == 0) indicator.checkCanceled();
|
||||
ProgressManager.checkCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,7 +668,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
};
|
||||
|
||||
LocalInspectionToolSession injSession = new LocalInspectionToolSession(injectedPsi, 0, injectedPsi.getTextLength());
|
||||
createVisitorAndAcceptElements(tool, holder, isOnTheFly, injSession, elements, indicator);
|
||||
createVisitorAndAcceptElements(tool, holder, isOnTheFly, injSession, elements);
|
||||
tool.inspectionFinished(injSession,holder);
|
||||
List<ProblemDescriptor> problems = holder.getResults();
|
||||
if (problems != null && !problems.isEmpty()) {
|
||||
|
||||
+23
-8
@@ -69,6 +69,7 @@ public abstract class AbstractExternalFilter {
|
||||
@NonNls private static final String DT = "<DT>";
|
||||
private static final Pattern CHARSET_META_PATTERN =
|
||||
Pattern.compile("<meta.*content\\s*=\".*[;|\\s]*charset=\\s*(.*)\\s*[;|\\s]*\">", Pattern.CASE_INSENSITIVE);
|
||||
private final HttpConfigurable myHttpConfigurable = HttpConfigurable.getInstance();
|
||||
|
||||
protected static abstract class RefConvertor {
|
||||
private final Pattern mySelector;
|
||||
@@ -209,6 +210,10 @@ public abstract class AbstractExternalFilter {
|
||||
}
|
||||
|
||||
protected void doBuildFromStream(String surl, Reader input, StringBuffer data) throws IOException {
|
||||
doBuildFromStream(surl, input, data, true);
|
||||
}
|
||||
|
||||
protected void doBuildFromStream(String surl, Reader input, StringBuffer data, boolean search4Encoding) throws IOException {
|
||||
BufferedReader buf = new BufferedReader(input);
|
||||
Matcher anchorMatcher = ourAnchorsuffix.matcher(surl);
|
||||
@NonNls String startSection = "<!-- ======== START OF CLASS DATA ======== -->";
|
||||
@@ -225,20 +230,30 @@ public abstract class AbstractExternalFilter {
|
||||
data.append(HTML);
|
||||
|
||||
String read;
|
||||
String charset = null;
|
||||
String contentEncoding = null;
|
||||
do {
|
||||
read = buf.readLine();
|
||||
if (read != null && read.contains("charset")) {
|
||||
charset = read;
|
||||
if (read != null && search4Encoding && read.contains("charset")) {
|
||||
String foundEncoding = parseContentEncoding(read);
|
||||
if (foundEncoding != null) {
|
||||
contentEncoding = foundEncoding;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (read != null && read.toUpperCase().indexOf(startSection) == -1);
|
||||
|
||||
if (input instanceof MyReader && charset != null) {
|
||||
String contentEncoding = parseContentEncoding(charset);
|
||||
if (contentEncoding != null) { //restart page parsing with correct encoding
|
||||
input = new MyReader(((MyReader)input).getInputStream(), contentEncoding);
|
||||
buf = new BufferedReader(input);
|
||||
if (input instanceof MyReader && contentEncoding != null) {
|
||||
if (contentEncoding != null && !contentEncoding.equals("UTF-8") && !contentEncoding.equals(((MyReader)input).getEncoding())) { //restart page parsing with correct encoding
|
||||
Reader stream;
|
||||
try {
|
||||
stream = getReaderByUrl(surl, myHttpConfigurable, new ProgressIndicatorBase());
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return;
|
||||
}
|
||||
data.delete(0, data.length());
|
||||
doBuildFromStream(surl, new MyReader(((MyReader)stream).getInputStream(), contentEncoding), data, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ public class AutoHardWrapHandler {
|
||||
new VisualPosition(caretModel.getVisualPosition().line, margin - FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS)
|
||||
));
|
||||
|
||||
int wrapOffset = strategy.calculateWrapPosition(document, startOffset, endOffset, maxPreferredOffset, true);
|
||||
int wrapOffset = strategy.calculateWrapPosition(document, project, startOffset, endOffset, maxPreferredOffset, true);
|
||||
if (wrapOffset < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-1
@@ -41,6 +41,7 @@ import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vcs.FileStatusManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
@@ -117,7 +118,8 @@ public class ImplementationViewComponent extends JPanel {
|
||||
for (PsiElement element : elements) {
|
||||
PsiFile file = getContainingFile(element);
|
||||
if (file == null) continue;
|
||||
files.add(new FileDescriptor(file, element.getParent()));
|
||||
final PsiElement parent = element.getParent();
|
||||
files.add(new FileDescriptor(file, parent == file ? element : parent));
|
||||
candidates.add(element.getNavigationElement());
|
||||
}
|
||||
myElements = PsiUtilBase.toPsiElementArray(candidates);
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.codeInsight.lookup;
|
||||
|
||||
import com.intellij.util.containers.StripedLockConcurrentHashMap;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CachingComparingClassifier extends ComparingClassifier<LookupElement> {
|
||||
private final Map<LookupElement, Comparable> myWeights = new StripedLockConcurrentHashMap<LookupElement, Comparable>(TObjectHashingStrategy.IDENTITY);
|
||||
private final LookupElementWeigher myWeigher;
|
||||
|
||||
public CachingComparingClassifier(Classifier<LookupElement> next, LookupElementWeigher weigher) {
|
||||
super(next, weigher.toString());
|
||||
myWeigher = weigher;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final Comparable getWeight(LookupElement t) {
|
||||
final Comparable weight = myWeights.get(t);
|
||||
if (weight == null) {
|
||||
throw new AssertionError(myName + "; " + myWeights.containsKey(t) + "; element=" + t);
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElement(LookupElement t) {
|
||||
myWeights.put(t, myWeigher.weigh(t));
|
||||
super.addElement(t);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,12 +23,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class ComparingClassifier<T> extends Classifier<T> {
|
||||
private final Map<T, Comparable> myWeights = new HashMap<T, Comparable>();
|
||||
private final Classifier<T> myNext;
|
||||
private final String myName;
|
||||
protected final String myName;
|
||||
|
||||
public ComparingClassifier(Classifier<T> next, String name) {
|
||||
myNext = next;
|
||||
@@ -38,19 +37,14 @@ public abstract class ComparingClassifier<T> extends Classifier<T> {
|
||||
@NotNull
|
||||
public abstract Comparable getWeight(T t);
|
||||
|
||||
@Override
|
||||
public void addElement(T t) {
|
||||
myWeights.put(t, getWeight(t));
|
||||
myNext.addElement(t);
|
||||
}
|
||||
|
||||
private TreeMap<Comparable, List<T>> groupByWeights(List<T> source) {
|
||||
TreeMap<Comparable, List<T>> map = new TreeMap<Comparable, List<T>>();
|
||||
for (T t : source) {
|
||||
final Comparable weight = myWeights.get(t);
|
||||
if (weight == null) {
|
||||
throw new AssertionError(myName + "; " + myWeights.containsKey(t));
|
||||
}
|
||||
final Comparable weight = getWeight(t);
|
||||
List<T> list = map.get(weight);
|
||||
if (list == null) {
|
||||
map.put(weight, list = new SmartList<T>());
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.event.*;
|
||||
import com.intellij.openapi.editor.ex.RangeMarkerEx;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
@@ -64,7 +65,6 @@ import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import com.intellij.util.ui.ButtonlessScrollBarUI;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -335,7 +335,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
void appendPrefix(char c) {
|
||||
checkReused();
|
||||
LOG.assertTrue(!myDisposed);
|
||||
checkValid();
|
||||
myAdditionalPrefix += c;
|
||||
myInitialPrefix = null;
|
||||
myFrozenItems.clear();
|
||||
@@ -377,17 +377,12 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
}
|
||||
assert !myDisposed;
|
||||
checkValid();
|
||||
|
||||
final Pair<List<LookupElement>,Iterable<List<LookupElement>>> snapshot = myModel.getModelSnapshot();
|
||||
|
||||
final List<LookupElement> items = matchingItems(snapshot);
|
||||
|
||||
List<LookupElement> oldItems = getItems();
|
||||
if (oldItems.size() == items.size() && new THashSet<LookupElement>(items, TObjectHashingStrategy.IDENTITY).containsAll(oldItems)) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkMinPrefixLengthChanges(items);
|
||||
|
||||
boolean hasPreselected = !mySelectionTouched && items.contains(myPreselectedItem);
|
||||
@@ -404,7 +399,9 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
myPreferredItemsCount = model.size();
|
||||
myFrozenItems.clear();
|
||||
myFrozenItems.addAll(model);
|
||||
if (myShown) {
|
||||
myFrozenItems.addAll(model);
|
||||
}
|
||||
|
||||
model.addAll(addRemainingItemsLexicographically(model, items));
|
||||
|
||||
@@ -498,7 +495,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myList.setSelectedIndex(doSelectMostPreferableItem(getItems()));
|
||||
}
|
||||
|
||||
if (myPreselectedItem != null) {
|
||||
if (myPreselectedItem != null && myShown) {
|
||||
myPreselectedItem = getCurrentItem();
|
||||
}
|
||||
}
|
||||
@@ -720,8 +717,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
int lookupStart = caretOffset - prefix.length();
|
||||
|
||||
int len = myEditor.getDocument().getTextLength();
|
||||
LOG.assertTrue(lookupStart >= 0 && lookupStart <= len, "ls: " + lookupStart + "doc: " + len);
|
||||
LOG.assertTrue(caretOffset >= 0 && caretOffset <= len, "co: " + caretOffset + "doc: " + len);
|
||||
LOG.assertTrue(lookupStart >= 0 && lookupStart <= len, "ls: " + lookupStart + "caret: " + caretOffset + " prefix:" + prefix + " doc: " + len);
|
||||
LOG.assertTrue(caretOffset >= 0 && caretOffset <= len, "co: " + caretOffset + " doc: " + len);
|
||||
|
||||
myEditor.getDocument().replaceString(lookupStart, caretOffset, lookupString);
|
||||
|
||||
@@ -755,21 +752,27 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
}
|
||||
|
||||
public void performGuardedChange(Runnable change) {
|
||||
LOG.assertTrue(!myDisposed, disposeTrace);
|
||||
checkValid();
|
||||
assert myLookupStartMarker.isValid();
|
||||
assert !myChangeGuard;
|
||||
|
||||
myChangeGuard = true;
|
||||
RangeMarkerEx marker = (RangeMarkerEx) myEditor.getDocument().createRangeMarker(myLookupStartMarker.getStartOffset(), myLookupStartMarker.getEndOffset());
|
||||
marker.trackInvalidation(true);
|
||||
try {
|
||||
change.run();
|
||||
}
|
||||
finally {
|
||||
marker.trackInvalidation(false);
|
||||
myChangeGuard = false;
|
||||
}
|
||||
LOG.assertTrue(!myDisposed, disposeTrace);
|
||||
LOG.assertTrue(myLookupStartMarker.isValid());
|
||||
checkValid();
|
||||
LOG.assertTrue(myLookupStartMarker.isValid(), "invalid lookup start");
|
||||
LOG.assertTrue(marker.isValid(), "invalid marker");
|
||||
if (isVisible()) {
|
||||
updateLookupBounds();
|
||||
}
|
||||
LOG.assertTrue(!myDisposed, disposeTrace);
|
||||
checkValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -784,7 +787,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
public void show(){
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
LOG.assertTrue(!myDisposed, disposeTrace);
|
||||
checkValid();
|
||||
LOG.assertTrue(!myShown);
|
||||
myShown = true;
|
||||
myStampShown = System.currentTimeMillis();
|
||||
@@ -1312,11 +1315,16 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
return myDisposed;
|
||||
}
|
||||
|
||||
public void checkValid() {
|
||||
if (myDisposed) {
|
||||
throw new AssertionError("Disposed at: " + disposeTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showItemPopup(JBPopup hint) {
|
||||
final Rectangle bounds = getCurrentItemBounds();
|
||||
hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width,
|
||||
bounds.y)));
|
||||
hint.show(new RelativePoint(getComponent(), new Point(bounds.x + bounds.width, bounds.y)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -225,6 +225,12 @@ public class LookupManagerImpl extends LookupManager {
|
||||
}
|
||||
|
||||
public LookupEx getActiveLookup() {
|
||||
if (myActiveLookup != null && myActiveLookup.isLookupDisposed()) {
|
||||
LookupImpl lookup = myActiveLookup;
|
||||
myActiveLookup = null;
|
||||
lookup.checkValid();
|
||||
}
|
||||
|
||||
return myActiveLookup;
|
||||
}
|
||||
|
||||
|
||||
+12
-6
@@ -31,16 +31,22 @@ public class ChooseItemAction extends EditorAction {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static LookupImpl getLookup(Editor editor) {
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
if (lookup == null) {
|
||||
Project project = editor.getProject();
|
||||
throw new AssertionError(editor + "; " + (project == null ? null : LookupManager.getInstance(project).getActiveLookup()));
|
||||
}
|
||||
return lookup;
|
||||
}
|
||||
|
||||
private static class Handler extends EditorActionHandler {
|
||||
public void execute(@NotNull final Editor editor, final DataContext dataContext) {
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
if (lookup == null) {
|
||||
Project project = editor.getProject();
|
||||
throw new AssertionError(editor + "; " + (project == null ? null : LookupManager.getInstance(project).getActiveLookup()));
|
||||
}
|
||||
lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
getLookup(editor).finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Editor editor, DataContext dataContext) {
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
|
||||
+1
-3
@@ -35,9 +35,7 @@ public class ChooseItemCompleteStatementAction extends EditorAction {
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_SMART_ENTER);
|
||||
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
lookup.finishLookup(Lookup.COMPLETE_STATEMENT_SELECT_CHAR);
|
||||
ChooseItemAction.getLookup(editor).finishLookup(Lookup.COMPLETE_STATEMENT_SELECT_CHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-10
@@ -41,15 +41,10 @@ public class ChooseItemReplaceAction extends EditorAction {
|
||||
}
|
||||
|
||||
private static class Handler extends EditorActionHandler {
|
||||
private boolean lastEnabled;
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_REPLACE);
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
if (lookup == null) {
|
||||
throw new AssertionError("Null lookup: lastEnabled=" + lastEnabled);
|
||||
}
|
||||
lookup.finishLookup(Lookup.REPLACE_SELECT_CHAR);
|
||||
ChooseItemAction.getLookup(editor).finishLookup(Lookup.REPLACE_SELECT_CHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,16 +55,16 @@ public class ChooseItemReplaceAction extends EditorAction {
|
||||
|
||||
CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
|
||||
if (completion != null && completion.isAutopopupCompletion() && hasTemplatePrefix(lookup, TemplateSettings.TAB_CHAR)) {
|
||||
return lastEnabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lookup.isFocused()) {
|
||||
return lastEnabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return lastEnabled = !lookup.getItems().isEmpty();
|
||||
return !lookup.getItems().isEmpty();
|
||||
}
|
||||
return lastEnabled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -200,7 +200,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
}
|
||||
}
|
||||
catch (AbstractMethodError e) {
|
||||
throw new RuntimeException(handler.toString(), e);
|
||||
LOG.error(handler.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ConversionContextImpl implements ConversionContext {
|
||||
myWorkspaceFile = new File(StringUtil.trimEnd(projectPath, ProjectFileType.DOT_DEFAULT_EXTENSION) + WorkspaceFileType.DOT_DEFAULT_EXTENSION);
|
||||
}
|
||||
|
||||
myModuleFiles = findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement());
|
||||
myModuleFiles = modulesFile.exists() ? findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement()) : new File[0];
|
||||
}
|
||||
|
||||
public Set<File> getAllProjectFiles() {
|
||||
|
||||
@@ -625,6 +625,8 @@ public class EditorSearchComponent extends JPanel implements DataProvider, Selec
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
mySearchField.setSelectionStart(0);
|
||||
mySearchField.setSelectionEnd(mySearchField.getText().length());
|
||||
requestFocus(mySearchField);
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ public class FindUtil {
|
||||
public void run() {
|
||||
if (model.isFindAll()) {
|
||||
findManager.setFindNextModel(model);
|
||||
findAll(project, editor, model);
|
||||
findAllAndShow(project, editor, model);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -237,10 +237,11 @@ public class FindUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static void findAll(final Project project, final Editor editor, final FindModel findModel) {
|
||||
@Nullable
|
||||
public static List<Usage> findAll(final Project project, final Editor editor, final FindModel findModel) {
|
||||
final Document document = editor.getDocument();
|
||||
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
|
||||
if (psiFile == null) return;
|
||||
if (psiFile == null) return null;
|
||||
|
||||
CharSequence text = document.getCharsSequence();
|
||||
int textLength = document.getTextLength();
|
||||
@@ -265,6 +266,12 @@ public class FindUtil {
|
||||
++offset;
|
||||
}
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
public static void findAllAndShow(final Project project, final Editor editor, final FindModel findModel) {
|
||||
List<Usage> usages = findAll(project, editor, findModel);
|
||||
if (usages == null) return;
|
||||
final UsageTarget[] usageTargets = { new FindInProjectUtil.StringUsageTarget(findModel.getStringToFind()) };
|
||||
final UsageViewPresentation usageViewPresentation = FindInProjectUtil.setupViewPresentation(false, findModel);
|
||||
UsageViewManager.getInstance(project).showUsages(usageTargets, usages.toArray(new Usage[usages.size()]), usageViewPresentation);
|
||||
@@ -576,6 +583,7 @@ public class FindUtil {
|
||||
public void run() {
|
||||
document.setText(newText);
|
||||
editor.getCaretModel().moveToOffset(finalCaretOffset);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user