Incorporate Review

This commit is contained in:
JohnHake 2020-02-10 09:15:27 -08:00
parent 65dd82041f
commit 605d747a2e
27 changed files with 69 additions and 85 deletions

2
.idea/modules.xml generated
View File

@ -2,8 +2,6 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/code_samples/comparing_references_inspection/comparing_references_inspection.iml" filepath="$PROJECT_DIR$/code_samples/comparing_references_inspection/comparing_references_inspection.iml" group="code_samples" />
<module fileurl="file://$PROJECT_DIR$/code_samples/conditional_operator_intention/conditional_operator_intention.iml" filepath="$PROJECT_DIR$/code_samples/conditional_operator_intention/conditional_operator_intention.iml" group="code_samples" />
<module fileurl="file://$PROJECT_DIR$/.idea/intellij-sdk-docs.iml" filepath="$PROJECT_DIR$/.idea/intellij-sdk-docs.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/intellij-sdk-docs.iml" filepath="$PROJECT_DIR$/.idea/intellij-sdk-docs.iml" />
<module fileurl="file://$PROJECT_DIR$/code_samples/live_templates/live_templates.iml" filepath="$PROJECT_DIR$/code_samples/live_templates/live_templates.iml" group="code_samples" /> <module fileurl="file://$PROJECT_DIR$/code_samples/live_templates/live_templates.iml" filepath="$PROJECT_DIR$/code_samples/live_templates/live_templates.iml" group="code_samples" />
<module fileurl="file://$PROJECT_DIR$/code_samples/max_opened_projects/max_opened_projects.iml" filepath="$PROJECT_DIR$/code_samples/max_opened_projects/max_opened_projects.iml" group="code_samples" /> <module fileurl="file://$PROJECT_DIR$/code_samples/max_opened_projects/max_opened_projects.iml" filepath="$PROJECT_DIR$/code_samples/max_opened_projects/max_opened_projects.iml" group="code_samples" />

View File

