mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
explicit "allow modificaiton" option and //lang comment initial
This commit is contained in:
@@ -368,11 +368,9 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean ensureAnnotationsJarInPath(final Module module, String annotationName) {
|
||||
public static boolean ensureAnnotationsJarInPath(final Module module) {
|
||||
if (isAnnotationsJarInPath(module)) return true;
|
||||
if (module == null) return false;
|
||||
final PsiClass psiClass = JavaPsiFacade.getInstance(module.getProject())
|
||||
.findClass(annotationName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
|
||||
if (psiClass != null) return true;
|
||||
final LocateLibraryDialog dialog = new LocateLibraryDialog(
|
||||
module, PathManager.getLibPath(), "annotations.jar",
|
||||
QuickFixBundle.message("add.library.annotations.description"));
|
||||
@@ -388,4 +386,10 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAnnotationsJarInPath(Module module) {
|
||||
if (module == null) return false;
|
||||
return JavaPsiFacade.getInstance(module.getProject())
|
||||
.findClass(AnnotationUtil.LANGUAGE, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) != null;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-3
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.intellij.plugins.intelliLang.AdvancedSettingsUI">
|
||||
<grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myRoot" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="5" left="8" bottom="5" right="8"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="562" height="499"/>
|
||||
<xy x="20" y="20" width="562" height="527"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -167,9 +167,17 @@
|
||||
<text value="Convert undefined operands to &text in concatenations"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c2199" class="javax.swing.JCheckBox" binding="mySourceModificationAllowedCheckBox">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Add @Language annotation or comment if needed"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="5c670">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
|
||||
+6
@@ -59,6 +59,7 @@ public class AdvancedSettingsUI implements Configurable {
|
||||
private JRadioButton myUseDfa;
|
||||
private JRadioButton myLookForAssignments;
|
||||
private JCheckBox myIncludeUncomputableOperandsAsCheckBox;
|
||||
private JCheckBox mySourceModificationAllowedCheckBox;
|
||||
|
||||
private final ReferenceEditorWithBrowseButton myAnnotationField;
|
||||
private final ReferenceEditorWithBrowseButton myPatternField;
|
||||
@@ -138,6 +139,9 @@ public class AdvancedSettingsUI implements Configurable {
|
||||
if (myConfiguration.isIncludeUncomputablesAsLiterals() != myIncludeUncomputableOperandsAsCheckBox.isSelected()) {
|
||||
return true;
|
||||
}
|
||||
if (myConfiguration.isSourceModificationAllowed() != mySourceModificationAllowedCheckBox.isSelected()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ public class AdvancedSettingsUI implements Configurable {
|
||||
|
||||
myConfiguration.setDfaOption(getDfaOption());
|
||||
myConfiguration.setIncludeUncomputablesAsLiterals(myIncludeUncomputableOperandsAsCheckBox.isSelected());
|
||||
myConfiguration.setSourceModificationAllowed(mySourceModificationAllowedCheckBox.isSelected());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -181,6 +186,7 @@ public class AdvancedSettingsUI implements Configurable {
|
||||
|
||||
setDfaOption(myConfiguration.getDfaOption());
|
||||
myIncludeUncomputableOperandsAsCheckBox.setSelected(myConfiguration.isIncludeUncomputablesAsLiterals());
|
||||
mySourceModificationAllowedCheckBox.setSelected(myConfiguration.isSourceModificationAllowed());
|
||||
}
|
||||
|
||||
private void setDfaOption(@NotNull final Configuration.DfaOption dfaOption) {
|
||||
|
||||
+26
-2
@@ -19,7 +19,9 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.injection.ConcatenationAwareInjector;
|
||||
import com.intellij.lang.injection.MultiHostRegistrar;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.psi.*;
|
||||
@@ -225,7 +227,7 @@ public class ConcatenationInjector implements ConcatenationAwareInjector {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (areThereInjectionsWithName(variable.getName(), false)) {
|
||||
if (!processCommentInjections(variable) && areThereInjectionsWithName(variable.getName(), false)) {
|
||||
process(variable, null, -1);
|
||||
}
|
||||
return false;
|
||||
@@ -272,6 +274,28 @@ public class ConcatenationInjector implements ConcatenationAwareInjector {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processCommentInjections(PsiVariable owner) {
|
||||
PsiElement prev = owner.getFirstChild();
|
||||
if (prev instanceof PsiComment) {
|
||||
String text = ElementManipulators.getValueText(prev).trim();
|
||||
Language language = null;
|
||||
for (int idx = 0, len = text.length(); idx != -1 && language == null; idx = StringUtil.indexOfAny(text, " \t\r\n,", idx + 1, len)) {
|
||||
String id = idx > 0 ? text.substring(0, idx).trim() : text;
|
||||
language = Language.findLanguageByID(id);
|
||||
}
|
||||
if (language != null) {
|
||||
final BaseInjection injection = new BaseInjection(LanguageInjectionSupport.JAVA_SUPPORT_ID);
|
||||
//if (prefix != null) injection.setPrefix(prefix);
|
||||
//if (suffix != null) injection.setSuffix(suffix);
|
||||
injection.setInjectedLanguageId(language.getID());
|
||||
processInjectionWithContext(myUnparsable, injection, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void process(final PsiModifierListOwner owner, PsiMethod method, int paramIndex) {
|
||||
if (!processAnnotationInjections(owner)) {
|
||||
myShouldStop = true;
|
||||
|
||||
+7
-3
@@ -201,13 +201,17 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
|
||||
}
|
||||
|
||||
static boolean doAddLanguageAnnotation(final Project project, final PsiModifierListOwner modifierListOwner,
|
||||
final String languageId) {
|
||||
final String languageId) {
|
||||
if (!Configuration.getProjectInstance(project).getAdvancedConfiguration().isSourceModificationAllowed()) return false;
|
||||
if (modifierListOwner.getModifierList() == null || !PsiUtil.isLanguageLevel5OrHigher(modifierListOwner)) return false;
|
||||
if (!OrderEntryFix.ensureAnnotationsJarInPath(ModuleUtil.findModuleForPsiElement(modifierListOwner), AnnotationUtil.LANGUAGE)) return false;
|
||||
if (!OrderEntryFix.isAnnotationsJarInPath(ModuleUtil.findModuleForPsiElement(modifierListOwner))) {
|
||||
// todo add languageId comment
|
||||
return false;
|
||||
}
|
||||
new WriteCommandAction(project, modifierListOwner.getContainingFile()) {
|
||||
protected void run(final Result result) throws Throwable {
|
||||
final PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory()
|
||||
.createAnnotationFromText("@" + AnnotationUtil.LANGUAGE + "(\"" + languageId + "\")", modifierListOwner);
|
||||
.createAnnotationFromText("@" + AnnotationUtil.LANGUAGE + "(\"" + languageId + "\")", modifierListOwner);
|
||||
final PsiModifierList list = modifierListOwner.getModifierList();
|
||||
assert list != null;
|
||||
final PsiAnnotation existingAnnotation = list.findAnnotation(AnnotationUtil.LANGUAGE);
|
||||
|
||||
@@ -178,6 +178,7 @@ public class Configuration implements PersistentStateComponent<Element>, Modific
|
||||
@NonNls private static final String LOOK_FOR_VAR_ASSIGNMENTS = "LOOK_FOR_VAR_ASSIGNMENTS";
|
||||
@NonNls private static final String USE_DFA_IF_AVAILABLE = "USE_DFA_IF_AVAILABLE";
|
||||
@NonNls private static final String INCLUDE_UNCOMPUTABLES_AS_LITERALS = "INCLUDE_UNCOMPUTABLES_AS_LITERALS";
|
||||
@NonNls private static final String SOURCE_MODIFICATION_ALLOWED = "SOURCE_MODIFICATION_ALLOWED";
|
||||
|
||||
private final Map<String, List<BaseInjection>> myInjections = new ConcurrentFactoryMap<String, List<BaseInjection>>() {
|
||||
@Override
|
||||
@@ -566,6 +567,7 @@ public class Configuration implements PersistentStateComponent<Element>, Modific
|
||||
|
||||
private boolean myIncludeUncomputablesAsLiterals;
|
||||
private DfaOption myDfaOption = DfaOption.RESOLVE;
|
||||
private boolean mySourceModificationAllowed;
|
||||
|
||||
// cached annotation name pairs
|
||||
private Pair<String, ? extends Set<String>> myLanguageAnnotationPair;
|
||||
@@ -648,6 +650,13 @@ public class Configuration implements PersistentStateComponent<Element>, Modific
|
||||
myDfaOption = dfaOption;
|
||||
}
|
||||
|
||||
public boolean isSourceModificationAllowed() {
|
||||
return mySourceModificationAllowed;
|
||||
}
|
||||
|
||||
public void setSourceModificationAllowed(boolean sourceModificationAllowed) {
|
||||
mySourceModificationAllowed = sourceModificationAllowed;
|
||||
}
|
||||
|
||||
public InstrumentationType getInstrumentation() {
|
||||
return myInstrumentationType;
|
||||
@@ -658,6 +667,12 @@ public class Configuration implements PersistentStateComponent<Element>, Modific
|
||||
JDOMExternalizerUtil.writeField(element, LANGUAGE_ANNOTATION_NAME, myLanguageAnnotation);
|
||||
JDOMExternalizerUtil.writeField(element, PATTERN_ANNOTATION_NAME, myPatternAnnotation);
|
||||
JDOMExternalizerUtil.writeField(element, SUBST_ANNOTATION_NAME, mySubstAnnotation);
|
||||
if (myIncludeUncomputablesAsLiterals) {
|
||||
JDOMExternalizerUtil.writeField(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, "true");
|
||||
}
|
||||
if (mySourceModificationAllowed) {
|
||||
JDOMExternalizerUtil.writeField(element, SOURCE_MODIFICATION_ALLOWED, "true");
|
||||
}
|
||||
switch (myDfaOption) {
|
||||
case OFF:
|
||||
break;
|
||||
@@ -688,6 +703,7 @@ public class Configuration implements PersistentStateComponent<Element>, Modific
|
||||
setDfaOption(DfaOption.DFA);
|
||||
}
|
||||
setIncludeUncomputablesAsLiterals(readBoolean(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, false));
|
||||
setSourceModificationAllowed(readBoolean(element, SOURCE_MODIFICATION_ALLOWED, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user