diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/config/Option.java b/grammar-kit-core/src/main/java/org/intellij/grammar/config/Option.java index 065164c8..9fc31f9f 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/config/Option.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/config/Option.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.grammar.config; import consulo.util.lang.ObjectUtil; @@ -33,6 +32,7 @@ abstract class Option implements Supplier { this.defValue = defValue; } + @Override public abstract T get(); String innerValue() { @@ -40,7 +40,7 @@ String innerValue() { } static Option intOption(String id, int def) { - return new Option(id, def) { + return new Option<>(id, def) { @Override public Integer get() { return StringUtil.parseInt(innerValue(), defValue); @@ -49,7 +49,7 @@ public Integer get() { } static Option strOption(String id, String def) { - return new Option(id, def) { + return new Option<>(id, def) { @Override public String get() { return ObjectUtil.chooseNotNull(innerValue(), defValue); diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/generator/NodeCalls.java b/grammar-kit-core/src/main/java/org/intellij/grammar/generator/NodeCalls.java index 9ca2b319..1d672cb2 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/generator/NodeCalls.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/generator/NodeCalls.java @@ -1,7 +1,6 @@ /* * Copyright 2011-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ - package org.intellij.grammar.generator; import consulo.util.collection.ContainerUtil; @@ -191,6 +190,7 @@ String getClassName() { } @Nonnull + @Override public String render(@Nonnull Names names) { if (renderClass) { return String.format("%s.%s(%s, %s + 1)", className, methodName, names.builder, names.level); diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/BnfNamedElement.java b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/BnfNamedElement.java index 950ebfa5..a1933ab3 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/BnfNamedElement.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/BnfNamedElement.java @@ -15,17 +15,19 @@ */ package org.intellij.grammar.psi; +import consulo.annotation.access.RequiredReadAction; import consulo.language.psi.PsiElement; import consulo.language.psi.PsiNameIdentifierOwner; import jakarta.annotation.Nonnull; /** - * User: gregory - * Date: 13.07.11 - * Time: 19:02 + * @author gregory + * @since 2011-07-13 */ public interface BnfNamedElement extends BnfComposite, PsiNameIdentifierOwner { @Nonnull + @Override + @RequiredReadAction String getName(); @Nonnull diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfFileImpl.java b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfFileImpl.java index 16707270..11b9e683 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfFileImpl.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfFileImpl.java @@ -38,9 +38,8 @@ import java.util.regex.Pattern; /** - * User: gregory - * Date: 13.07.11 - * Time: 23:55 + * @author gregory + * @since 2011-07-13 */ public class BnfFileImpl extends PsiFileBase implements BnfFile { private final CachedValue> myRules; @@ -98,6 +97,7 @@ public BnfAttr findAttribute( return PsiTreeUtil.getParentOfType(findElementAt(result.attrOffset), BnfAttr.class); } + @Override @RequiredReadAction public T findAttributeValue( @Nullable String version, diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfRefOrTokenImpl.java b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfRefOrTokenImpl.java index f443e2a5..a5ab8961 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfRefOrTokenImpl.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfRefOrTokenImpl.java @@ -15,6 +15,8 @@ */ package org.intellij.grammar.psi.impl; +import consulo.annotation.access.RequiredReadAction; +import consulo.annotation.access.RequiredWriteAction; import consulo.document.util.TextRange; import consulo.language.ast.ASTNode; import consulo.language.psi.PsiElement; @@ -28,10 +30,8 @@ import jakarta.annotation.Nullable; /** - * Created by IntelliJ IDEA. - * User: gregory - * Date: 14.07.11 - * Time: 19:17 + * @author gregory + * @since 2011-07-14 */ public abstract class BnfRefOrTokenImpl extends BnfExpressionImpl implements BnfReferenceOrToken { public BnfRefOrTokenImpl(ASTNode node) { @@ -39,17 +39,20 @@ public BnfRefOrTokenImpl(ASTNode node) { } @Nullable + @Override public BnfRule resolveRule() { PsiFile file = getContainingFile(); return file instanceof BnfFile bnfFile ? bnfFile.getRule(GrammarUtil.getIdText(getId())) : null; } @Override + @RequiredReadAction public PsiReference getReference() { int delta = GrammarUtil.isIdQuoted(getId().getText()) ? 1 : 0; TextRange range = TextRange.create(delta, getTextLength() - delta); return new BnfReferenceImpl(this, range) { @Override + @RequiredWriteAction public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { myElement.getId().replace(BnfElementFactory.createLeafFromText(getElement().getProject(), newElementName)); return myElement; diff --git a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfStringImpl.java b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfStringImpl.java index c25d9520..7a3db74e 100644 --- a/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfStringImpl.java +++ b/grammar-kit-core/src/main/java/org/intellij/grammar/psi/impl/BnfStringImpl.java @@ -15,6 +15,8 @@ */ package org.intellij.grammar.psi.impl; +import consulo.annotation.access.RequiredReadAction; +import consulo.annotation.access.RequiredWriteAction; import consulo.document.util.TextRange; import consulo.language.ast.ASTNode; import consulo.language.impl.psi.FakePsiElement; @@ -90,6 +92,7 @@ public PsiElement getNumber() { } @Nonnull + @Override public PsiReference[] getReferences() { // performance: do not run injectors // return PsiReferenceService.getService().getContributedReferences(this); @@ -114,8 +117,9 @@ public boolean isValidHost() { } @Override - public BnfStringImpl updateText(@Nonnull final String text) { - final BnfExpression expression = BnfElementFactory.createExpressionFromText(getProject(), text); + @RequiredWriteAction + public BnfStringImpl updateText(@Nonnull String text) { + BnfExpression expression = BnfElementFactory.createExpressionFromText(getProject(), text); assert expression instanceof BnfStringImpl : text + "-->" + expression; return (BnfStringImpl)this.replace(expression); } @@ -127,6 +131,7 @@ public LiteralTextEscaper createLiteralTextE } @Nullable + @RequiredReadAction private static Pattern getPattern(BnfLiteralExpression expression) { return ParserGeneratorUtil.compilePattern(StringUtil.stripQuotesAroundValue(expression.getText())); } @@ -142,6 +147,7 @@ public TextRange getRangeInElement() { } @Override + @RequiredWriteAction public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { BnfStringImpl element = getElement(); PsiElement string = element.getString(); @@ -176,17 +182,19 @@ public boolean isReferenceTo(PsiElement element) { @Nonnull @Override + @RequiredReadAction public ResolveResult[] multiResolve(boolean b) { return ResolveCache.getInstance(getElement().getProject()).resolveWithCaching(this, RESOLVER, false, b); } @Nonnull + @RequiredReadAction public ResolveResult[] multiResolveInner() { - final Pattern pattern = getPattern(getElement()); + Pattern pattern = getPattern(getElement()); if (pattern == null) { return ResolveResult.EMPTY_ARRAY; } - final List result = ContainerUtil.newArrayList(); + List result = new ArrayList<>(); BnfAttr thisAttr = ObjectUtil.assertNotNull(PsiTreeUtil.getParentOfType(getElement(), BnfAttr.class)); BnfAttrs thisAttrs = ObjectUtil.assertNotNull(PsiTreeUtil.getParentOfType(thisAttr, BnfAttrs.class)); @@ -249,6 +257,7 @@ public ResolveResult[] multiResolveInner() { } @Override + @RequiredWriteAction public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { // do not rename pattern return myElement; @@ -256,11 +265,13 @@ public PsiElement handleElementRename(String newElementName) throws IncorrectOpe @Nonnull @Override + @RequiredReadAction public Object[] getVariants() { return ArrayUtil.EMPTY_OBJECT_ARRAY; } } + @RequiredReadAction public static boolean matchesElement(@Nullable BnfLiteralExpression e1, @Nonnull PsiElement e2) { if (e1 == null) { return false; @@ -285,6 +296,7 @@ private static class MyFakePsiElement extends FakePsiElement implements BnfCompo } @Override + @RequiredReadAction public String getName() { return myFuncName; } @@ -296,6 +308,7 @@ public PsiElement getNavigationElement() { } @Override + @RequiredReadAction public TextRange getTextRange() { return myExpression.getTextRange(); } @@ -311,7 +324,8 @@ public R accept(@Nonnull BnfVisitor visitor) { } } - public static TextRange getStringTokenRange(final BnfStringImpl element) { + @RequiredReadAction + public static TextRange getStringTokenRange(BnfStringImpl element) { return TextRange.from(1, element.getTextLength() - 2); } } diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/editor/BnfColorSettingsPage.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/editor/BnfColorSettingsPage.java index 94556f9d..c6148d39 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/editor/BnfColorSettingsPage.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/editor/BnfColorSettingsPage.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.grammar.impl.editor; import consulo.annotation.component.ExtensionImpl; @@ -61,21 +60,25 @@ public class BnfColorSettingsPage implements ColorSettingsPage { } @Nonnull + @Override public LocalizeValue getDisplayName() { return LocalizeValue.localizeTODO("IntelliJ Grammar"); } @Nonnull + @Override public AttributesDescriptor[] getAttributeDescriptors() { return ATTRS; } @Nonnull + @Override public SyntaxHighlighter getHighlighter() { return new BnfSyntaxHighlighter(); } @Nonnull + @Override public String getDemoText() { return "/*\n" + " * Sample grammar\n" + @@ -102,8 +105,9 @@ public String getDemoText() { "\n"; } + @Override public Map getAdditionalHighlightingTagToDescriptorMap() { - final Map map = new HashMap<>(); + Map map = new HashMap<>(); map.put("r", RULE); map.put("mr", META_RULE); map.put("a", ATTRIBUTE); diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewParserDefinition.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewParserDefinition.java index f322cb3a..432450a6 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewParserDefinition.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewParserDefinition.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.grammar.impl.livePreview; +import consulo.annotation.access.RequiredReadAction; import consulo.language.ast.ASTNode; import consulo.language.parser.ParserDefinition; import consulo.language.lexer.Lexer; @@ -54,6 +54,7 @@ public LivePreviewParserDefinition(LivePreviewLanguage language) { myFileElementType = new IFileElementType(myLanguage); // todo do not register } + @Override public LivePreviewLanguage getLanguage() { return myLanguage; } @@ -65,6 +66,7 @@ public Lexer createLexer(LanguageVersion languageVersion) { } @Override + @RequiredReadAction public PsiParser createParser(LanguageVersion languageVersion) { return new LivePreviewParser(null, myLanguage); } @@ -94,6 +96,7 @@ public TokenSet getStringLiteralElements(LanguageVersion languageVersion) { @Nonnull @Override + @RequiredReadAction public PsiElement createElement(ASTNode node) { return new ASTWrapperPsiElement(node); } diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewStructureViewFactory.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewStructureViewFactory.java index ef9efcfc..5c8dc440 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewStructureViewFactory.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/livePreview/LivePreviewStructureViewFactory.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.grammar.impl.livePreview; +import consulo.annotation.access.RequiredReadAction; import consulo.codeEditor.CodeInsightColors; import consulo.codeEditor.Editor; import consulo.colorScheme.TextAttributesKey; @@ -48,6 +48,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; import static org.intellij.grammar.generator.ParserGeneratorUtil.getPsiClassFormat; import static org.intellij.grammar.generator.ParserGeneratorUtil.getRulePsiClassName; @@ -57,6 +58,8 @@ */ public class LivePreviewStructureViewFactory implements PsiStructureViewFactory { @Nullable + @Override + @RequiredReadAction public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { if (!(psiFile.getLanguage() instanceof LivePreviewLanguage)) { return null; @@ -101,7 +104,6 @@ public boolean isAlwaysShowsPlus(StructureViewTreeElement element) { public boolean isAlwaysLeaf(StructureViewTreeElement element) { return element.getValue() instanceof LeafPsiElement; } - } private static class MyElement extends PsiTreeElementBase implements SortableTreeElement, ColoredItemPresentation { @@ -110,12 +112,14 @@ private static class MyElement extends PsiTreeElementBase implements } @Nonnull + @Override + @RequiredReadAction public Collection getChildrenBase() { PsiElement element = getElement(); if (element == null || element instanceof LeafPsiElement) { return Collections.emptyList(); } - ArrayList result = new ArrayList(); + List result = new ArrayList<>(); for (PsiElement e = element.getFirstChild(); e != null; e = e.getNextSibling()) { if (e instanceof PsiWhiteSpace) { continue; @@ -126,12 +130,14 @@ public Collection getChildrenBase() { } @Override + @RequiredReadAction public String getAlphaSortKey() { return getPresentableText(); } @Nonnull @Override + @RequiredReadAction public String getPresentableText() { PsiElement element = getElement(); ASTNode node = element != null ? element.getNode() : null; @@ -139,11 +145,11 @@ public String getPresentableText() { if (element instanceof LeafPsiElement) { return elementType + ": '" + element.getText() + "'"; } - else if (element instanceof PsiErrorElement) { - return "PsiErrorElement: '" + ((PsiErrorElement)element).getErrorDescription() + "'"; + else if (element instanceof PsiErrorElement errorElem) { + return "PsiErrorElement: '" + errorElem.getErrorDescription() + "'"; } - else if (elementType instanceof LivePreviewElementType.RuleType) { - BnfRule rule = ((LivePreviewElementType.RuleType)elementType).getRule(element.getProject()); + else if (elementType instanceof LivePreviewElementType.RuleType ruleType) { + BnfRule rule = ruleType.getRule(element.getProject()); if (rule != null) { BnfFile file = (BnfFile)rule.getContainingFile(); String className = getRulePsiClassName(rule, getPsiClassFormat(file)); diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfInlineViewDescriptor.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfInlineViewDescriptor.java index 3cc15648..517ecb67 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfInlineViewDescriptor.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfInlineViewDescriptor.java @@ -15,7 +15,7 @@ */ package org.intellij.grammar.impl.refactor; -import consulo.language.editor.refactoring.RefactoringBundle; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; import consulo.language.psi.PsiElement; import consulo.usage.UsageViewBundle; import consulo.usage.UsageViewDescriptor; @@ -23,11 +23,8 @@ import org.intellij.grammar.psi.BnfRule; /** - * Created by IntelliJ IDEA. - * Date: 8/11/11 - * Time: 8:50 PM - * * @author Vadim Romansky + * @since 2011-08-11 */ public class BnfInlineViewDescriptor implements UsageViewDescriptor { private final BnfRule myElement; @@ -37,22 +34,23 @@ public BnfInlineViewDescriptor(BnfRule myElement) { } @Nonnull + @Override public PsiElement[] getElements() { return new PsiElement[]{myElement}; } + @Override public String getProcessedElementsHeader() { return "Rule"; } + @Override public String getCodeReferencesText(int usagesCount, int filesCount) { - return RefactoringBundle.message("invocations.to.be.inlined", UsageViewBundle.getReferencesString(usagesCount, filesCount)); + return RefactoringLocalize.invocationsToBeInlined(UsageViewBundle.getReferencesString(usagesCount, filesCount)).get(); } + @Override public String getCommentReferencesText(int usagesCount, int filesCount) { - return RefactoringBundle.message( - "comments.elements.header", - UsageViewBundle.getOccurencesString(usagesCount, filesCount) - ); + return RefactoringLocalize.commentsElementsHeader(UsageViewBundle.getOccurencesString(usagesCount, filesCount)).get(); } } diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceRuleAction.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceRuleAction.java index 431227d3..bf8d1544 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceRuleAction.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceRuleAction.java @@ -15,6 +15,7 @@ */ package org.intellij.grammar.impl.refactor; +import consulo.annotation.access.RequiredReadAction; import consulo.language.editor.refactoring.RefactoringSupportProvider; import consulo.language.editor.refactoring.action.BasePlatformRefactoringAction; import consulo.language.editor.refactoring.action.RefactoringActionHandler; @@ -25,17 +26,15 @@ import jakarta.annotation.Nonnull; /** - * Created by IntelliJ IDEA. - * Date: 8/16/11 - * Time: 5:14 PM - * * @author Vadim Romansky + * @since 2011-08-16 */ public class BnfIntroduceRuleAction extends BasePlatformRefactoringAction { public BnfIntroduceRuleAction() { setInjectedContext(true); } + @Override protected boolean isAvailableInEditorOnly() { return true; } @@ -45,6 +44,8 @@ protected boolean isAvailableForFile(PsiFile file) { return file instanceof BnfFile; } + @Override + @RequiredReadAction protected boolean isEnabledOnElements(PsiElement[] elements) { return false; } diff --git a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceTokenAction.java b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceTokenAction.java index e61c3635..223dcd18 100644 --- a/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceTokenAction.java +++ b/grammar-kit/src/main/java/org/intellij/grammar/impl/refactor/BnfIntroduceTokenAction.java @@ -30,6 +30,7 @@ public class BnfIntroduceTokenAction extends BasePlatformRefactoringAction { public BnfIntroduceTokenAction() { } + @Override protected boolean isAvailableInEditorOnly() { return true; } @@ -39,6 +40,7 @@ protected boolean isAvailableForFile(PsiFile file) { return file instanceof BnfFile; } + @Override protected boolean isEnabledOnElements(@Nonnull PsiElement[] elements) { return false; } @@ -48,4 +50,3 @@ protected RefactoringActionHandler getRefactoringHandler(@Nonnull RefactoringSup return new BnfIntroduceTokenHandler(); } } - diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/DTDModelLoader.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/DTDModelLoader.java index 5676b582..226c7052 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/DTDModelLoader.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/DTDModelLoader.java @@ -13,13 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; import com.wutka.dtd.*; @@ -29,12 +22,15 @@ import java.util.*; /** + * XSD/DTD Model generator tool + * * @author Gregory.Shrago * @author Konstantin Bulenkov */ public class DTDModelLoader implements ModelLoader { private ModelDesc model; + @Override public void loadModel(ModelDesc model, Collection schemas, XMLEntityResolver resolver) throws Exception { this.model = model; for (File dtdFile : schemas) { @@ -61,7 +57,6 @@ private NamespaceDesc ensureNamespaceExists(String ns) { return model.nsdMap.get(ns); } - private void loadDTDByWutka(String ns, File dtdFile) throws Exception { DTDParser parser = new DTDParser(dtdFile, false); // Parse the DTD and ask the parser to guess the root element @@ -70,31 +65,30 @@ private void loadDTDByWutka(String ns, File dtdFile) throws Exception { processDTD(ns, dtd, model.jtMap, model.nsdMap); } - private void processDTD(String namespace, DTD dtd, Map jtMap, Map nsdMap) { - final NamespaceDesc nsd = ensureNamespaceExists(namespace); + NamespaceDesc nsd = ensureNamespaceExists(namespace); if (nsd.skip) { return; } - final ArrayList resultQNames = new ArrayList<>(); - final DTDElement[] elements = new DTDElement[dtd.elements.size()]; + List resultQNames = new ArrayList<>(); + DTDElement[] elements = new DTDElement[dtd.elements.size()]; int ptr = 1; - final HashSet visitedElements = new HashSet<>(); + Set visitedElements = new HashSet<>(); elements[0] = dtd.rootElement; while (--ptr > -1) { - final DTDElement el = elements[ptr]; + DTDElement el = elements[ptr]; visitedElements.add(el); - final String typeName = model.toJavaTypeName(el.name, namespace); - final String typeQName = model.toJavaQualifiedTypeName(namespace, typeName, false); + String typeName = model.toJavaTypeName(el.name, namespace); + String typeQName = model.toJavaQualifiedTypeName(namespace, typeName, false); if (resultQNames.contains(typeQName)) { continue; } else { resultQNames.add(typeQName); } - final TypeDesc td = new TypeDesc(el.name, namespace, typeName, TypeDesc.TypeEnum.CLASS); + TypeDesc td = new TypeDesc(el.name, namespace, typeName, TypeDesc.TypeEnum.CLASS); boolean duplicates = false; if (el.content instanceof DTDAny || el.content instanceof DTDMixed) { FieldDesc fd = new FieldDesc(FieldDesc.SIMPLE, "value", "String", null, "null", false); @@ -115,22 +109,26 @@ private void processDTD(String namespace, DTD dtd, Map jtMap, fd1.realIndex = td.fdMap.size(); duplicates = Util.addToNameMap(td.fdMap, fd1, false) || duplicates; } - final ArrayList> choiceList = new ArrayList<>(); - final LinkedList plist = new LinkedList<>(); + List> choiceList = new ArrayList<>(); + List plist = new LinkedList<>(); if (el.content instanceof DTDContainer) { //if ((el.content instanceof DTDChoice) || (el.content instanceof DTDSequence)) { plist.add(new Entry(el.content, false, true)); } while (!plist.isEmpty()) { - final Entry pentry = plist.removeFirst(); + Entry pentry = plist.removeFirst(); - final DTDItem p = pentry.p; + DTDItem p = pentry.p; - if (p instanceof DTDName) { - final DTDName n = (DTDName)p; - final DTDElement nel = (DTDElement)dtd.elements.get(n.value); - final String pName = n.value; - final FieldDesc fd1 = new FieldDesc(FieldDesc.STR, Util.toJavaFieldName(pName), pName, null, "null", + if (p instanceof DTDName n) { + DTDElement nel = (DTDElement)dtd.elements.get(n.value); + String pName = n.value; + FieldDesc fd1 = new FieldDesc( + FieldDesc.STR, + Util.toJavaFieldName(pName), + pName, + null, + "null", pentry.required && (n.cardinal == DTDCardinal.ONEMANY || n.cardinal == DTDCardinal.NONE) ); fd1.tagName = pName; @@ -174,10 +172,10 @@ else if (hasTextContents) { else if (nel.content instanceof DTDContainer) { boolean hasAttrFields = false; boolean hasTextField = false; - if ((nel.content instanceof DTDMixed) && ((DTDMixed)nel.content).getItemsVec().size() == 1) { + if (nel.content instanceof DTDMixed mixed && mixed.getItemsVec().size() == 1) { hasTextField = true; for (Object o : nel.attributes.values()) { - final DTDAttribute attr = (DTDAttribute)o; + DTDAttribute attr = (DTDAttribute)o; if (attr.decl != DTDDecl.FIXED && !"ID".equals(attr.type)) { hasAttrFields = true; break; @@ -214,13 +212,12 @@ else if (nel.content instanceof DTDContainer) { fd1.realIndex = td.fdMap.size(); duplicates = Util.addToNameMap(td.fdMap, fd1, false) || duplicates; } - else if (p instanceof DTDContainer) { - final DTDContainer cont = (DTDContainer)p; - final boolean isChoice = cont instanceof DTDChoice; + else if (p instanceof DTDContainer cont) { + boolean isChoice = cont instanceof DTDChoice; // 0 - NONE, 1 - OPT, 2 - ZEROMANY, 3 - ONEMANY - final boolean required = + boolean required = !isChoice && pentry.required && p.cardinal != DTDCardinal.ZEROMANY && p.cardinal != DTDCardinal.OPTIONAL; - final boolean many = p.cardinal == DTDCardinal.ONEMANY || p.cardinal == DTDCardinal.ZEROMANY; + boolean many = p.cardinal == DTDCardinal.ONEMANY || p.cardinal == DTDCardinal.ZEROMANY; List l = cont.getItemsVec(); if (!many && isChoice) { choiceList.add(l); @@ -241,33 +238,33 @@ else if (p instanceof DTDContainer) { fd.idx = i++; } for (List l : choiceList) { - ArrayList clist = new ArrayList<>(); - LinkedList elist = new LinkedList<>(); + List cList = new ArrayList<>(); + List eList = new LinkedList<>(); for (i = 0; i < l.size(); i++) { - elist.add(l.get(i)); + eList.add(l.get(i)); } - while (!elist.isEmpty()) { - DTDItem p = elist.removeFirst(); + while (!eList.isEmpty()) { + DTDItem p = eList.removeFirst(); if (p instanceof DTDContainer dtdContainer) { List l2 = dtdContainer.getItemsVec(); for (DTDItem aL2 : l2) { - elist.addFirst(aL2); + eList.addFirst(aL2); } } else if (p instanceof DTDName) { - clist.add(p); + cList.add(p); } } boolean choiceOpt = true; - FieldDesc[] choice = new FieldDesc[clist.size()]; + FieldDesc[] choice = new FieldDesc[cList.size()]; for (i = 0; i < choice.length; i++) { - DTDName p = (DTDName)clist.get(i); + DTDName p = (DTDName)cList.get(i); String s = Util.toJavaFieldName(p.value); FieldDesc fd = td.fdMap.get(s); if (fd == null) { fd = td.fdMap.get(Util.pluralize(s)); if (fd == null) { - Util.logerr("uknown choice element: " + s); + Util.logerr("unknown choice element: " + s); continue; } } @@ -292,7 +289,7 @@ else if (p instanceof DTDName) { TypeDesc td = new TypeDesc(entity.name, namespace, typeName, TypeDesc.TypeEnum.ENUM); StringTokenizer st = new StringTokenizer(value, "(|)"); while (st.hasMoreTokens()) { - final String s = st.nextToken(); + String s = st.nextToken(); td.fdMap.put(s, new FieldDesc(Util.computeEnumConstantName(s, td.name), s)); } td.documentation = parseDTDItemDocumentation(dtd, entity, "Type " + entity.name + " documentation"); @@ -337,11 +334,10 @@ static class Entry { } } - private static void checkDTDRootElement(DTD dtd) throws Exception { if (dtd.rootElement == null) { - StringBuffer sb = new StringBuffer("Empty root: possible elements: "); - HashMap map = new HashMap(dtd.elements); + StringBuilder sb = new StringBuilder("Empty root: possible elements: "); + Map map = new HashMap(dtd.elements); for (Object o : dtd.elements.values()) { DTDElement el = (DTDElement)o; if (el.content instanceof DTDContainer dtdContainer) { diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/FieldDesc.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/FieldDesc.java index afa38140..8a4abdc0 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/FieldDesc.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/FieldDesc.java @@ -13,16 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; /** + * XSD/DTD Model generator tool + * + * @author Gregory Shrago * @author Konstantin Bulenkov */ public class FieldDesc implements Comparable { @@ -67,10 +63,12 @@ public FieldDesc(int clType, String name, String type, String elementType, Strin int realIndex; String contentQualifiedName; + @Override public int compareTo(FieldDesc o) { return name.compareTo(o.name); } + @Override public String toString() { return "Field: " + name + ";" + type + ";" + elementName + ";" + elementType; } diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/MergingFileManager.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/MergingFileManager.java index 7ac30aa4..b4464de8 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/MergingFileManager.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/MergingFileManager.java @@ -13,13 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; import consulo.util.collection.ArrayUtil; @@ -27,13 +20,18 @@ import java.io.*; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.TreeSet; /** + * XSD/DTD Model generator tool + * * @author Gregory.Shrago * @author Konstantin Bulenkov + * @since 2002 */ public class MergingFileManager implements FileManager { + @Override public File getOutputFile(File target) { File outFile = target; if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { @@ -46,6 +44,7 @@ public File getOutputFile(File target) { return outFile; } + @Override public File releaseOutputFile(File outFile) { int idx = outFile.getName().indexOf(".tmp."); File target = outFile; @@ -87,7 +86,7 @@ private static String[] mergeLines(String[] curLines, String[] prevLines) { if (prevLines.length == 0) { return curLines; } - ArrayList merged = new ArrayList(); + List merged = new ArrayList<>(); int curIdx = 0, prevIdx = 0; String cur, prev; boolean classScope = false; @@ -159,13 +158,13 @@ else if (compareLines(mergedLines, curLines, 2) == 0) { } } - private static void mergeImports(ArrayList merged, String[] curLines, String[] prevLines, int[] indices) { + private static void mergeImports(List merged, String[] curLines, String[] prevLines, int[] indices) { TreeSet externalClasses = new TreeSet(); for (int i = 0; i < curLines.length; i++) { String line = curLines[i].trim(); if (line.startsWith("import ") && line.endsWith(";")) { indices[0] = i + 1; - final String name = line.substring("import ".length(), line.length() - 1).trim(); + String name = line.substring("import ".length(), line.length() - 1).trim(); if (name.endsWith("*")) { continue; } @@ -176,7 +175,7 @@ private static void mergeImports(ArrayList merged, String[] curLines, St String line = prevLines[i].trim(); if (line.startsWith("import ") && line.endsWith(";")) { indices[1] = i + 1; - final String name = line.substring("import ".length(), line.length() - 1).trim(); + String name = line.substring("import ".length(), line.length() - 1).trim(); if (name.endsWith("*")) { continue; } @@ -202,7 +201,7 @@ private static void mergeImports(ArrayList merged, String[] curLines, St } } - private static int addAllStringsUpTo(ArrayList merged, String[] lines, int startIdx, String upTo) { + private static int addAllStringsUpTo(List merged, String[] lines, int startIdx, String upTo) { String str; do { str = startIdx < lines.length ? lines[startIdx] : upTo; @@ -223,7 +222,7 @@ private static int compareLines(String[] mergedLines, String[] curLines, int sta return 1; } for (int i = start; i < mergedLines.length; i++) { - final int comp = mergedLines[i].compareTo(curLines[i]); + int comp = mergedLines[i].compareTo(curLines[i]); if (comp != 0) { return comp; } @@ -251,7 +250,7 @@ private static void writeFile(File target, String[] mergedLines) { try { out.close(); } - catch (Exception e) { + catch (Exception ignored) { } } } @@ -262,7 +261,7 @@ private static String[] loadFile(File f1) { if (!f1.exists()) { return ArrayUtil.EMPTY_STRING_ARRAY; } - ArrayList list = new ArrayList(); + List list = new ArrayList<>(); BufferedReader in = null; try { in = new BufferedReader(new FileReader(f1)); @@ -279,7 +278,7 @@ private static String[] loadFile(File f1) { try { in.close(); } - catch (IOException e) { + catch (IOException ignored) { } } } diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/NamespaceDesc.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/NamespaceDesc.java index ed10b12f..1879fa0a 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/NamespaceDesc.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/NamespaceDesc.java @@ -13,19 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; import java.util.HashMap; import java.util.Map; /** + * XSD/DTD Model generator tool + * + * @author Gregory Shrago * @author Konstantin Bulenkov */ public class NamespaceDesc { @@ -54,7 +50,6 @@ public NamespaceDesc(String name) { skip = true; } - public NamespaceDesc(String name, NamespaceDesc def) { this.name = name; this.pkgName = def.pkgName; @@ -79,6 +74,7 @@ public NamespaceDesc(String name, NamespaceDesc def) { String[] pkgNames; String enumPkg; + @Override public String toString() { return "NS:" + name + " " + (skip ? "skip" : "") + pkgName; } diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/TypeDesc.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/TypeDesc.java index e3a04c41..f8e3e62b 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/TypeDesc.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/TypeDesc.java @@ -13,19 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; import java.util.Map; import java.util.TreeMap; /** + * XSD/DTD Model generator tool + * + * @author Gregory Shrago * @author Konstantin Bulenkov */ public class TypeDesc { @@ -46,11 +42,12 @@ public TypeDesc(String xsName, String xsNamespace, String name, TypeEnum type) { final String xsName; final String xsNamespace; final String name; - final Map fdMap = new TreeMap(); + final Map fdMap = new TreeMap<>(); boolean duplicates; String documentation; TypeDesc[] supers; + @Override public String toString() { return (type == TypeEnum.ENUM ? "enum" : "type") + ": " + name + ";" + xsName + ";"; } diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/XSDModelLoader.java b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/XSDModelLoader.java index 01738f0e..0d223230 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/XSDModelLoader.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/dom/generator/XSDModelLoader.java @@ -13,13 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * XSD/DTD Model generator tool - * - * By Gregory Shrago - * 2002 - 2006 - */ package org.jetbrains.idea.devkit.dom.generator; import org.apache.xerces.impl.dv.XSSimpleType; @@ -37,6 +30,8 @@ import java.util.*; /** + * XSD/DTD Model generator tool + * * @author Gregory.Shrago * @author Konstantin Bulenkov */ @@ -45,6 +40,7 @@ public class XSDModelLoader implements ModelLoader { private ModelDesc model; + @Override public void loadModel(ModelDesc model, Collection files, XMLEntityResolver resolver) throws Exception { this.model = model; processSchemas(files, resolver); @@ -77,7 +73,7 @@ public static boolean checkComplexType(XSTypeDefinition td) { } public static boolean checkEnumType(XSTypeDefinition td) { - final XSSimpleTypeDefinition st; + XSSimpleTypeDefinition st; if (td.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { XSComplexTypeDefinition ctd = (XSComplexTypeDefinition)td; if (ctd.getContentType() != XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { @@ -108,10 +104,10 @@ private static boolean checkBooleanType(XSTypeDefinition td) { if (td.getTypeCategory() != XSTypeDefinition.SIMPLE_TYPE) { return false; } - final XSSimpleTypeDefinition st = ((XSSimpleTypeDefinition)td); - final XSObjectList facets = st.getFacets(); + XSSimpleTypeDefinition st = ((XSSimpleTypeDefinition)td); + XSObjectList facets = st.getFacets(); for (int i = 0; i < facets.getLength(); i++) { - final XSFacet facet = (XSFacet)facets.item(i); + XSFacet facet = (XSFacet)facets.item(i); if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_LENGTH) { if ("0".equals(facet.getLexicalFacetValue())) { return true; @@ -171,9 +167,9 @@ private XSModel loadSchema(File schemaFile, XMLEntityResolver resolver) throws E public void processSchemas(Collection schemas, XMLEntityResolver resolver) throws Exception { Map nsdMap = model.nsdMap; Map jtMap = model.jtMap; - final NamespaceDesc nsdDef = nsdMap.get(""); - final ArrayList models = new ArrayList(); - final HashMap types = new HashMap(); + NamespaceDesc nsdDef = nsdMap.get(""); + List models = new ArrayList<>(); + Map types = new HashMap<>(); for (File schemaFile : schemas) { String fileName = schemaFile.getPath(); if (schemaFile.isDirectory() || !fileName.endsWith(".xsd")) { @@ -182,12 +178,12 @@ public void processSchemas(Collection schemas, XMLEntityResolver resolver) } Util.log("loading " + fileName + ".."); - final XSModel model = loadSchema(schemaFile, resolver); + XSModel model = loadSchema(schemaFile, resolver); if (model == null) { continue; } - final StringList namespaceList = model.getNamespaces(); + StringList namespaceList = model.getNamespaces(); for (int i = 0; i < namespaceList.getLength(); i++) { String ns = namespaceList.item(i); if (!nsdMap.containsKey(ns)) { @@ -197,17 +193,17 @@ public void processSchemas(Collection schemas, XMLEntityResolver resolver) } } models.add(model); - final XSNamedMap typeDefMap = model.getComponents(XSConstants.TYPE_DEFINITION); + XSNamedMap typeDefMap = model.getComponents(XSConstants.TYPE_DEFINITION); for (int i = 0; i < typeDefMap.getLength(); i++) { XSTypeDefinition o = (XSTypeDefinition)typeDefMap.item(i); NamespaceDesc nsd = nsdMap.get(o.getNamespace()); if (nsd != null && nsd.skip) { continue; } - final String key = o.getName() + "," + o.getNamespace(); + String key = o.getName() + "," + o.getNamespace(); types.put(key, o); } - final XSNamedMap elementDeclMap = model.getComponents(XSConstants.ELEMENT_DECLARATION); + XSNamedMap elementDeclMap = model.getComponents(XSConstants.ELEMENT_DECLARATION); for (int i = 0; i < elementDeclMap.getLength(); i++) { XSElementDeclaration o = (XSElementDeclaration)elementDeclMap.item(i); if (o.getTypeDefinition().getAnonymous() && (o.getTypeDefinition() instanceof XSComplexTypeDefinition)) { @@ -217,14 +213,14 @@ public void processSchemas(Collection schemas, XMLEntityResolver resolver) if (nsd != null && nsd.skip) { continue; } - final String key = ctd.getName() + "," + ctd.getNamespace(); + String key = ctd.getName() + "," + ctd.getNamespace(); types.put(key, ctd); } } } Util.log(types.size() + " elements loaded, processing.."); - ArrayList toProcess = new ArrayList<>(types.values()); - ArrayList toAdd = new ArrayList<>(); + List toProcess = new ArrayList<>(types.values()); + List toAdd = new ArrayList<>(); for (ListIterator it = toProcess.listIterator(); it.hasNext(); ) { XSTypeDefinition td = it.next(); Util.log("processing " + td.getName() + "," + td.getNamespace() + ".."); @@ -236,7 +232,7 @@ else if (checkEnumType(td)) { } if (toAdd.size() != 0) { for (XSComplexTypeDefinition o : toAdd) { - final String key = o.getName() + "," + o.getNamespace(); + String key = o.getName() + "," + o.getNamespace(); if (!types.containsKey(key)) { Util.log(" adding " + o.getName() + "," + o.getNamespace()); types.put(key, o); @@ -253,23 +249,23 @@ else if (checkEnumType(td)) { } private XSComplexTypeDefinition makeTypeFromAnonymous(XSObject o) { - final XSComplexTypeDecl ctd = new XSComplexTypeDecl(); - if (o instanceof XSElementDeclaration && ((XSElementDeclaration)o).getTypeDefinition() instanceof XSComplexTypeDecl) { - final XSComplexTypeDecl ctd1 = (XSComplexTypeDecl)((XSElementDeclaration)o).getTypeDefinition(); - final XSObjectListImpl annotations = - ctd1.getAnnotations() instanceof XSObjectListImpl ? (XSObjectListImpl)ctd1.getAnnotations() : new XSObjectListImpl(); - ctd.setValues(o.getName(), ctd1.getNamespace(), ctd1.getBaseType(), ctd1.getDerivationMethod(), ctd1.getFinal(), + XSComplexTypeDecl ctd = new XSComplexTypeDecl(); + if (o instanceof XSElementDeclaration elemDecl && elemDecl.getTypeDefinition() instanceof XSComplexTypeDecl) { + XSComplexTypeDecl ctd1 = (XSComplexTypeDecl) elemDecl.getTypeDefinition(); + XSObjectListImpl annotations = + ctd1.getAnnotations() instanceof XSObjectListImpl objectList ? objectList : new XSObjectListImpl(); + ctd.setValues(elemDecl.getName(), ctd1.getNamespace(), ctd1.getBaseType(), ctd1.getDerivationMethod(), ctd1.getFinal(), ctd1.getProhibitedSubstitutions(), ctd1.getContentType(), ctd1.getAbstract(), ctd1.getAttrGrp(), (XSSimpleType)ctd1.getSimpleType(), (XSParticleDecl)ctd1.getParticle(), annotations ); - ctd.setName(o.getName() + Util.ANONYMOUS_ELEM_TYPE_SUFFIX); + ctd.setName(elemDecl.getName() + Util.ANONYMOUS_ELEM_TYPE_SUFFIX); } - else if (o instanceof XSAttributeDeclaration) { - final XSSimpleTypeDecl ctd1 = (XSSimpleTypeDecl)((XSAttributeDeclaration)o).getTypeDefinition(); - final XSObjectListImpl annotations = + else if (o instanceof XSAttributeDeclaration attrDecl) { + XSSimpleTypeDecl ctd1 = (XSSimpleTypeDecl) attrDecl.getTypeDefinition(); + XSObjectListImpl annotations = ctd1.getAnnotations() instanceof XSObjectListImpl xsObjectList ? xsObjectList : new XSObjectListImpl(); ctd.setValues( - o.getName(), + attrDecl.getName(), ctd1.getNamespace(), ctd1.getBaseType(), XSConstants.DERIVATION_RESTRICTION, @@ -282,7 +278,7 @@ else if (o instanceof XSAttributeDeclaration) { null, annotations ); - ctd.setName(o.getName() + Util.ANONYMOUS_ATTR_TYPE_SUFFIX); + ctd.setName(attrDecl.getName() + Util.ANONYMOUS_ATTR_TYPE_SUFFIX); } model.qname2FileMap @@ -295,16 +291,16 @@ public void processEnumType(XSTypeDefinition def, Map jtMap, M if (!nsdMap.containsKey(def.getNamespace())) { Util.log("Namespace desc not found for: " + def); } - final String typeName = toJavaTypeName(def, nsdMap); - final TypeDesc td = new TypeDesc(def.getName(), def.getNamespace(), typeName, TypeDesc.TypeEnum.ENUM); - final XSComplexTypeDefinition ct = complexType ? (XSComplexTypeDefinition)def : null; - final XSSimpleTypeDefinition st = (XSSimpleTypeDefinition)(complexType ? ((XSComplexTypeDefinition)def).getSimpleType() : def); + String typeName = toJavaTypeName(def, nsdMap); + TypeDesc td = new TypeDesc(def.getName(), def.getNamespace(), typeName, TypeDesc.TypeEnum.ENUM); + XSComplexTypeDefinition ct = complexType ? (XSComplexTypeDefinition)def : null; + XSSimpleTypeDefinition st = (XSSimpleTypeDefinition)(complexType ? ((XSComplexTypeDefinition)def).getSimpleType() : def); for (int i = 0; i < st.getLexicalEnumeration().getLength(); i++) { - final String s = st.getLexicalEnumeration().item(i); + String s = st.getLexicalEnumeration().item(i); td.fdMap.put(s, new FieldDesc(Util.computeEnumConstantName(s, td.name), s)); } - final XSObjectList anns = complexType ? ct.getAnnotations() : st.getAnnotations(); + XSObjectList anns = complexType ? ct.getAnnotations() : st.getAnnotations(); td.documentation = parseAnnotationString( "Enumeration " + def.getNamespace() + ":" + def.getName() + " documentation", @@ -320,7 +316,7 @@ public void processType( List models, Map jtMap, Map nsdMap, - ArrayList toAdd + List toAdd ) throws Exception { if (!nsdMap.containsKey(def.getNamespace())) { Util.log("Namespace desc not found for: " + def); @@ -408,7 +404,7 @@ public void processType( fd1.simpleTypesString = getSimpleTypesString(ad.getTypeDefinition()); } } - LinkedList plist = new LinkedList<>(); + List plist = new LinkedList<>(); if (def.getParticle() != null) { plist.add(new PEntry(def.getParticle(), false)); } @@ -422,7 +418,7 @@ public void processType( } private static String getSimpleTypesString(XSTypeDefinition et) { - StringBuffer typesHierarchy = new StringBuffer(); + StringBuilder typesHierarchy = new StringBuilder(); while (et != null && !"anySimpleType".equals(et.getName()) && !"anyType".equals(et.getName()) && et.getNamespace() != null) { typesHierarchy.append(et.getNamespace().substring(et.getNamespace().lastIndexOf("/") + 1)).append(":").append(et.getName()) .append(";"); @@ -456,7 +452,7 @@ private TypeDesc processGroup( XSNamedMap map = xsModel.getComponents(XSConstants.MODEL_GROUP_DEFINITION); for (int i = 0; i < map.getLength(); i++) { XSModelGroupDefinition mg = (XSModelGroupDefinition)map.item(i); - final XSModelGroup xsModelGroup = mg.getModelGroup(); + XSModelGroup xsModelGroup = mg.getModelGroup(); if (xsModelGroup == modelGroup || xsModelGroup.toString().equals(modelGroup.toString())) { def = mg; break; @@ -470,7 +466,7 @@ private TypeDesc processGroup( Util.log("Namespace desc not found for: " + def); } String typeName = toJavaTypeName(def, nsdMap); - final String typeQName = model.toJavaQualifiedTypeName(def, nsdMap, false); + String typeQName = model.toJavaQualifiedTypeName(def, nsdMap, false); TypeDesc td = jtMap.get(typeQName); if (td != null) { if (td.type == TypeDesc.TypeEnum.GROUP_INTERFACE) { @@ -491,7 +487,7 @@ private TypeDesc processGroup( ann == null ? null : ann.getAnnotationString() ); td.type = TypeDesc.TypeEnum.GROUP_INTERFACE; - LinkedList plist = new LinkedList<>(); + List plist = new LinkedList<>(); for (int i = 0; i < def.getModelGroup().getParticles().getLength(); i++) { XSParticle p = (XSParticle)def.getModelGroup().getParticles().item(i); plist.add(new PEntry(p, false)); @@ -503,26 +499,25 @@ private TypeDesc processGroup( private void processParticles( XSObject def, - LinkedList plist, + List plist, Map nsdMap, Map jtMap, TypeDesc td, List models, - ArrayList toAdd, + List toAdd, TypeDesc baseClass ) { - final boolean globalMerge = jtMap.containsKey(model.toJavaQualifiedTypeName(def, nsdMap, td.type == TypeDesc.TypeEnum.ENUM)); - final HashMap globalChoice = new HashMap<>(); - final ArrayList choiceList = new ArrayList<>(); - final ArrayList supers = new ArrayList<>(); + boolean globalMerge = jtMap.containsKey(model.toJavaQualifiedTypeName(def, nsdMap, td.type == TypeDesc.TypeEnum.ENUM)); + Map globalChoice = new HashMap<>(); + List choiceList = new ArrayList<>(); + List supers = new ArrayList<>(); if (baseClass != null) { supers.add(baseClass); } while (!plist.isEmpty()) { - final PEntry pentry = plist.removeFirst(); - final XSParticle p = pentry.p; - if (p.getTerm() instanceof XSElementDecl) { - final XSElementDecl el = (XSElementDecl)p.getTerm(); + PEntry pentry = plist.removeFirst(); + XSParticle p = pentry.p; + if (p.getTerm() instanceof XSElementDecl el) { if (el.getConstraintType() == XSConstants.VC_FIXED) { continue; } @@ -533,7 +528,12 @@ private void processParticles( "Element " + el.getNamespace() + ":" + el.getName() + " documentation", ann != null ? ann.getAnnotationString() : null ); - final FieldDesc fd1 = new FieldDesc(FieldDesc.STR, Util.toJavaFieldName(el.getName()), et.getName(), null, "null", + FieldDesc fd1 = new FieldDesc( + FieldDesc.STR, + Util.toJavaFieldName(el.getName()), + et.getName(), + null, + "null", !pentry.many && p.getMinOccurs() > 0 ); fd1.documentation = documentation; @@ -680,7 +680,7 @@ else if (p.getTerm() instanceof XSModelGroup groupDef) { addToGlobalChoice = true; } for (int i = 0; i < l.getLength(); i++) { - final PEntry o = new PEntry((XSParticle)l.item(i), many); + PEntry o = new PEntry((XSParticle)l.item(i), many); plist.add(o); if (addToGlobalChoice && !globalChoice.containsKey(o.p)) { globalChoice.put(o.p, null); @@ -694,27 +694,27 @@ else if (p.getTerm() instanceof XSModelGroup groupDef) { fd.idx = i; } for (XSObjectList l : choiceList) { - final ArrayList clist = new ArrayList<>(); - final LinkedList elist = new LinkedList<>(); + List cList = new ArrayList<>(); + List eList = new LinkedList<>(); for (i = 0; i < l.getLength(); i++) { - elist.add((XSParticle)l.item(i)); + eList.add((XSParticle)l.item(i)); } - while (!elist.isEmpty()) { - final XSParticle p = elist.removeFirst(); + while (!eList.isEmpty()) { + XSParticle p = eList.removeFirst(); if (p.getTerm() instanceof XSModelGroup groupDef) { XSObjectList l2 = groupDef.getParticles(); for (int i2 = 0; i2 < l2.getLength(); i2++) { - elist.addFirst((XSParticle)l2.item(i2)); + eList.addFirst((XSParticle)l2.item(i2)); } } else if (p.getTerm() instanceof XSElementDecl) { - clist.add(p); + cList.add(p); } } boolean choiceOpt = true; - FieldDesc[] choice = new FieldDesc[clist.size()]; + FieldDesc[] choice = new FieldDesc[cList.size()]; for (i = 0; i < choice.length; i++) { - XSParticle p = clist.get(i); + XSParticle p = cList.get(i); XSElementDecl el = (XSElementDecl)p.getTerm(); String s = Util.toJavaFieldName(el.getName()); if (p.getMaxOccursUnbounded() || p.getMaxOccurs() > 1) { @@ -724,7 +724,7 @@ else if (p.getTerm() instanceof XSElementDecl) { if (fd == null) { fd = td.fdMap.get(Util.pluralize(s)); if (fd == null) { - Util.logerr("uknown choice element: " + s); + Util.logerr("unknown choice element: " + s); } } diff --git a/plugin/src/main/java/org/jetbrains/idea/devkit/util/ChooseModulesDialog.java b/plugin/src/main/java/org/jetbrains/idea/devkit/util/ChooseModulesDialog.java index dfa81238..aaecdb0a 100644 --- a/plugin/src/main/java/org/jetbrains/idea/devkit/util/ChooseModulesDialog.java +++ b/plugin/src/main/java/org/jetbrains/idea/devkit/util/ChooseModulesDialog.java @@ -15,11 +15,13 @@ */ package org.jetbrains.idea.devkit.util; -import consulo.application.AllIcons; +import consulo.annotation.access.RequiredReadAction; import consulo.devkit.localize.DevKitLocalize; import consulo.devkit.util.PluginModuleUtil; import consulo.module.Module; +import consulo.platform.base.icon.PlatformIconGroup; import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.SimpleTextAttributes; import consulo.ui.ex.awt.*; import consulo.ui.ex.awt.internal.laf.MultiLineLabelUI; @@ -52,39 +54,45 @@ public class ChooseModulesDialog extends DialogWrapper { private final List myCandidateModules; private final boolean[] myStates; - public ChooseModulesDialog(final Project project, List candidateModules, @NonNls String title) { + public ChooseModulesDialog(Project project, List candidateModules, @NonNls String title) { this(project, candidateModules, title, DevKitLocalize.selectPluginModulesToPatch().get()); } - public ChooseModulesDialog(final Project project, List candidateModules, @NonNls String title, final String message) { + public ChooseModulesDialog(Project project, List candidateModules, @NonNls String title, String message) { super(project, false); setTitle(title); myCandidateModules = candidateModules; - myIcon = Messages.getQuestionIcon(); + myIcon = UIUtil.getQuestionIcon(); myMessage = message; myView = new JBTable(new AbstractTableModel() { + @Override public int getRowCount() { return myCandidateModules.size(); } + @Override public int getColumnCount() { return 2; } + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return columnIndex == 0; } + @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { myStates[rowIndex] = (Boolean)aValue; fireTableCellUpdated(rowIndex, columnIndex); } + @Override public Class getColumnClass(int columnIndex) { return columnIndex == 0 ? Boolean.class : Module.class; } + @Override public Object getValueAt(int rowIndex, int columnIndex) { return columnIndex == 0 ? myStates[rowIndex] : myCandidateModules.get(rowIndex); } @@ -96,6 +104,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { myView.getColumnModel().getColumn(0).setMaxWidth(new JCheckBox().getPreferredSize().width); myView.getModel().addTableModelListener(e -> getOKAction().setEnabled(getSelectedModules().size() > 0)); myView.addKeyListener(new KeyAdapter() { + @Override public void keyTyped(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyChar() == '\n') { doOKAction(); @@ -110,6 +119,7 @@ public void keyTyped(KeyEvent e) { init(); } + @Override protected JComponent createNorthPanel() { JPanel panel = new JPanel(new BorderLayout(15, 10)); if (myIcon != null) { @@ -129,25 +139,27 @@ protected JComponent createNorthPanel() { } panel.add(messagePanel, BorderLayout.CENTER); - final JScrollPane jScrollPane = ScrollPaneFactory.createScrollPane(); + JScrollPane jScrollPane = ScrollPaneFactory.createScrollPane(); jScrollPane.setViewportView(myView); jScrollPane.setPreferredSize(new Dimension(300, 80)); panel.add(jScrollPane, BorderLayout.SOUTH); return panel; } + @Override + @RequiredUIAccess public JComponent getPreferredFocusedComponent() { return myView; } - + @Override protected JComponent createCenterPanel() { return null; } public List getSelectedModules() { - final ArrayList list = new ArrayList<>(myCandidateModules); - final Iterator modules = list.iterator(); + List list = new ArrayList<>(myCandidateModules); + Iterator modules = list.iterator(); for (boolean b : myStates) { modules.next(); if (!b) { @@ -166,17 +178,19 @@ public MyTableCellRenderer(Project project) { myProject = project; myList = new JBList(); myCellRenderer = new ColoredListCellRenderer() { + @Override + @RequiredReadAction protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { - final Module module = ((Module)value); - setIcon(AllIcons.Nodes.Module); + Module module = ((Module)value); + setIcon(PlatformIconGroup.nodesModule()); append(module.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); - final XmlFile pluginXml = PluginModuleUtil.getPluginXml(module); + XmlFile pluginXml = PluginModuleUtil.getPluginXml(module); assert pluginXml != null; - final VirtualFile virtualFile = pluginXml.getVirtualFile(); + VirtualFile virtualFile = pluginXml.getVirtualFile(); assert virtualFile != null; - final VirtualFile projectPath = myProject.getBaseDir(); + VirtualFile projectPath = myProject.getBaseDir(); assert projectPath != null; if (VirtualFileUtil.isAncestor(projectPath, virtualFile, false)) { append(" (" + VirtualFileUtil.getRelativePath(virtualFile, projectPath, File.separatorChar) + ")", @@ -189,6 +203,7 @@ protected void customizeCellRenderer(JList list, Object value, int index, boolea }; } + @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return myCellRenderer.getListCellRendererComponent(myList, value, row, isSelected, hasFocus); }