@ -1,6 +1,6 @@
plugins { plugins {
id 'java' id 'java'
id 'org.jetbrains.intellij' version '0.4.15' id 'org.jetbrains.intellij' version '0.4.16'
} }
group 'com.intellij.sdk' group 'com.intellij.sdk'
@ -13,6 +13,7 @@ repositories {
} }
test { test {
// This path value is machine-specific placeholder text.
// Set idea.home.path to the absolute path to the intellij-community source // Set idea.home.path to the absolute path to the intellij-community source
// on your local machine. // on your local machine.
systemProperty "idea.home.path", "/Users/jhake/Documents/source/comm" systemProperty "idea.home.path", "/Users/jhake/Documents/source/comm"
@ -28,7 +29,6 @@ dependencies {
// See https://github.com/JetBrains/gradle-intellij-plugin/ // See https://github.com/JetBrains/gradle-intellij-plugin/
intellij { intellij {
version '2019.3.2' version '2019.3.2'
type = 'IC'
plugins 'java' plugins 'java'
updateSinceUntilBuild = false updateSinceUntilBuild = false
} }

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -15,45 +15,45 @@ public class SimpleAnnotator implements Annotator {
// Define strings for the Simple language prefix - used for annotations, line markers, etc. // Define strings for the Simple language prefix - used for annotations, line markers, etc.
public static final String SIMPLE_PREFIX_STR = "simple"; public static final String SIMPLE_PREFIX_STR = "simple";
public static final String SIMPLE_SEPARATOR_STR = ":"; public static final String SIMPLE_SEPARATOR_STR = ":";
@Override @Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
// Ensure the Psi element is an expression // Ensure the Psi Element is an expression
if ( !( element instanceof PsiLiteralExpression ) ) return; if (!(element instanceof PsiLiteralExpression)) return;
// Ensure the Psi element contains a string that starts with the key and separator // Ensure the Psi element contains a string that starts with the key and separator
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
if ( ( value == null ) || !value.startsWith( SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR ) ) return; if ((value == null) || !value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR)) return;
// Define the text ranges (start is inclusive, end is exclusive) // Define the text ranges (start is inclusive, end is exclusive)
// "simple:key" // "simple:key"
// 01234567890 // 01234567890
TextRange prefixRange = TextRange.from( element.getTextRange().getStartOffset(), SIMPLE_PREFIX_STR.length() + 1 ); TextRange prefixRange = TextRange.from(element.getTextRange().getStartOffset(), SIMPLE_PREFIX_STR.length() + 1);
TextRange separatorRange = TextRange.from( prefixRange.getEndOffset(), SIMPLE_SEPARATOR_STR.length() ); TextRange separatorRange = TextRange.from(prefixRange.getEndOffset(), SIMPLE_SEPARATOR_STR.length());
TextRange keyRange = new TextRange( separatorRange.getEndOffset(), element.getTextRange().getEndOffset() - 1 ); TextRange keyRange = new TextRange(separatorRange.getEndOffset(), element.getTextRange().getEndOffset() - 1);
// Get the list of properties from the Project // Get the list of properties from the Project
String possibleProperties = value.substring( SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length() ); String possibleProperties = value.substring(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length());
Project project = element.getProject(); Project project = element.getProject();
List< SimpleProperty > properties = SimpleUtil.findProperties( project, possibleProperties ); List<SimpleProperty> properties = SimpleUtil.findProperties(project, possibleProperties);
// Set the annotations using the text ranges. // Set the annotations using the text ranges.
Annotation keyAnnotation = holder.createInfoAnnotation( prefixRange, null ); Annotation keyAnnotation = holder.createInfoAnnotation(prefixRange, null);
keyAnnotation.setTextAttributes( DefaultLanguageHighlighterColors.KEYWORD ); keyAnnotation.setTextAttributes(DefaultLanguageHighlighterColors.KEYWORD);
Annotation separatorAnnotation = holder.createInfoAnnotation( separatorRange, null ); Annotation separatorAnnotation = holder.createInfoAnnotation(separatorRange, null);
separatorAnnotation.setTextAttributes( SimpleSyntaxHighlighter.SEPARATOR ); separatorAnnotation.setTextAttributes(SimpleSyntaxHighlighter.SEPARATOR);
if ( properties.isEmpty() ) { if (properties.isEmpty()) {
// No well-formed property found following the key-separator // No well-formed property found following the key-separator
Annotation badProperty = holder.createErrorAnnotation( keyRange, "Unresolved property" ); Annotation badProperty = holder.createErrorAnnotation(keyRange, "Unresolved property");
badProperty.setTextAttributes( SimpleSyntaxHighlighter.BAD_CHARACTER ); badProperty.setTextAttributes(SimpleSyntaxHighlighter.BAD_CHARACTER);
// ** Tutorial step 18.3 - Add a quick fix for the string containing possible properties // ** Tutorial step 18.3 - Add a quick fix for the string containing possible properties
badProperty.registerFix(new SimpleCreatePropertyQuickFix(possibleProperties)); badProperty.registerFix(new SimpleCreatePropertyQuickFix(possibleProperties));
} else { } else {
// Found at least one property // Found at least one property
Annotation annotation = holder.createInfoAnnotation( keyRange, null ); Annotation annotation = holder.createInfoAnnotation(keyRange, null);
annotation.setTextAttributes( SimpleSyntaxHighlighter.VALUE ); annotation.setTextAttributes(SimpleSyntaxHighlighter.VALUE);
} }
} }
} }

View File

