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">
<component name="ProjectModuleManager">
<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$/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" />

View File

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

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists

View File

@ -18,41 +18,41 @@ public class SimpleAnnotator implements Annotator {
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
// Ensure the Psi element is an expression
if ( !( element instanceof PsiLiteralExpression ) ) return;
// Ensure the Psi Element is an expression
if (!(element instanceof PsiLiteralExpression)) return;
// Ensure the Psi element contains a string that starts with the key and separator
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
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)
// "simple:key"
// 01234567890
TextRange prefixRange = TextRange.from( element.getTextRange().getStartOffset(), SIMPLE_PREFIX_STR.length() + 1 );
TextRange separatorRange = TextRange.from( prefixRange.getEndOffset(), SIMPLE_SEPARATOR_STR.length() );
TextRange keyRange = new TextRange( separatorRange.getEndOffset(), element.getTextRange().getEndOffset() - 1 );
TextRange prefixRange = TextRange.from(element.getTextRange().getStartOffset(), SIMPLE_PREFIX_STR.length() + 1);
TextRange separatorRange = TextRange.from(prefixRange.getEndOffset(), SIMPLE_SEPARATOR_STR.length());
TextRange keyRange = new TextRange(separatorRange.getEndOffset(), element.getTextRange().getEndOffset() - 1);
// 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();
List< SimpleProperty > properties = SimpleUtil.findProperties( project, possibleProperties );
List<SimpleProperty> properties = SimpleUtil.findProperties(project, possibleProperties);
// Set the annotations using the text ranges.
Annotation keyAnnotation = holder.createInfoAnnotation( prefixRange, null );
keyAnnotation.setTextAttributes( DefaultLanguageHighlighterColors.KEYWORD );
Annotation separatorAnnotation = holder.createInfoAnnotation( separatorRange, null );
separatorAnnotation.setTextAttributes( SimpleSyntaxHighlighter.SEPARATOR );
if ( properties.isEmpty() ) {
Annotation keyAnnotation = holder.createInfoAnnotation(prefixRange, null);
keyAnnotation.setTextAttributes(DefaultLanguageHighlighterColors.KEYWORD);
Annotation separatorAnnotation = holder.createInfoAnnotation(separatorRange, null);
separatorAnnotation.setTextAttributes(SimpleSyntaxHighlighter.SEPARATOR);
if (properties.isEmpty()) {
// No well-formed property found following the key-separator
Annotation badProperty = holder.createErrorAnnotation( keyRange, "Unresolved property" );
badProperty.setTextAttributes( SimpleSyntaxHighlighter.BAD_CHARACTER );
Annotation badProperty = holder.createErrorAnnotation(keyRange, "Unresolved property");
badProperty.setTextAttributes(SimpleSyntaxHighlighter.BAD_CHARACTER);
// ** Tutorial step 18.3 - Add a quick fix for the string containing possible properties
badProperty.registerFix(new SimpleCreatePropertyQuickFix(possibleProperties));
} else {
// Found at least one property
Annotation annotation = holder.createInfoAnnotation( keyRange, null );
annotation.setTextAttributes( SimpleSyntaxHighlighter.VALUE );
Annotation annotation = holder.createInfoAnnotation(keyRange, null);
annotation.setTextAttributes(SimpleSyntaxHighlighter.VALUE);
}
}

View File

@ -11,15 +11,12 @@ import org.jetbrains.annotations.NotNull;
public class SimpleCompletionContributor extends CompletionContributor {
public SimpleCompletionContributor() {
// Register the completion providers
extend( CompletionType.BASIC,
PlatformPatterns.psiElement(SimpleTypes.VALUE).withLanguage(SimpleLanguage.INSTANCE),
new CompletionProvider<CompletionParameters>() {
// Define candidate completions
public void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet resultSet) {
// Create a completion independent of context for Simple language
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
Collection< PsiLiteralExpression > literalExpressions =
PsiTreeUtil.findChildrenOfType(root, PsiLiteralExpression.class);
// Evaluate the collection, using only Simple language literalExpressions
// Evaluate the collection
for ( final PsiLiteralExpression literalExpression : literalExpressions ) {
String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null;
if ( value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR) ) {
Project project = literalExpression.getProject();
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);
if ( properties.size() == 1 ) {
// 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
* SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR + Key, where Key is
* defined by the Simple language file.
* @return String corresponding to the "website" key.
*/
@Nullable
@Override

View File

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

View File

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

View File

@ -12,7 +12,7 @@ import java.util.*;
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) {
List<SimpleProperty> result = null;
Collection<VirtualFile> virtualFiles =

View File

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

View File

@ -12,7 +12,7 @@
<version>2.0.0</version>
<!-- 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. -->
<idea-version since-build="192.2"/>
@ -43,6 +43,7 @@
<fileType name="Simple file" implementationClass="com.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE"
language="Simple" extensions="simple"/>
<!-- 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"/>
-->
<lang.parserDefinition language="Simple" implementationClass="com.intellij.sdk.language.SimpleParserDefinition"/>

View File

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

View File

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