mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
Incorporate Review
This commit is contained in:
parent
65dd82041f
commit
605d747a2e
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -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" />
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -15,45 +15,45 @@ public class SimpleAnnotator implements Annotator {
|
||||
// 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_SEPARATOR_STR = ":";
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
*/
|
@ -13,22 +13,22 @@ 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 ),
|
||||
new PsiReferenceProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
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 ) };
|
||||
}
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
} );
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class),
|
||||
new PsiReferenceProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
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)};
|
||||
}
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
}
|
@ -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 =
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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"/>
|
||||
|
@ -23,7 +23,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
*/
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return "src/test/testData";
|
||||
return "src/test/resources";
|
||||
}
|
||||
|
||||
public void testCompletion() {
|
||||
|
@ -17,7 +17,7 @@ public class SimpleParsingTest extends ParsingTestCase {
|
||||
*/
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return "src/test/testData";
|
||||
return "src/test/resources";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user