@ -11,15 +11,12 @@ import org.jetbrains.annotations.NotNull;
public class SimpleCompletionContributor extends CompletionContributor { public class SimpleCompletionContributor extends CompletionContributor {
public SimpleCompletionContributor() { public SimpleCompletionContributor() {
// Register the completion providers
extend( CompletionType.BASIC, extend( CompletionType.BASIC,
PlatformPatterns.psiElement(SimpleTypes.VALUE).withLanguage(SimpleLanguage.INSTANCE), PlatformPatterns.psiElement(SimpleTypes.VALUE).withLanguage(SimpleLanguage.INSTANCE),
new CompletionProvider<CompletionParameters>() { new CompletionProvider<CompletionParameters>() {
// Define candidate completions
public void addCompletions(@NotNull CompletionParameters parameters, public void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context, ProcessingContext context,
@NotNull CompletionResultSet resultSet) { @NotNull CompletionResultSet resultSet) {
// Create a completion independent of context for Simple language
resultSet.addElement(LookupElementBuilder.create("Hello")); resultSet.addElement(LookupElementBuilder.create("Hello"));
} }
} }

View File

@ -27,13 +27,13 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware
// Get a collection of the literal expressions in the document below root // Get a collection of the literal expressions in the document below root
Collection< PsiLiteralExpression > literalExpressions = Collection< PsiLiteralExpression > literalExpressions =
PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class); PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class);
// Evaluate the collection, using only Simple language literalExpressions // Evaluate the collection
for ( final PsiLiteralExpression literalExpression : literalExpressions ) { for ( final PsiLiteralExpression literalExpression : literalExpressions ) {
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
if ( value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR) ) { if ( value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR) ) {
Project project = literalExpression.getProject(); Project project = literalExpression.getProject();
String key = value.substring(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length()); String key = value.substring(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length());
// Get a list of properties for the project // Get a list of all properties for a given key in the project
final List< SimpleProperty > properties = SimpleUtil.findProperties(project, key); final List< SimpleProperty > properties = SimpleUtil.findProperties(project, key);
if ( properties.size() == 1 ) { if ( properties.size() == 1 ) {
// Add a folding descriptor for the literal expression at this node. // Add a folding descriptor for the literal expression at this node.
@ -52,7 +52,6 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware
* @param node Node corresponding to PsiLiteralExpression containing a string in the format * @param node Node corresponding to PsiLiteralExpression containing a string in the format
* SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR + Key, where Key is * SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR + Key, where Key is
* defined by the Simple language file. * defined by the Simple language file.
* @return String corresponding to the "website" key.
*/ */
@Nullable @Nullable
@Override @Override

View File

@ -13,8 +13,3 @@ public class SimpleRefactoringSupportProvider extends RefactoringSupportProvider
return (elementToRename instanceof SimpleProperty); return (elementToRename instanceof SimpleProperty);
} }
} }
/*
2020-01-10 21:59:36,392 [ 74521] WARN - name.RenamePsiElementProcessor - org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinTypeParameterProcessor overrides deprecated findReferences(..).
Override findReferences(PsiElement, SearchScope, boolean) instead.
*/

View File

@ -13,22 +13,22 @@ import static com.intellij.sdk.language.SimpleAnnotator.*;
public class SimpleReferenceContributor extends PsiReferenceContributor { public class SimpleReferenceContributor extends PsiReferenceContributor {
@Override @Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider( PlatformPatterns.psiElement( PsiLiteralExpression.class ), registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
new PsiReferenceProvider() { new PsiReferenceProvider() {
@NotNull @NotNull
@Override @Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) { @NotNull ProcessingContext context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
String value = literalExpression.getValue() instanceof String ? String value = literalExpression.getValue() instanceof String ?
(String) literalExpression.getValue() : null; (String) literalExpression.getValue() : null;
if ( ( value != null && value.startsWith( SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR ) ) ) { if ((value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR))) {
TextRange property = new TextRange( SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length() + 1, TextRange property = new TextRange(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length() + 1,
value.length() + 1 ); value.length() + 1);
return new PsiReference[]{ new SimpleReference( element, property ) }; return new PsiReference[]{new SimpleReference(element, property)};
} }
return PsiReference.EMPTY_ARRAY; return PsiReference.EMPTY_ARRAY;
} }
} ); });
} }
} }

View File

