Skip to content

Commit

Permalink
Return type support: disabled temporarily;
Browse files Browse the repository at this point in the history
  • Loading branch information
rentalhost committed Dec 19, 2017
1 parent df70700 commit b3f4972
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 44 deletions.
1 change: 1 addition & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<li><strong>Blade</strong> (<em>Reverted</em>): added support to comments folding again (FR <a href="https://youtrack.jetbrains.com/issue/WI-39264">#WI-39264</a>);</li>
<li><strong>Development</strong> (<em>Added</em>): added a <a href="https://github.com/rentalhost/laravel-insight/blob/master/development/DEVELOPMENT.md">development guide</a>;</li>
<li><strong>Plugin</strong> (<em>Fixed</em>): recompiled to support PS 2017.3+ builds;</li>
<li><strong>Return Type Support</strong> (<em>Disabled</em>): return type support was <em>disabled temporarily</em> due to software limitation (waiting for IntelliJ IDEA 2017.3.2);</li>
</ul>
]]></change-notes>

Expand Down
21 changes: 0 additions & 21 deletions src/laravelInsight/fluent/UsingAsTypeInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocType;
import com.jetbrains.php.lang.inspections.PhpInspection;
import com.jetbrains.php.lang.psi.elements.Function;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.Parameter;
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;

Expand All @@ -29,24 +26,6 @@ public PsiElementVisitor buildVisitor(
final boolean isOnTheFly
) {
return new PhpElementVisitor() {
@Override
public void visitPhpMethod(final Method method) {
final PsiElement methodReturnType = method.getReturnType();

if (FluentUtil.isUsingDirectly(methodReturnType)) {
problemsHolder.registerProblem(methodReturnType, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING);
}
}

@Override
public void visitPhpFunction(final Function function) {
final PsiElement functionReturnType = function.getReturnType();

if (FluentUtil.isUsingDirectly(functionReturnType)) {
problemsHolder.registerProblem(functionReturnType, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING);
}
}

@Override
public void visitPhpParameter(final Parameter parameter) {
if (FluentUtil.isUsingDirectly(parameter)) {
Expand Down
24 changes: 1 addition & 23 deletions src/utils/PhpFunctionUtil.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package net.rentalhost.idea.utils;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.jetbrains.php.codeInsight.controlFlow.instructions.PhpInstruction;
import com.jetbrains.php.codeInsight.controlFlow.instructions.PhpReturnInstruction;
import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment;
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocReturnTag;
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
import com.jetbrains.php.lang.psi.elements.ClassReference;
import com.jetbrains.php.lang.psi.elements.Function;
import com.jetbrains.php.lang.psi.elements.FunctionReference;
import com.jetbrains.php.lang.psi.elements.NewExpression;
import com.jetbrains.php.lang.psi.elements.PhpReference;
import com.jetbrains.php.lang.psi.elements.PhpTypedElement;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;

import java.util.Objects;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
Expand All @@ -27,25 +23,7 @@ public enum PhpFunctionUtil {
@NotNull
public static PhpType getReturnType(@NotNull final Function functionInitial) {
final PhpType typeResolved = RecursionResolver.resolve(functionInitial, (RecursionResolver.Resolver resolver) -> {
final Function function = (Function) resolver.getObject();
final PsiElement functionReturnType = function.getReturnType();

if (functionReturnType instanceof PhpReference) {
final String functionReturnTypeFQN = ((PhpReference) functionReturnType).getFQN();
final PhpType.PhpTypeBuilder functionReturnTypePrimary = PhpType.builder().add(functionReturnTypeFQN);

final PsiElement prevMatch = TreeUtil.getPrevMatch(
functionReturnType,
filterBy -> (filterBy instanceof ASTNode) && Objects.equals(((ASTNode) filterBy).getElementType(), PhpTokenTypes.opQUEST),
stopBy -> (stopBy instanceof ASTNode) && Objects.equals(((ASTNode) stopBy).getElementType(), PhpTokenTypes.chRPAREN)
);

if (prevMatch instanceof ASTNode) {
functionReturnTypePrimary.add(PhpType.NULL);
}

return functionReturnTypePrimary.build();
}
final Function function = (Function) resolver.getObject();

final PhpInstruction[] phpInstructions = function.getControlFlow().getInstructions();
if (phpInstructions.length != 0) {
Expand Down

0 comments on commit b3f4972

Please sign in to comment.