Skip to content

Commit

Permalink
Remove TreeShims mechanism.
Browse files Browse the repository at this point in the history
The class was mostly empty at this point and was copied
around using an annotation processor.
  • Loading branch information
mbien committed Sep 27, 2023
1 parent a867eb8 commit 4911d31
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 620 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.ContinueTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.InstanceOfTree;
import com.sun.source.tree.LabeledStatementTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MemberSelectTree;
Expand Down Expand Up @@ -667,11 +666,11 @@ public static boolean isPrivateElement(Element el) {
}

public static Element toRecordComponent(Element el) {
if (el == null ||el.getKind() != ElementKind.FIELD) {
if (el == null || el.getKind() != ElementKind.FIELD) {
return el;
}
TypeElement owner = (TypeElement) el.getEnclosingElement();
if (!"RECORD".equals(owner.getKind().name())) {
if (!ElementKind.RECORD.equals(owner.getKind())) {
return el;
}
for (Element encl : owner.getEnclosedElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ private boolean process() {
}
private boolean process(TreePath path) {

Element resolved = TreeShims.toRecordComponent(info.getTrees().getElement(path));
Element resolved = org.netbeans.modules.java.editor.base.semantic.Utilities.toRecordComponent(info.getTrees().getElement(path));
if (toFind.equals(resolved)) {
found = getCurrentPath();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.sun.source.tree.BlockTree;
import com.sun.source.tree.CaseTree;
import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.IfTree;
import com.sun.source.tree.InstanceOfTree;
import com.sun.source.tree.ParenthesizedTree;
Expand All @@ -32,21 +30,17 @@
import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.tree.JCTree;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.type.TypeMirror;
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.api.java.source.TreeMaker;
import org.netbeans.api.java.source.WorkingCopy;
import org.netbeans.modules.java.source.TreeShims;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
Expand All @@ -57,7 +51,6 @@
import org.netbeans.spi.java.hints.TriggerPattern;
import org.netbeans.spi.java.hints.TriggerPatterns;
import org.netbeans.spi.java.hints.TriggerTreeKind;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;

/**
Expand Down Expand Up @@ -274,9 +267,7 @@ protected void performRewrite(JavaFix.TransformationContext ctx) {
public static ErrorDescription switchPatternMatchToSwitchNull(HintContext ctx) {

SwitchTree switchTree = (SwitchTree) ctx.getPath().getLeaf();
boolean isPatternMatch = false;
isPatternMatch = TreeShims.isPatternMatch(switchTree);
if (!isPatternMatch) {
if (!isPatternMatch(switchTree)) {
return null;
}
Tree expression = ((ParenthesizedTree) switchTree.getExpression()).getExpression();
Expand All @@ -297,6 +288,16 @@ public static ErrorDescription switchPatternMatchToSwitchNull(HintContext ctx) {

}

public static boolean isPatternMatch(Tree node) {
try {
return node.getClass().getField("patternSwitch").getBoolean(node);
} catch (NoSuchFieldException e){
return false;
} catch (IllegalArgumentException | IllegalAccessException | SecurityException ex) {
throw new RuntimeException(ex);
}
}

private static final class FixSwitchPatternMatchToSwitchNull extends JavaFix {

private final int indexOf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.java.hints.test.api.HintTest;
import javax.lang.model.SourceVersion;
import org.testng.annotations.Test;

/**
Expand Down
Loading

0 comments on commit 4911d31

Please sign in to comment.