@ -18,57 +18,56 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SimpleStructureViewElement implements StructureViewTreeElement, SortableTreeElement { public class SimpleStructureViewElement implements StructureViewTreeElement, SortableTreeElement {
private NavigatablePsiElement element; private NavigatablePsiElement myElement;
public SimpleStructureViewElement(NavigatablePsiElement element) { public SimpleStructureViewElement(NavigatablePsiElement element) {
this.element = element; this.myElement = element;
} }
@Override @Override
public Object getValue() { public Object getValue() {
return element; return myElement;
} }
@Override @Override
public void navigate(boolean requestFocus) { public void navigate(boolean requestFocus) {
element.navigate(requestFocus); myElement.navigate(requestFocus);
} }
@Override @Override
public boolean canNavigate() { public boolean canNavigate() {
return element.canNavigate(); return myElement.canNavigate();
} }
@Override @Override
public boolean canNavigateToSource() { public boolean canNavigateToSource() {
return element.canNavigateToSource(); return myElement.canNavigateToSource();
} }
@NotNull @NotNull
@Override @Override
public String getAlphaSortKey() { public String getAlphaSortKey() {
String name = element.getName(); String name = myElement.getName();
return name != null ? name : ""; return name != null ? name : "";
} }
@NotNull @NotNull
@Override @Override
public ItemPresentation getPresentation() { public ItemPresentation getPresentation() {
ItemPresentation presentation = element.getPresentation(); ItemPresentation presentation = myElement.getPresentation();
return presentation != null ? presentation : new PresentationData(); return presentation != null ? presentation : new PresentationData();
} }
@Override @Override
public TreeElement[] getChildren() { public TreeElement[] getChildren() {
if (element instanceof SimpleFile) { if (myElement instanceof SimpleFile) {
SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(element, SimpleProperty.class); SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(myElement, SimpleProperty.class);
List<TreeElement> treeElements = new ArrayList<TreeElement>(properties.length); List<TreeElement> treeElements = new ArrayList<TreeElement>(properties.length);
for (SimpleProperty property : properties) { for (SimpleProperty property : properties) {
treeElements.add(new SimpleStructureViewElement((SimplePropertyImpl) property)); treeElements.add(new SimpleStructureViewElement((SimplePropertyImpl) property));
} }
return treeElements.toArray(new TreeElement[treeElements.size()]); return treeElements.toArray(new TreeElement[treeElements.size()]);
} else {
return EMPTY_ARRAY;
} }
return EMPTY_ARRAY;
} }
} }

View File

@ -12,7 +12,7 @@ import java.util.*;
public class SimpleUtil { public class SimpleUtil {
// Searches the entire project for Simple language files with instances of the Simple property // Searches the entire project for Simple language files with instances of the Simple property with the given key
public static List<SimpleProperty> findProperties(Project project, String key) { public static List<SimpleProperty> findProperties(Project project, String key) {
List<SimpleProperty> result = null; List<SimpleProperty> result = null;
Collection<VirtualFile> virtualFiles = Collection<VirtualFile> virtualFiles =

View File

@ -23,9 +23,4 @@ public class SimpleFile extends PsiFileBase {
public String toString() { public String toString() {
return "Simple File"; return "Simple File";
} }
@Override
public Icon getIcon(int flags) {
return super.getIcon(flags);
}
} }

View File

@ -12,7 +12,7 @@
<version>2.0.0</version> <version>2.0.0</version>
<!-- Compatible with the following versions of IntelliJ Platform <!-- Compatible with the following versions of IntelliJ Platform
At least 2019.2 is required. Otherwise, a FileTypeFactor must be registered as an extension. At least 2019.2 is required. Otherwise, FileTypeFactor must be registered as an extension.
See the extensions section below. --> See the extensions section below. -->
<idea-version since-build="192.2"/> <idea-version since-build="192.2"/>
@ -43,6 +43,7 @@
<fileType name="Simple file" implementationClass="com.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE" <fileType name="Simple file" implementationClass="com.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE"
language="Simple" extensions="simple"/> language="Simple" extensions="simple"/>
<!-- Only required for versions of the IntelliJ Platform prior to v2019.2. <!-- Only required for versions of the IntelliJ Platform prior to v2019.2.
Use fileTypeFactory extension point INSTEAD of fileType.
<fileTypeFactory implementation="com.intellij.sdk.language.SimpleFileTypeFactory"/> <fileTypeFactory implementation="com.intellij.sdk.language.SimpleFileTypeFactory"/>
--> -->
<lang.parserDefinition language="Simple" implementationClass="com.intellij.sdk.language.SimpleParserDefinition"/> <lang.parserDefinition language="Simple" implementationClass="com.intellij.sdk.language.SimpleParserDefinition"/>

View File

@ -23,7 +23,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
*/ */
@Override @Override
protected String getTestDataPath() { protected String getTestDataPath() {
return "src/test/testData"; return "src/test/resources";
} }
public void testCompletion() { public void testCompletion() {

View File

@ -17,7 +17,7 @@ public class SimpleParsingTest extends ParsingTestCase {
*/ */
@Override @Override
protected String getTestDataPath() { protected String getTestDataPath() {
return "src/test/testData"; return "src/test/resources";
} }
@Override @Override