Merge remote-tracking branch 'origin/master'

This commit is contained in:
Maxim.Mossienko
2015-02-24 13:13:55 +01:00
28 changed files with 264 additions and 83 deletions
@@ -37,9 +37,11 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Consumer;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
import static com.intellij.patterns.PsiJavaPatterns.psiClass;
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
@@ -117,26 +119,52 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
final boolean pkgContext = JavaCompletionUtil.inSomePackage(insertedElement);
AllClassesGetter.processJavaClasses(parameters, matcher, filterByScope, new Consumer<PsiClass>() {
@Override
public void consume(PsiClass psiClass) {
if (filter.isAcceptable(psiClass, insertedElement)) {
if (!inJavaContext) {
consumer.consume(AllClassesGetter.createLookupItem(psiClass, AllClassesGetter.TRY_SHORTENING));
} else {
for (JavaPsiClassReferenceElement element : createClassLookupItems(psiClass, afterNew,
JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, new Condition<PsiClass>() {
@Override
public void consume(PsiClass psiClass) {
processClass(psiClass, ContainerUtil.<PsiClass>newHashSet(), "");
}
private void processClass(PsiClass psiClass, Set<PsiClass> visited, String prefix) {
if (!visited.add(psiClass)) return;
boolean isInnerClass = StringUtil.isNotEmpty(prefix);
if (isInnerClass && isProcessedIndependently(psiClass)) {
return;
}
if (filter.isAcceptable(psiClass, insertedElement)) {
if (!inJavaContext) {
JavaPsiClassReferenceElement element = AllClassesGetter.createLookupItem(psiClass, AllClassesGetter.TRY_SHORTENING);
element.setLookupString(prefix + element.getLookupString());
consumer.consume(element);
} else {
for (JavaPsiClassReferenceElement element : createClassLookupItems(psiClass, afterNew,
JavaClassNameInsertHandler.JAVA_CLASS_INSERT_HANDLER, new Condition<PsiClass>() {
@Override
public boolean value(PsiClass psiClass) {
return filter.isAcceptable(psiClass, insertedElement) &&
AllClassesGetter.isAcceptableInContext(insertedElement, psiClass, filterByScope, pkgContext);
}
})) {
consumer.consume(element);
}
element.setLookupString(prefix + element.getLookupString());
consumer.consume(element);
}
}
} else {
String name = psiClass.getName();
if (name != null) {
for (PsiClass innerClass : psiClass.getInnerClasses()) {
processClass(innerClass, visited, prefix + name + ".");
}
}
}
});
}
private boolean isProcessedIndependently(PsiClass psiClass) {
String innerName = psiClass.getName();
return innerName != null && matcher.prefixMatches(innerName);
}
});
}
static LookupElement highlightIfNeeded(JavaPsiClassReferenceElement element, CompletionParameters parameters) {
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.roots.FileIndexFacade;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -711,6 +712,10 @@ public class PsiClassImplUtil {
@Nullable
public static PsiClassType correctType(PsiClassType originalType, final GlobalSearchScope resolveScope) {
if (!Registry.is("java.correct.class.type.by.place.resolve.scope")) {
return originalType;
}
final PsiClassType.ClassResolveResult originalResolveResult = originalType.resolveGenerics();
PsiClass superClass = originalResolveResult.getElement();
if (superClass == null) {
@@ -746,7 +751,7 @@ public class PsiClassImplUtil {
}
});
if (substitute == null) return null;
substitutor = substitutor.put(typeParameters[i], substitute);
}
}
@@ -0,0 +1,11 @@
final class MyModule {
@Target({FIELD,PARAMETER,METHOD})
@Retention(RUNTIME)
public static @interface Dependency { }
}
final class SomeService {
SomeService(@My<caret>) {
}
}
@@ -0,0 +1,11 @@
final class MyModule {
@Target({FIELD,PARAMETER,METHOD})
@Retention(RUNTIME)
public static @interface Dependency { }
}
final class SomeService {
SomeService(@MyModule.Dependency<caret>) {
}
}
@@ -25,7 +25,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
*/
class MultipleModuleHighlightingTest extends JavaCodeInsightFixtureTestCase {
@Bombed(day = 1, month = Calendar.MARCH)
@Bombed(day = 1, month = Calendar.APRIL)
public void "test use original place classpath for reference type resolving"() {
addTwoModules()
@@ -60,7 +60,7 @@ class Class3 {
myFixture.checkHighlighting()
}
@Bombed(day = 1, month = Calendar.MARCH)
@Bombed(day = 1, month = Calendar.APRIL)
public void "test use original place classpath for new expression type resolving"() {
addTwoModules()
@@ -932,6 +932,7 @@ public class ListUtils {
public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); }
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
public void testInnerAnnotation() { doTest('\n'); }
public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' }
public void testClassReferenceInFor() throws Throwable { doTest ' ' }
public void testClassReferenceInFor2() throws Throwable { doTest ' ' }
@@ -365,6 +365,19 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
assertSize(1, findUsages(findModel));
}
public void testNonSourceContent() throws Exception {
VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTempDirectory());
PsiTestUtil.addContentRoot(myModule, root);
createFile(myModule, root, "A.txt", "goo doo");
FindModel findModel = FindManagerTestUtils.configureFindModel("goo");
findModel.setProjectScope(false);
findModel.setModuleName(myModule.getName());
assertSize(1, findUsages(findModel));
}
public void testReplaceRegexp() {
FindModel findModel = new FindModel();
findModel.setStringToFind("bug_(?=here)");
@@ -537,6 +550,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
findModel.setFromCursor(false);
findModel.setGlobal(true);
findModel.setMultipleFiles(true);
findModel.setCustomScope(true);
ThrowableRunnable test = new ThrowableRunnable() {
@Override
@@ -573,6 +587,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
VirtualFile file = tempDirFixture.createFile("a.txt", "foo bar foo");
FindModel findModel = FindManagerTestUtils.configureFindModel("foo");
findModel.setWholeWordsOnly(true);
findModel.setCustomScope(true);
findModel.setCustomScope(new LocalSearchScope(PsiManager.getInstance(myProject).findFile(file)));
assertSize(2, findUsages(findModel));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.util.xmlb.annotations.OptionTag;
import com.intellij.util.xmlb.annotations.Transient;
public class DaemonCodeAnalyzerSettings {
@@ -26,9 +26,9 @@ public class DaemonCodeAnalyzerSettings {
public boolean NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = true;
public int AUTOREPARSE_DELAY = 300;
public boolean SHOW_ADD_IMPORT_HINTS = true;
protected boolean myShowAddImportHints = true;
public String NO_AUTO_IMPORT_PATTERN = "[a-z].?";
public boolean SUPPRESS_WARNINGS = true;
protected boolean mySuppressWarnings = true;
public boolean SHOW_METHOD_SEPARATORS = false;
public int ERROR_STRIPE_MARK_MIN_HEIGHT = 2;
public boolean SHOW_SMALL_ICONS_IN_GUTTER = true;
@@ -38,21 +38,21 @@ public class DaemonCodeAnalyzerSettings {
return false;
}
@Transient
@OptionTag(value = "SHOW_ADD_IMPORT_HINTS")
public boolean isImportHintEnabled() {
return SHOW_ADD_IMPORT_HINTS;
return myShowAddImportHints;
}
public void setImportHintEnabled(boolean isImportHintEnabled) {
SHOW_ADD_IMPORT_HINTS = isImportHintEnabled;
myShowAddImportHints = isImportHintEnabled;
}
@Transient
@OptionTag(value = "SUPPRESS_WARNINGS")
public boolean isSuppressWarnings() {
return SUPPRESS_WARNINGS;
return mySuppressWarnings;
}
public void setSuppressWarnings(boolean suppressWarnings) {
SUPPRESS_WARNINGS = suppressWarnings;
mySuppressWarnings = suppressWarnings;
}
}
@@ -42,8 +42,31 @@ public class CompareFilesAction extends BaseShowDiffAction {
VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
String text = getTemplatePresentation().getText();
if (files != null && files.length == 1) text += "...";
String text = "Compare Files";
if (files != null && files.length == 1) {
text = "Compare With...";
}
else if (files != null && files.length == 2) {
Type type1 = getType(files[0]);
Type type2 = getType(files[1]);
if (type1 != type2) {
text = "Compare";
}
else {
switch (type1) {
case FILE:
text = "Compare Files";
break;
case DIRECTORY:
text = "Compare Directories";
break;
case ARCHIEVE:
text = "Compare Archieves";
break;
}
}
}
e.getPresentation().setText(text);
}
@@ -93,7 +116,9 @@ public class CompareFilesAction extends BaseShowDiffAction {
private static VirtualFile getOtherFile(@Nullable Project project, @NotNull VirtualFile file) {
FileChooserDescriptor descriptor;
String key;
if (file.isDirectory() || file.getFileType() instanceof ArchiveFileType) {
Type type = getType(file);
if (type == Type.DIRECTORY || type == Type.ARCHIEVE) {
descriptor = new FileChooserDescriptor(false, true, true, false, false, false);
key = LAST_USED_FOLDER_KEY;
}
@@ -121,4 +146,14 @@ public class CompareFilesAction extends BaseShowDiffAction {
if (project == null) return;
PropertiesComponent.getInstance(project).setValue(key, file.getPath());
}
@NotNull
private static Type getType(@Nullable VirtualFile file) {
if (file == null) return Type.FILE;
if (file.isDirectory()) return Type.DIRECTORY;
if (file.getFileType() instanceof ArchiveFileType) return Type.ARCHIEVE;
return Type.FILE;
}
private enum Type {FILE, DIRECTORY, ARCHIEVE}
}
@@ -23,17 +23,21 @@ import com.intellij.diff.contents.EmptyContent;
import com.intellij.diff.contents.FileContent;
import com.intellij.diff.requests.ContentDiffRequest;
import com.intellij.diff.requests.DiffRequest;
import com.intellij.ide.DataManager;
import com.intellij.ide.diff.DiffElement;
import com.intellij.ide.diff.DirDiffSettings;
import com.intellij.ide.diff.JarFileDiffElement;
import com.intellij.ide.diff.VirtualFileDiffElement;
import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.diff.impl.dir.DirDiffFrame;
import com.intellij.openapi.diff.impl.dir.DirDiffPanel;
import com.intellij.openapi.diff.impl.dir.DirDiffTableModel;
import com.intellij.openapi.diff.impl.dir.DirDiffWindow;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,7 +50,8 @@ class DifDiffViewer implements FrameDiffTool.DiffViewer {
@NotNull private final DiffContext myContext;
@NotNull private final ContentDiffRequest myRequest;
@NotNull private final DirDiffPanel myPanel;
@NotNull private final DirDiffPanel myDirDiffPanel;
@NotNull private final JPanel myPanel;
public DifDiffViewer(@NotNull DiffContext context, @NotNull ContentDiffRequest request) {
myContext = context;
@@ -57,7 +62,7 @@ class DifDiffViewer implements FrameDiffTool.DiffViewer {
DiffElement element2 = createDiffElement(contents.get(1));
DirDiffTableModel model = new DirDiffTableModel(context.getProject(), element1, element2, new DirDiffSettings());
myPanel = new DirDiffPanel(model, new DirDiffWindow((DirDiffFrame)null) {
myDirDiffPanel = new DirDiffPanel(model, new DirDiffWindow((DirDiffFrame)null) {
@Override
public Window getWindow() {
return null;
@@ -72,31 +77,43 @@ class DifDiffViewer implements FrameDiffTool.DiffViewer {
public void setTitle(String title) {
}
});
myPanel = new JPanel(new BorderLayout());
myPanel.add(myDirDiffPanel.getPanel(), BorderLayout.CENTER);
DataManager.registerDataProvider(myPanel, new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.HELP_ID.is(dataId)) {
return "reference.dialogs.diff.folder";
}
return null;
}
});
}
@NotNull
@Override
public FrameDiffTool.ToolbarComponents init() {
myPanel.setupSplitter();
myDirDiffPanel.setupSplitter();
return new FrameDiffTool.ToolbarComponents();
}
@Override
public void dispose() {
Disposer.dispose(myPanel);
Disposer.dispose(myDirDiffPanel);
}
@NotNull
@Override
public JComponent getComponent() {
return myPanel.getPanel();
return myPanel;
}
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myPanel.getTable();
return myDirDiffPanel.getTable();
}
//
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -24,13 +24,13 @@ import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProfileManagerImpl;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.SkipDefaultsSerializationFilter;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
@State(
name = "DaemonCodeAnalyzerSettings",
storages = {@Storage(file = StoragePathMacros.APP_CONFIG + "/editor.codeinsight.xml")}
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/editor.codeinsight.xml")
)
public class DaemonCodeAnalyzerSettingsImpl extends DaemonCodeAnalyzerSettings implements PersistentStateComponent<Element>, Cloneable {
@Override
@@ -42,7 +42,7 @@ public class DaemonCodeAnalyzerSettingsImpl extends DaemonCodeAnalyzerSettings i
public DaemonCodeAnalyzerSettingsImpl clone() {
DaemonCodeAnalyzerSettingsImpl settings = new DaemonCodeAnalyzerSettingsImpl();
settings.AUTOREPARSE_DELAY = AUTOREPARSE_DELAY;
settings.SHOW_ADD_IMPORT_HINTS = SHOW_ADD_IMPORT_HINTS;
settings.myShowAddImportHints = myShowAddImportHints;
settings.SHOW_METHOD_SEPARATORS = SHOW_METHOD_SEPARATORS;
settings.NO_AUTO_IMPORT_PATTERN = NO_AUTO_IMPORT_PATTERN;
settings.SHOW_SMALL_ICONS_IN_GUTTER = SHOW_SMALL_ICONS_IN_GUTTER;
@@ -51,7 +51,7 @@ public class DaemonCodeAnalyzerSettingsImpl extends DaemonCodeAnalyzerSettings i
@Override
public Element getState() {
Element element = XmlSerializer.serialize(this, new SkipDefaultValuesSerializationFilters());
Element element = XmlSerializer.serialize(this, new SkipDefaultsSerializationFilter());
String profile = InspectionProfileManager.getInstance().getRootProfile().getName();
if (!"Default".equals(profile)) {
element.setAttribute("profile", profile);
@@ -356,7 +356,7 @@ public class EnterHandler extends BaseEnterHandler {
commentContext.docStart = false;
}
else {
commentContext.docAsterisk = true;
commentContext.docAsterisk = CodeStyleSettingsManager.getSettings(getProject()).JD_LEADING_ASTERISKS_ARE_ENABLED;
commentContext.docStart = false;
}
}
@@ -267,7 +267,7 @@ class FindInProjectTask {
@NotNull
private Collection<VirtualFile> collectFilesInScope(@NotNull final Set<VirtualFile> alreadySearched, final boolean skipIndexed) {
SearchScope customScope = myFindModel.getCustomScope();
SearchScope customScope = myFindModel.isCustomScope() ? myFindModel.getCustomScope() : null;
final GlobalSearchScope globalCustomScope = toGlobal(customScope);
final ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
@@ -432,17 +432,7 @@ class FindInProjectTask {
return Collections.emptySet();
}
SearchScope customScope = myFindModel.getCustomScope();
GlobalSearchScope scope = myPsiDirectory != null
? GlobalSearchScopesCore.directoryScope(myPsiDirectory, myFindModel.isWithSubdirectories())
: myModule != null
? myModule.getModuleContentScope()
: customScope instanceof GlobalSearchScope
? (GlobalSearchScope)customScope
: toGlobal(customScope);
if (scope == null) {
scope = ProjectScope.getContentScope(myProject);
}
GlobalSearchScope scope = toGlobal(FindInProjectUtil.getScopeFromModel(myProject, myFindModel));
final Set<VirtualFile> resultFiles = new LinkedHashSet<VirtualFile>();
@@ -49,10 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.ex.VirtualFileManagerEx;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScopesCore;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.*;
import com.intellij.ui.content.Content;
import com.intellij.usageView.UsageInfo;
import com.intellij.usageView.UsageViewManager;
@@ -443,7 +440,7 @@ public class FindInProjectUtil {
}
@NotNull
private static SearchScope getScopeFromModel(@NotNull Project project, @NotNull FindModel findModel) {
static SearchScope getScopeFromModel(@NotNull Project project, @NotNull FindModel findModel) {
SearchScope customScope = findModel.getCustomScope();
PsiDirectory psiDir = getPsiDirectory(findModel, project);
VirtualFile directory = psiDir == null ? null : psiDir.getVirtualFile();
@@ -452,8 +449,8 @@ public class FindInProjectUtil {
// we don't have to check for myProjectFileIndex.isExcluded(file) here like FindInProjectTask.collectFilesInScope() does
// because all found usages are guaranteed to be not in excluded dir
directory != null ? GlobalSearchScopesCore.directoryScope(project, directory, findModel.isWithSubdirectories()) :
module != null ? GlobalSearchScope.moduleScope(module) :
findModel.isProjectScope() ? GlobalSearchScope.projectScope(project) :
module != null ? module.getModuleContentScope() :
findModel.isProjectScope() ? ProjectScope.getContentScope(project) :
GlobalSearchScope.allScope(project);
}
}
@@ -28,7 +28,10 @@ import java.util.TreeMap;
@State(
name = "Registry",
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml")
storages = {
@Storage(file = StoragePathMacros.APP_CONFIG + "/ide.general.xml"),
@Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml", deprecated = true)
}
)
public class RegistryState implements PersistentStateComponent<Element> {
private static final Logger LOG = Logger.getInstance(RegistryState.class);
@@ -215,7 +215,10 @@ public class StartupManagerImpl extends StartupManagerEx {
}
});
Registry.get("ide.firstStartup").setValue(false);
// otherwise will be stored - we must not create config files in tests
if (!app.isUnitTestMode()) {
Registry.get("ide.firstStartup").setValue(false);
}
}
public void scheduleInitialVfsRefresh() {
@@ -225,6 +225,7 @@ public final class NettyUtil {
.allowCredentials()
.allowNullOrigin()
.allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.PATCH)
.allowedRequestHeaders("origin", "accept", "authorization", "content-type")
.build()));
}
@@ -228,8 +228,8 @@ action.NewClass.text=Java Class
action.NewFile.text=File
action.NewDir.text=Directory/Package
action.NewFromTemplate.text=From Template
action.CompareTwoFiles.text=Compare Two _Files
action.CompareTwoFiles.description=Compare two selected files
action.CompareTwoFiles.text=Compare _Files
action.CompareTwoFiles.description=Compare two selected files or folders
action.CompareFileWithEditor.text=Co_mpare File with Editor
action.CompareFileWithEditor.description=Compare selected file with editor
action.ShowQuickDocAtPinnedWindowFromTooltip.text=Full documentation in a pinned window
@@ -25,6 +25,11 @@ import com.intellij.usages.UsageTarget;
import com.intellij.usages.UsageViewManager;
public class UsageViewManagerTest extends PlatformTestCase {
static {
initPlatformLangPrefix();
}
public void testScopeCreatedForFindInDirectory() {
VirtualFile dir = getProject().getBaseDir();
FindModel findModel = new FindModel();
@@ -36,4 +41,14 @@ public class UsageViewManagerTest extends PlatformTestCase {
SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[]{target});
assertEquals(scope, GlobalSearchScopesCore.directoryScope(getProject(), dir, true));
}
public void testScopeCreatedForFindInModuleContent() {
FindModel findModel = new FindModel();
findModel.setModuleName(getModule().getName());
findModel.setProjectScope(false);
UsageTarget target = new FindInProjectUtil.StringUsageTarget(getProject(), findModel);
UsageViewManagerImpl manager = (UsageViewManagerImpl)UsageViewManager.getInstance(getProject());
SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[]{target});
assertEquals(scope, getModule().getModuleContentScope());
}
}
@@ -257,6 +257,9 @@ java.annotations.inference.nullable.method.description=Restart is required; infe
java.annotations.inference.nullable.method.transitivity=true
java.annotations.inference.nullable.method.transitivity.description=Restart is required; if a method result is a call to a @Nullable method, reports the caller as @Nullable as well
java.correct.class.type.by.place.resolve.scope=true
java.correct.class.type.by.place.resolve.scope.description=When resolving Java references, use the resolve scope of the currently processed source file
documentation.component.editor.font=false
ide.completion.show.better.matching.classes=true
@@ -27,25 +27,28 @@ public class StudySmartChecker {
private StudySmartChecker() {
}
private static final Logger LOG = Logger.getInstance(StudySmartChecker.class);
public static void smartCheck(@NotNull final AnswerPlaceholder placeholder,
@NotNull final Project project,
@NotNull final VirtualFile answerFile,
@NotNull final TaskFile answerTaskFile,
@NotNull final TaskFile usersTaskFile,
@NotNull final StudyTestRunner testRunner,
@NotNull final VirtualFile virtualFile,
@NotNull final Document usersDocument) {
@NotNull final Project project,
@NotNull final VirtualFile answerFile,
@NotNull final TaskFile answerTaskFile,
@NotNull final TaskFile usersTaskFile,
@NotNull final StudyTestRunner testRunner,
@NotNull final VirtualFile virtualFile,
@NotNull final Document usersDocument) {
try {
final int index = placeholder.getIndex();
String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
final VirtualFile windowCopy =
answerFile.copy(project, answerFile.getParent(), answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX);
answerFile.copy(project, answerFile.getParent(), windowCopyName);
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document windowDocument = documentManager.getDocument(windowCopy);
if (windowDocument != null) {
final File resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
final File resourceFile =
StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
final TaskFile windowTaskFile = new TaskFile();
TaskFile.copy(answerTaskFile, windowTaskFile);
EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
@@ -85,5 +88,4 @@ public class StudySmartChecker {
LOG.error(e);
}
}
}
@@ -25,7 +25,7 @@ public class EduNames {
public static final String TEST_TAB_NAME = "test";
public static final String USER_TEST_INPUT = "input";
public static final String USER_TEST_OUTPUT = "output";
public static final String WINDOW_POSTFIX = "_window.py";
public static final String WINDOW_POSTFIX = "_window.";
public static final String TASK = "task";
public static final String USER_TESTS = "userTests";
public static final String SANDBOX_DIR = "Sandbox";
@@ -15,14 +15,18 @@ public class CourseInfo {
private String myName;
@SerializedName("summary")
private String myDescription;
@SerializedName("course_format")
//course type in format "pycharm <language>"
private String myType;
private String myAuthor;
public static CourseInfo INVALID_COURSE = new CourseInfo("", "", "");
public static CourseInfo INVALID_COURSE = new CourseInfo("", "", "", "");
public CourseInfo(String name, String author, String description) {
public CourseInfo(String name, String author, String description, String type) {
myName = name;
myAuthor = author;
myDescription = description;
myType = type;
}
public String getName() {
@@ -37,6 +41,10 @@ public class CourseInfo {
return myDescription;
}
public String getType() {
return myType;
}
@Override
public String toString() {
return myName;
@@ -41,6 +41,8 @@ public class EduStepicConnector {
private static final String ourDomain = "stepic.org";
private static String ourSessionId = "524iethiwju2tjywaqmf7tbwx0p0jk1b";
private static String ourCSRFToken = "LJ9n6OyLVA7hxU94dlYWUu65MF51Nx37";
//this prefix indicates that course can be opened by educational plugin
public static final String PYCHARM_PREFIX = "pycharm ";
private EduStepicConnector() {
}
@@ -84,7 +86,8 @@ public class EduStepicConnector {
course.setAuthor(info.getAuthor());
course.setDescription(info.getDescription());
course.setName(info.getName());
course.setLanguage("Python"); // TODO: get from stepic
String courseType = info.getType();
course.setLanguage(courseType.substring(PYCHARM_PREFIX.length()));
course.setUpToDate(true); // TODO: get from stepic
try {
for (Integer section : info.sections) {
@@ -104,8 +104,9 @@ public class PyContentEntriesModuleConfigurable extends SearchableConfigurable.P
@Override
public void apply() throws ConfigurationException {
if (myEditor == null) return;
final boolean editorWasModified = myEditor.isModified();
myEditor.apply();
if (myModifiableModel.isChanged()) {
if (editorWasModified) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
@@ -49,6 +49,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -64,6 +65,7 @@ import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xml.XmlAttributeDescriptor;
import com.intellij.xml.XmlBundle;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.impl.schema.XmlElementDescriptorImpl;
import com.intellij.xml.util.*;
import gnu.trove.THashSet;
@@ -1422,7 +1424,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase {
Editor[] allEditors = EditorFactory.getInstance().getAllEditors();
final Editor schemaEditor = allEditors[0] == myEditor ? allEditors[1]:allEditors[0];
final String text = schemaEditor.getDocument().getText();
final String newText = text.replaceAll("xsd","xs");
final String newText = text.replaceAll("xsd", "xs");
WriteCommandAction.runWriteCommandAction(null, new Runnable(){
@Override
public void run() {
@@ -1767,7 +1769,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase {
final String testName = getTestName(false);
String[][] urls = {
{"urn:jboss:bean-deployer:2.0", testName + ".xsd"},
{null, testName + "_2.xsd"}
{"", testName + "_2.xsd"}
};
doTestWithLocations(urls,"xml");
}
@@ -2082,6 +2084,26 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase {
assertTrue(resolve instanceof XmlTag);
}
public void testDropAnyAttributeCacheOnExitFromDumbMode() throws Exception {
try {
DumbServiceImpl.getInstance(myProject).setDumb(true);
configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"),
getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"),
getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
XmlElementDescriptor descriptor = tag.getDescriptor();
XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
System.out.println(Arrays.asList(descriptors));
}
finally {
DumbServiceImpl.getInstance(myProject).setDumb(false);
}
doDoTest(true, false);
}
public void testQualifiedAttributeReference() throws Exception {
configureByFiles(null, BASE_PATH + "qualified.xml", BASE_PATH + "qualified.xsd");
doDoTest(true, false);
@@ -38,7 +38,7 @@ public abstract class ExternalResourceManager extends SimpleModificationTracker
public abstract void removeResource(@NotNull String url, @Nullable String version);
/**
* @see #getResourceLocation(String, com.intellij.openapi.project.Project)
* @see #getResourceLocation(String, Project)
*/
@Deprecated
public abstract String getResourceLocation(@NotNull @NonNls String url);
@@ -15,10 +15,11 @@
*/
package com.intellij.xml.impl.schema;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.FieldCache;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.SchemaReferencesProvider;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.util.CachedValue;
@@ -85,17 +86,26 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
}
};
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private final FactoryMap<String, CachedValue<CanContainAttributeType>> myAnyAttributeCache = new ConcurrentFactoryMap<String, CachedValue<CanContainAttributeType>>() {
@Override
protected CachedValue<CanContainAttributeType> create(final String key) {
return CachedValuesManager.getManager(myTag.getProject()).createCachedValue(new CachedValueProvider<CanContainAttributeType>() {
@Override
public Result<CanContainAttributeType> compute() {
THashSet<PsiFile> dependencies = new THashSet<PsiFile>();
THashSet<Object> dependencies = new THashSet<Object>();
CanContainAttributeType type = _canContainAttribute(key, myTag, null, new THashSet<String>(), dependencies);
if (dependencies.isEmpty()) {
dependencies.add(myTag.getContainingFile());
}
if (DumbService.isDumb(myTag.getProject())) {
dependencies.add(new ModificationTracker() {
@Override
public long getModificationCount() {
return DumbService.isDumb(myTag.getProject()) ? 0 : 1;
}
});
}
return Result.create(type, ArrayUtil.toObjectArray(dependencies));
}
}, false);
@@ -398,7 +408,7 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
XmlTag tag,
@Nullable String qName,
Set<String> visited,
@Nullable Set<PsiFile> dependencies) {
@Nullable Set<Object> dependencies) {
if (XmlNSDescriptorImpl.equalsToSchemaName(tag, "anyAttribute")) {
if (dependencies != null) {
dependencies.add(tag.getContainingFile());