summaryrefslogtreecommitdiff
path: root/platform/lang-api/src/com/intellij/psi
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-api/src/com/intellij/psi')
-rw-r--r--platform/lang-api/src/com/intellij/psi/WeigherExtensionPoint.java18
-rw-r--r--platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java40
-rw-r--r--platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java20
3 files changed, 43 insertions, 35 deletions
diff --git a/platform/lang-api/src/com/intellij/psi/WeigherExtensionPoint.java b/platform/lang-api/src/com/intellij/psi/WeigherExtensionPoint.java
index 2c38cd057b2b..11bf87e7a2cd 100644
--- a/platform/lang-api/src/com/intellij/psi/WeigherExtensionPoint.java
+++ b/platform/lang-api/src/com/intellij/psi/WeigherExtensionPoint.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -18,11 +18,10 @@ package com.intellij.psi;
import com.intellij.openapi.extensions.AbstractExtensionPointBean;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.util.KeyedLazyInstance;
+import com.intellij.util.ReflectionUtil;
import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.NotNull;
-import java.lang.reflect.Constructor;
-
/**
* @author peter
*/
@@ -44,24 +43,13 @@ public class WeigherExtensionPoint extends AbstractExtensionPointBean implements
protected final Weigher compute() {
try {
Class<Weigher> tClass = findClass(implementationClass);
- Constructor<Weigher> constructor = tClass.getConstructor();
- constructor.setAccessible(true);
- final Weigher weigher = tClass.newInstance();
+ final Weigher weigher = ReflectionUtil.newInstance(tClass);
weigher.setDebugName(id);
return weigher;
}
- catch (InstantiationException e) {
- throw new RuntimeException(e);
- }
- catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
- catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
}
};
diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java
index d858bfc01fcb..2683db2a846d 100644
--- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java
+++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java
@@ -113,7 +113,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
}
}
- public <T extends CustomCodeStyleSettings> T getCustomSettings(Class<T> aClass) {
+ public <T extends CustomCodeStyleSettings> T getCustomSettings(@NotNull Class<T> aClass) {
synchronized (myCustomSettings) {
return (T)myCustomSettings.get(aClass);
}
@@ -127,7 +127,9 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
}
private void copyCustomSettingsFrom(@NotNull CodeStyleSettings from) {
- myCustomSettings.clear();
+ synchronized (myCustomSettings) {
+ myCustomSettings.clear();
+ }
for (final CustomCodeStyleSettings settings : from.getCustomSettingsValues()) {
addCustomSettings((CustomCodeStyleSettings) settings.clone());
}
@@ -247,6 +249,10 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
public int INNER_CLASSES_ORDER_WEIGHT = 7;
//----------------- WRAPPING ---------------------------
+ /**
+ * @deprecated Use get/setRightMargin() methods instead.
+ */
+ @Deprecated
public int RIGHT_MARGIN = 120;
public boolean WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = false;
@@ -435,6 +441,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
private CodeStyleSettings myParentSettings;
private boolean myLoadedAdditionalIndentOptions;
+ @NotNull
private Collection<CustomCodeStyleSettings> getCustomSettingsValues() {
synchronized (myCustomSettings) {
return Collections.unmodifiableCollection(myCustomSettings.values());
@@ -524,7 +531,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
@NonNls Element option = (Element)option1;
@NonNls final String name = option.getAttributeValue("name");
if ("TAB_SIZE".equals(name)) {
- final int value = Integer.valueOf(option.getAttributeValue("value")).intValue();
+ final int value = Integer.parseInt(option.getAttributeValue("value"));
JAVA_INDENT_OPTIONS.TAB_SIZE = value;
JSP_INDENT_OPTIONS.TAB_SIZE = value;
XML_INDENT_OPTIONS.TAB_SIZE = value;
@@ -532,7 +539,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
optionsImported = true;
}
else if ("INDENT_SIZE".equals(name)) {
- final int value = Integer.valueOf(option.getAttributeValue("value")).intValue();
+ final int value = Integer.parseInt(option.getAttributeValue("value"));
JAVA_INDENT_OPTIONS.INDENT_SIZE = value;
JSP_INDENT_OPTIONS.INDENT_SIZE = value;
XML_INDENT_OPTIONS.INDENT_SIZE = value;
@@ -540,7 +547,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
optionsImported = true;
}
else if ("CONTINUATION_INDENT_SIZE".equals(name)) {
- final int value = Integer.valueOf(option.getAttributeValue("value")).intValue();
+ final int value = Integer.parseInt(option.getAttributeValue("value"));
JAVA_INDENT_OPTIONS.CONTINUATION_INDENT_SIZE = value;
JSP_INDENT_OPTIONS.CONTINUATION_INDENT_SIZE = value;
XML_INDENT_OPTIONS.CONTINUATION_INDENT_SIZE = value;
@@ -548,7 +555,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
optionsImported = true;
}
else if ("USE_TAB_CHARACTER".equals(name)) {
- final boolean value = Boolean.valueOf(option.getAttributeValue("value")).booleanValue();
+ final boolean value = Boolean.parseBoolean(option.getAttributeValue("value"));
JAVA_INDENT_OPTIONS.USE_TAB_CHARACTER = value;
JSP_INDENT_OPTIONS.USE_TAB_CHARACTER = value;
XML_INDENT_OPTIONS.USE_TAB_CHARACTER = value;
@@ -556,14 +563,15 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
optionsImported = true;
}
else if ("SMART_TABS".equals(name)) {
- final boolean value = Boolean.valueOf(option.getAttributeValue("value")).booleanValue();
+ final boolean value = Boolean.parseBoolean(option.getAttributeValue("value"));
JAVA_INDENT_OPTIONS.SMART_TABS = value;
JSP_INDENT_OPTIONS.SMART_TABS = value;
XML_INDENT_OPTIONS.SMART_TABS = value;
OTHER_INDENT_OPTIONS.SMART_TABS = value;
optionsImported = true;
- } else if ("SPACE_AFTER_UNARY_OPERATOR".equals(name)) {
- SPACE_AROUND_UNARY_OPERATOR = Boolean.valueOf(option.getAttributeValue("value")).booleanValue();
+ }
+ else if ("SPACE_AFTER_UNARY_OPERATOR".equals(name)) {
+ SPACE_AROUND_UNARY_OPERATOR = Boolean.parseBoolean(option.getAttributeValue("value"));
optionsImported = true;
}
}
@@ -751,6 +759,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
myNames.addAll(from.myNames);
}
+ @Override
public boolean equals(Object other) {
if (other instanceof TypeToNameMap) {
TypeToNameMap otherMap = (TypeToNameMap)other;
@@ -759,6 +768,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
return false;
}
+ @Override
public int hashCode() {
int code = 0;
for (String myPattern : myPatterns) {
@@ -900,7 +910,7 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
if (langSettings.RIGHT_MARGIN >= 0) return langSettings.RIGHT_MARGIN;
}
}
- return RIGHT_MARGIN;
+ return getDefaultRightMargin();
}
/**
@@ -917,6 +927,16 @@ public class CodeStyleSettings extends CommonCodeStyleSettings implements Clonea
return;
}
}
+ setDefaultRightMargin(rightMargin);
+ }
+
+ @SuppressWarnings("deprecation")
+ public int getDefaultRightMargin() {
+ return RIGHT_MARGIN;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultRightMargin(int rightMargin) {
RIGHT_MARGIN = rightMargin;
}
}
diff --git a/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java b/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java
index 56fe91a0dc28..13f84cb1dc4f 100644
--- a/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java
+++ b/platform/lang-api/src/com/intellij/psi/util/PsiUtilBase.java
@@ -32,6 +32,7 @@ import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.util.TextRange;
+import com.intellij.openapi.vfs.NonPhysicalFileSystem;
import com.intellij.openapi.vfs.VFileProperty;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
@@ -221,12 +222,13 @@ public class PsiUtilBase extends PsiUtilCore implements PsiEditorUtil {
* Tries to find editor for the given element.
* <p/>
* There are at least two approaches to achieve the target. Current method is intended to encapsulate both of them:
- * <pre>
* <ul>
* <li>target editor works with a real file that remains at file system;</li>
* <li>target editor works with a virtual file;</li>
* </ul>
- * </pre>
+ * <p/>
+ * Please don't use this method for finding an editor for quick fix.
+ * @see {@link com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement}
*
* @param element target element
* @return editor that works with a given element if the one is found; <code>null</code> otherwise
@@ -234,30 +236,28 @@ public class PsiUtilBase extends PsiUtilCore implements PsiEditorUtil {
@Nullable
public static Editor findEditor(@NotNull PsiElement element) {
PsiFile psiFile = element.getContainingFile();
- if (psiFile == null) {
- return null;
- }
- VirtualFile virtualFile = psiFile.getOriginalFile().getVirtualFile();
+ VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (virtualFile == null) {
return null;
}
- if (virtualFile.isInLocalFileSystem()) {
+ Project project = psiFile.getProject();
+ if (virtualFile.isInLocalFileSystem() || virtualFile.getFileSystem() instanceof NonPhysicalFileSystem) {
// Try to find editor for the real file.
- final FileEditor[] editors = FileEditorManager.getInstance(psiFile.getProject()).getEditors(virtualFile);
+ final FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(virtualFile);
for (FileEditor editor : editors) {
if (editor instanceof TextEditor) {
return ((TextEditor)editor).getEditor();
}
}
}
- else if (SwingUtilities.isEventDispatchThread()) {
+ if (SwingUtilities.isEventDispatchThread()) {
// We assume that data context from focus-based retrieval should success if performed from EDT.
AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus();
if (asyncResult.isDone()) {
Editor editor = CommonDataKeys.EDITOR.getData(asyncResult.getResult());
if (editor != null) {
- Document cachedDocument = PsiDocumentManager.getInstance(psiFile.getProject()).getCachedDocument(psiFile);
+ Document cachedDocument = PsiDocumentManager.getInstance(project).getCachedDocument(psiFile);
// Ensure that target editor is found by checking its document against the one from given PSI element.
if (cachedDocument == editor.getDocument()) {
return editor;