mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javac ast indices: move tools.jar dependent parts to another classes (follow-up 768cee3)
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.jps.backwardRefs;
|
||||
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import org.jetbrains.jps.javac.ast.api.JavacRefSymbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BackwardReferenceIndexUtil {
|
||||
static final Symbol[] EMPTY_SYMBOL_ARRAY = new Symbol[0];
|
||||
static final Tree.Kind LAMBDA_EXPRESSION;
|
||||
static final Tree.Kind MEMBER_REFERENCE;
|
||||
|
||||
static {
|
||||
Tree.Kind lambdaExpression = null;
|
||||
Tree.Kind memberReference = null;
|
||||
try {
|
||||
lambdaExpression = Tree.Kind.valueOf("LAMBDA_EXPRESSION");
|
||||
memberReference = Tree.Kind.valueOf("MEMBER_REFERENCE");
|
||||
}
|
||||
catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
LAMBDA_EXPRESSION = lambdaExpression;
|
||||
MEMBER_REFERENCE = memberReference;
|
||||
}
|
||||
|
||||
static void registerFile(String filePath,
|
||||
Set<JavacRefSymbol> refs,
|
||||
List<JavacRefSymbol> defs,
|
||||
BackwardReferenceIndexWriter writer) {
|
||||
final int fileId = writer.enumeratePath(filePath);
|
||||
int funExprId = 0;
|
||||
|
||||
final List<LightRef> definitions = new ArrayList<LightRef>(defs.size());
|
||||
for (JavacRefSymbol def : defs) {
|
||||
Tree.Kind kind = def.getPlaceKind();
|
||||
if (kind == Tree.Kind.CLASS) {
|
||||
Symbol.ClassSymbol sym = (Symbol.ClassSymbol)def.getSymbol();
|
||||
Type superclass = sym.getSuperclass();
|
||||
List<Type> interfaces = sym.getInterfaces();
|
||||
|
||||
final Symbol[] supers;
|
||||
if (superclass != Type.noType) {
|
||||
supers = new Symbol[interfaces.size() + 1];
|
||||
supers[interfaces.size()] = superclass.asElement();
|
||||
} else {
|
||||
supers = interfaces.isEmpty() ? EMPTY_SYMBOL_ARRAY : new Symbol[interfaces.size()];
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Type anInterface : interfaces) {
|
||||
supers[i++] = anInterface.asElement();
|
||||
}
|
||||
|
||||
final LightRef.JavaLightClassRef aClass = writer.asClassUsage(sym);
|
||||
definitions.add(aClass);
|
||||
|
||||
if (supers.length != 0) {
|
||||
|
||||
final LightRef.JavaLightClassRef[] superIds = new LightRef.JavaLightClassRef[supers.length];
|
||||
for (int j = 0; j < supers.length; j++) {
|
||||
superIds[j] = writer.asClassUsage(supers[j]);
|
||||
}
|
||||
|
||||
writer.writeHierarchy(fileId, aClass, superIds);
|
||||
}
|
||||
}
|
||||
else if (kind == LAMBDA_EXPRESSION || kind == MEMBER_REFERENCE) {
|
||||
final LightRef.JavaLightClassRef functionalType = writer.asClassUsage(def.getSymbol());
|
||||
int id = funExprId++;
|
||||
LightRef.JavaLightFunExprDef result = new LightRef.JavaLightFunExprDef(id);
|
||||
definitions.add(result);
|
||||
writer.writeHierarchy(fileId, result, functionalType);
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeClassDefinitions(fileId, definitions);
|
||||
|
||||
writer.writeReferences(fileId, refs);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -43,6 +43,7 @@ import static com.sun.tools.javac.code.Flags.PRIVATE;
|
||||
|
||||
public class BackwardReferenceIndexWriter {
|
||||
public static final String PROP_KEY = "ref.index.builder";
|
||||
|
||||
public static volatile boolean forceEnabled;
|
||||
|
||||
private static volatile BackwardReferenceIndexWriter ourInstance;
|
||||
@@ -245,12 +246,12 @@ public class BackwardReferenceIndexWriter {
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] bytes(Symbol symbol) {
|
||||
private static byte[] bytes(Symbol symbol) {
|
||||
return symbol.flatName().toUtf();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static LightRef fromSymbol(JavacRefSymbol refSymbol, ByteArrayEnumerator byteArrayEnumerator) {
|
||||
private static LightRef fromSymbol(JavacRefSymbol refSymbol, ByteArrayEnumerator byteArrayEnumerator) {
|
||||
Symbol symbol = refSymbol.getSymbol();
|
||||
final Tree.Kind kind = refSymbol.getPlaceKind();
|
||||
if (symbol instanceof Symbol.ClassSymbol) {
|
||||
|
||||
+1
-71
@@ -15,35 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.jps.backwardRefs;
|
||||
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import org.jetbrains.jps.javac.ast.api.JavacFileReferencesRegistrar;
|
||||
import org.jetbrains.jps.javac.ast.api.JavacRefSymbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BackwardReferenceRegistrar implements JavacFileReferencesRegistrar {
|
||||
private static final Symbol[] EMPTY_SYMBOL_ARRAY = new Symbol[0];
|
||||
|
||||
private static final Tree.Kind LAMBDA_EXPRESSION;
|
||||
private static final Tree.Kind MEMBER_REFERENCE;
|
||||
|
||||
static {
|
||||
Tree.Kind lambdaExpression = null;
|
||||
Tree.Kind memberReference = null;
|
||||
try {
|
||||
lambdaExpression = Tree.Kind.valueOf("LAMBDA_EXPRESSION");
|
||||
memberReference = Tree.Kind.valueOf("MEMBER_REFERENCE");
|
||||
}
|
||||
catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
LAMBDA_EXPRESSION = lambdaExpression;
|
||||
MEMBER_REFERENCE = memberReference;
|
||||
}
|
||||
|
||||
private BackwardReferenceIndexWriter myWriter;
|
||||
|
||||
@Override
|
||||
@@ -59,54 +37,6 @@ public class BackwardReferenceRegistrar implements JavacFileReferencesRegistrar
|
||||
|
||||
@Override
|
||||
public void registerFile(String filePath, Set<JavacRefSymbol> refs, List<JavacRefSymbol> defs) {
|
||||
final int fileId = myWriter.enumeratePath(filePath);
|
||||
int funExprId = 0;
|
||||
|
||||
final List<LightRef> definitions = new ArrayList<LightRef>(defs.size());
|
||||
for (JavacRefSymbol def : defs) {
|
||||
Tree.Kind kind = def.getPlaceKind();
|
||||
if (kind == Tree.Kind.CLASS) {
|
||||
Symbol.ClassSymbol sym = (Symbol.ClassSymbol)def.getSymbol();
|
||||
Type superclass = sym.getSuperclass();
|
||||
List<Type> interfaces = sym.getInterfaces();
|
||||
|
||||
final Symbol[] supers;
|
||||
if (superclass != Type.noType) {
|
||||
supers = new Symbol[interfaces.size() + 1];
|
||||
supers[interfaces.size()] = superclass.asElement();
|
||||
} else {
|
||||
supers = interfaces.isEmpty() ? EMPTY_SYMBOL_ARRAY : new Symbol[interfaces.size()];
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Type anInterface : interfaces) {
|
||||
supers[i++] = anInterface.asElement();
|
||||
}
|
||||
|
||||
final LightRef.JavaLightClassRef aClass = myWriter.asClassUsage(sym);
|
||||
definitions.add(aClass);
|
||||
|
||||
if (supers.length != 0) {
|
||||
|
||||
final LightRef.JavaLightClassRef[] superIds = new LightRef.JavaLightClassRef[supers.length];
|
||||
for (int j = 0; j < supers.length; j++) {
|
||||
superIds[j] = myWriter.asClassUsage(supers[j]);
|
||||
}
|
||||
|
||||
myWriter.writeHierarchy(fileId, aClass, superIds);
|
||||
}
|
||||
}
|
||||
else if (kind == LAMBDA_EXPRESSION || kind == MEMBER_REFERENCE) {
|
||||
final LightRef.JavaLightClassRef functionalType = myWriter.asClassUsage(def.getSymbol());
|
||||
int id = funExprId++;
|
||||
LightRef.JavaLightFunExprDef result = new LightRef.JavaLightFunExprDef(id);
|
||||
definitions.add(result);
|
||||
myWriter.writeHierarchy(fileId, result, functionalType);
|
||||
}
|
||||
}
|
||||
|
||||
myWriter.writeClassDefinitions(fileId, definitions);
|
||||
|
||||
myWriter.writeReferences(fileId, refs);
|
||||
BackwardReferenceIndexUtil.registerFile(filePath, refs, defs, myWriter);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-1
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.jps.javac.ast;
|
||||
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.TaskEvent;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
@@ -28,6 +30,9 @@ import org.jetbrains.jps.javac.ast.api.JavacRefSymbol;
|
||||
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -44,7 +49,29 @@ final class JavacReferenceCollectorListener implements TaskListener {
|
||||
private Set<JavacRefSymbol> myCollectedReferences;
|
||||
private List<JavacRefSymbol> myCollectedDefinitions;
|
||||
|
||||
public JavacReferenceCollectorListener(JavacFileReferencesRegistrar[] fullASTListenerArray, JavacFileReferencesRegistrar[] importsListenerArray) {
|
||||
static void installOn(JavaCompiler.CompilationTask task,
|
||||
JavacFileReferencesRegistrar[] fullASTListenerArray,
|
||||
JavacFileReferencesRegistrar[] onlyImportsListenerArray) {
|
||||
JavacTask javacTask = (JavacTask)task;
|
||||
Method addTaskMethod = ReflectionUtil.getMethod(JavacTask.class, "addTaskListener", TaskListener.class); // jdk >= 8
|
||||
final JavacReferenceCollectorListener taskListener = new JavacReferenceCollectorListener(fullASTListenerArray, onlyImportsListenerArray);
|
||||
if (addTaskMethod != null) {
|
||||
try {
|
||||
addTaskMethod.invoke(task, taskListener);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
// jdk 6-7
|
||||
javacTask.setTaskListener(taskListener);
|
||||
}
|
||||
}
|
||||
|
||||
private JavacReferenceCollectorListener(JavacFileReferencesRegistrar[] fullASTListenerArray, JavacFileReferencesRegistrar[] importsListenerArray) {
|
||||
myFullASTListeners = fullASTListenerArray;
|
||||
myOnlyImportsListeners = importsListenerArray;
|
||||
myAstScanner = JavacTreeRefScanner.createASTScanner();
|
||||
|
||||
@@ -15,16 +15,11 @@
|
||||
*/
|
||||
package org.jetbrains.jps.javac.ast;
|
||||
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import org.jetbrains.jps.javac.ast.api.JavacFileReferencesRegistrar;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -48,22 +43,6 @@ public class JavacReferencesCollector {
|
||||
return;
|
||||
}
|
||||
|
||||
JavacTask javacTask = (JavacTask)task;
|
||||
Method addTaskMethod = ReflectionUtil.getMethod(JavacTask.class, "addTaskListener", TaskListener.class); // jdk >= 8
|
||||
final JavacReferenceCollectorListener taskListener = new JavacReferenceCollectorListener(fullASTListenerArray, onlyImportsListenerArray);
|
||||
if (addTaskMethod != null) {
|
||||
try {
|
||||
addTaskMethod.invoke(task, taskListener);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
// jdk 6-7
|
||||
javacTask.setTaskListener(taskListener);
|
||||
}
|
||||
JavacReferenceCollectorListener.installOn(task, fullASTListenerArray, onlyImportsListenerArray);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user