Skip to content

Commit

Permalink
Added some functionality back in and updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
notzippy committed Jul 23, 2019
1 parent c87d18a commit 1b82f95
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -39,6 +39,7 @@ allprojects {
}
test {
java.srcDir 'src/test/java'
resources.srcDirs 'src/main/resources'
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.notzippy.intellij.go.grammar.psi.*;
import com.notzippy.intellij.go.intellij.GoConstants;
import com.notzippy.intellij.go.intellij.quickfix.GoEmptySignatureQuickFix;
import com.notzippy.intellij.go.parser.GoTypes;
import com.notzippy.intellij.go.grammar.psi.impl.GoCType;
import com.notzippy.intellij.go.grammar.psi.impl.GoPsiImplUtil;
Expand Down Expand Up @@ -185,11 +186,13 @@ else if (element instanceof GoFunctionDeclaration) {
if (result != null && !result.isVoid()) {
Annotation annotation = holder.createErrorAnnotation(result, declaration.getName() +
" function must have no arguments and no return values");
annotation.registerFix(new GoEmptySignatureQuickFix(declaration));
}
GoParameters parameters = signature.getParameters();
if (!parameters.getParameterDeclarationList().isEmpty()) {
Annotation annotation = holder.createErrorAnnotation(parameters, declaration.getName() +
" function must have no arguments and no return values");
annotation.registerFix(new GoEmptySignatureQuickFix(declaration));
}
}
}
Expand Down
Expand Up @@ -53,12 +53,13 @@ public String getFamilyName() {

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
return getData(element) != null;
boolean available = getData(element) != null;
return available;
}

@Nullable
private static Data getData(@NotNull PsiElement element) {
if (!element.isValid() || !element.isWritable()) return null;
if (!element.isValid()) return null; // removed || !element.isWritable())
GoAssignmentStatement assignment = getValidAssignmentParent(element);
GoReferenceExpression selectedFieldReference = assignment != null ? getFieldReferenceExpression(element, assignment) : null;
GoCompositeLit compositeLit = selectedFieldReference != null ? getStructLiteralByReference(selectedFieldReference, assignment) : null;
Expand All @@ -71,6 +72,9 @@ private static Data getData(@NotNull PsiElement element) {
@Nullable
private static GoAssignmentStatement getValidAssignmentParent(@Nullable PsiElement element) {
GoAssignmentStatement assignment = PsiTreeUtil.getNonStrictParentOfType(element, GoAssignmentStatement.class);
if (assignment == null) {
assignment = PsiTreeUtil.getNonStrictParentOfType(element.getPrevSibling(), GoAssignmentStatement.class);
}
return assignment != null && assignment.isValid() && getLeftHandElements(assignment).size() == assignment.getExpressionList().size()
? assignment : null;
}
Expand Down
Expand Up @@ -16,15 +16,15 @@

package com.notzippy.intellij.go.intellij.quickfix;

import com.notzippy.intellij.go.grammar.psi.GoFunctionDeclaration;
import com.notzippy.intellij.go.grammar.psi.GoSignature;
import com.notzippy.intellij.go.grammar.psi.impl.GoElementFactory;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.ObjectUtils;
import com.notzippy.intellij.go.grammar.psi.GoFunctionDeclaration;
import com.notzippy.intellij.go.grammar.psi.GoSignature;
import com.notzippy.intellij.go.grammar.psi.impl.GoElementFactory;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Expand Up @@ -43,7 +43,7 @@ public void tryClosure() {
}
catch (AssertionError e) {
String message = e.getMessage();
assertTrue(message.contains("Access to tree elements not allowed in tests"));
assertTrue(message.contains("Access to tree elements not allowed"));
assertTrue(message.contains("bar.go"));
throw e;
}
Expand Down

0 comments on commit 1b82f95

Please sign in to comment.