Moved commons and concourse editor to 'headless-services'
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMemberValuePair;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public class AnnotationImpl implements IAnnotation {
|
||||
|
||||
private AnnotationInstance annotation;
|
||||
private IJavadocProvider javadocProvider;
|
||||
|
||||
AnnotationImpl(AnnotationInstance annotation, IJavadocProvider javadocProvider) {
|
||||
this.annotation = annotation;
|
||||
this.javadocProvider = javadocProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return annotation.name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavaDoc() {
|
||||
return javadocProvider == null ? null : javadocProvider.getJavadoc(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IMemberValuePair> getMemberValuePairs() {
|
||||
return annotation.values().stream().map(av -> {
|
||||
return Wrappers.wrap(av);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotation.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return annotation.toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof AnnotationImpl) {
|
||||
return annotation.toString().equals(((AnnotationImpl)obj).annotation.toString());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import static org.springframework.ide.vscode.commons.jandex.Wrappers.wrap;
|
||||
|
||||
import org.jboss.jandex.ArrayType;
|
||||
import org.springframework.ide.vscode.commons.java.IArrayType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
|
||||
final class ArrayTypeWrapper extends TypeWrapper<ArrayType> implements IArrayType {
|
||||
|
||||
ArrayTypeWrapper(ArrayType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return getType().name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int dimensions() {
|
||||
return getType().dimensions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaType component() {
|
||||
return wrap(getType().component());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import org.jboss.jandex.ClassType;
|
||||
import org.springframework.ide.vscode.commons.java.IClassType;
|
||||
|
||||
final class ClassTypeWrapper extends TypeWrapper<ClassType> implements IClassType {
|
||||
|
||||
ClassTypeWrapper(ClassType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return getType().name().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.FieldInfo;
|
||||
import org.springframework.ide.vscode.commons.java.Flags;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
class FieldImpl implements IField {
|
||||
|
||||
private JandexIndex index;
|
||||
private FieldInfo field;
|
||||
private IJavadocProvider javadocProvider;
|
||||
|
||||
FieldImpl(JandexIndex index, FieldInfo field, IJavadocProvider javadocProvider) {
|
||||
this.index = index;
|
||||
this.field = field;
|
||||
this.javadocProvider = javadocProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlags() {
|
||||
return field.flags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getDeclaringType() {
|
||||
return Wrappers.wrap(index, field.declaringClass(), javadocProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return field.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavaDoc() {
|
||||
return javadocProvider == null ? null : javadocProvider.getJavadoc(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IAnnotation> getAnnotations() {
|
||||
return field.annotations().stream().map(a -> {
|
||||
return Wrappers.wrap(a, javadocProvider);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnumConstant() {
|
||||
return Flags.isEnum(field.flags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return field.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return field.toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof FieldImpl) {
|
||||
return field.toString().equals(((FieldImpl)obj).field.toString());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
public abstract class JandexClasspath implements IClasspath {
|
||||
|
||||
public static JavadocProviderTypes providerType = JavadocProviderTypes.HTML;
|
||||
|
||||
public enum JavadocProviderTypes {
|
||||
JAVA_PARSER,
|
||||
HTML
|
||||
}
|
||||
|
||||
private Supplier<JandexIndex> javaIndex;
|
||||
|
||||
public JandexClasspath() {
|
||||
this.javaIndex = Suppliers.memoize(() -> createIndex());
|
||||
}
|
||||
|
||||
protected JandexIndex createIndex() {
|
||||
Stream<Path> classpathEntries = Stream.empty();
|
||||
try {
|
||||
classpathEntries = getClasspathEntries();
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return new JandexIndex(classpathEntries.map(p -> p.toFile()).collect(Collectors.toList()), jarFile -> findIndexFile(jarFile), classpathResource -> {
|
||||
switch (providerType) {
|
||||
case JAVA_PARSER:
|
||||
return createParserJavadocProvider(classpathResource);
|
||||
default:
|
||||
return createHtmlJavdocProvider(classpathResource);
|
||||
}
|
||||
}, getBaseIndices());
|
||||
}
|
||||
|
||||
protected JandexIndex[] getBaseIndices() {
|
||||
return new JandexIndex[0];
|
||||
}
|
||||
|
||||
public IType findType(String fqName) {
|
||||
return javaIndex.get().findType(fqName);
|
||||
}
|
||||
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
return javaIndex.get().fuzzySearchTypes(searchTerm, typeFilter);
|
||||
}
|
||||
|
||||
public Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm) {
|
||||
return javaIndex.get().fuzzySearchPackages(searchTerm);
|
||||
}
|
||||
|
||||
public Flux<IType> allSubtypesOf(IType type) {
|
||||
return javaIndex.get().allSubtypesOf(type);
|
||||
}
|
||||
|
||||
private File findIndexFile(File jarFile) {
|
||||
File indexFolder = getIndexFolder();
|
||||
if (indexFolder == null) {
|
||||
return null;
|
||||
}
|
||||
return new File(indexFolder.toString(), jarFile.getName() + "-" + jarFile.lastModified() + ".jdx");
|
||||
}
|
||||
|
||||
protected File getIndexFolder() {
|
||||
return JandexIndex.getIndexFolder();
|
||||
}
|
||||
|
||||
abstract protected IJavadocProvider createParserJavadocProvider(File classpathResource);
|
||||
|
||||
abstract protected IJavadocProvider createHtmlJavdocProvider(File classpathResource);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.jandex.IndexReader;
|
||||
import org.jboss.jandex.IndexView;
|
||||
import org.jboss.jandex.Indexer;
|
||||
import org.jboss.jandex.JarIndexer;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
public class JandexIndex {
|
||||
|
||||
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface IndexFileFinder {
|
||||
File findIndexFile(File jarFile);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface JavadocProviderFactory {
|
||||
IJavadocProvider createJavadocProvider(File jarContainer);
|
||||
}
|
||||
|
||||
public static File getIndexFolder() {
|
||||
File folder = new File(System.getProperty(JAVA_IO_TMPDIR), "jandex");
|
||||
if (!folder.isDirectory()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
private static final IJavadocProvider ABSENT_JAVADOC_PROVIDER = new IJavadocProvider() {
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IAnnotation method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private Map<File, Supplier<Optional<IndexView>>> index;
|
||||
|
||||
private JavadocProviderFactory javadocProviderFactory;
|
||||
|
||||
private Map<File, Supplier<List<Tuple2<String, IType>>>> knownTypes;
|
||||
|
||||
private Map<File, Supplier<List<String>>> knownPackages;
|
||||
|
||||
private Cache<File, IJavadocProvider> javadocProvidersCache = CacheBuilder.newBuilder().build();
|
||||
|
||||
private JandexIndex[] baseIndex;
|
||||
|
||||
public void setJvadocProviderFactory(JavadocProviderFactory sourceContainerProvider) {
|
||||
this.javadocProviderFactory = sourceContainerProvider;
|
||||
}
|
||||
|
||||
public JavadocProviderFactory getJavadocProviderFactory() {
|
||||
return javadocProviderFactory;
|
||||
}
|
||||
|
||||
public JandexIndex(Collection<File> classpathEntries, IndexFileFinder indexFileFinder,
|
||||
JavadocProviderFactory javadocProviderFactory, JandexIndex... baseIndex) {
|
||||
this.baseIndex = baseIndex;
|
||||
this.index = new ConcurrentHashMap<>();
|
||||
this.knownTypes = new HashMap<>();
|
||||
this.knownPackages = new HashMap<>();
|
||||
this.javadocProviderFactory = javadocProviderFactory;
|
||||
classpathEntries.forEach(file -> {
|
||||
index.put(file, Suppliers.memoize(() -> createIndex(file, indexFileFinder)));
|
||||
knownTypes.put(file, Suppliers.memoize(() -> getKnownTypesStream(file).collect(Collectors.toList())));
|
||||
knownPackages.put(file, Suppliers.memoize(() -> getKnownPackages(file).collect(Collectors.toList())));
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<IndexView> createIndex(File file, IndexFileFinder indexFileFinder) {
|
||||
if (file != null && file.isFile() && file.getName().endsWith(".jar")) {
|
||||
return indexJar(file, indexFileFinder);
|
||||
} else if (file != null && file.isDirectory()) {
|
||||
return indexFolder(file);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<IndexView> indexFolder(File folder) {
|
||||
Indexer indexer = new Indexer();
|
||||
for (Iterator<File> itr = com.google.common.io.Files.fileTreeTraverser().breadthFirstTraversal(folder)
|
||||
.iterator(); itr.hasNext();) {
|
||||
File file = itr.next();
|
||||
if (file.isFile() && file.getName().endsWith(".class")) {
|
||||
try {
|
||||
final InputStream stream = new FileInputStream(file);
|
||||
try {
|
||||
indexer.index(stream);
|
||||
} finally {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.of(indexer.complete());
|
||||
}
|
||||
|
||||
private static Optional<IndexView> indexJar(File file, IndexFileFinder indexFileFinder) {
|
||||
File indexFile = indexFileFinder.findIndexFile(file);
|
||||
if (indexFile != null) {
|
||||
try {
|
||||
if (indexFile.createNewFile()) {
|
||||
try {
|
||||
return Optional.of(JarIndexer.createJarIndex(file, new Indexer(), indexFile, false, false,
|
||||
false, System.out, System.err).getIndex());
|
||||
} catch (IOException e) {
|
||||
Log.log("Failed to index '" + file + "'", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return Optional.of(new IndexReader(new FileInputStream(indexFile)).read());
|
||||
} catch (IOException e) {
|
||||
Log.log("Failed to read index file '" + indexFile + "'. Creating new index file.", e);
|
||||
if (indexFile.delete()) {
|
||||
return indexJar(file, indexFileFinder);
|
||||
} else {
|
||||
Log.log("Failed to read index file '" + indexFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.log("Unable to create index file '" + indexFile + "'");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return Optional.of(JarIndexer
|
||||
.createJarIndex(file, new Indexer(), file.canWrite(), file.getParentFile().canWrite(), false)
|
||||
.getIndex());
|
||||
} catch (IOException e) {
|
||||
Log.log("Failed to index '" + file + "'", e);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public IType findType(String fqName) {
|
||||
return getClassByName(DotName.createSimple(fqName));
|
||||
}
|
||||
|
||||
IType getClassByName(DotName fqName) {
|
||||
// First look for type in the base index array
|
||||
return (baseIndex == null ? Stream.<IType>empty()
|
||||
: Arrays.stream(
|
||||
baseIndex)
|
||||
.filter(
|
||||
jandexIndex -> jandexIndex != null)
|
||||
.map(jandexIndex -> jandexIndex.getClassByName(fqName))).filter(type -> type != null)
|
||||
.findFirst()
|
||||
// If not found look at indices owned by this
|
||||
// JandexIndex instance
|
||||
.orElseGet(() -> streamOfIndices()
|
||||
.map(e -> Tuples.of(e.getT1(), e.getT2().getClassByName(fqName)))
|
||||
.filter(e -> e.getT2() != null).map(e -> createType(e)).findFirst()
|
||||
.orElse(null));
|
||||
|
||||
}
|
||||
|
||||
private IType createType(Tuple2<File, ClassInfo> match) {
|
||||
File classpathResource = match.getT1();
|
||||
IJavadocProvider javadocProvider = null;
|
||||
try {
|
||||
javadocProvider = javadocProvidersCache.get(classpathResource, () -> {
|
||||
IJavadocProvider provider = null;
|
||||
if (javadocProviderFactory != null) {
|
||||
provider = javadocProviderFactory.createJavadocProvider(classpathResource);
|
||||
}
|
||||
return provider == null ? ABSENT_JAVADOC_PROVIDER : provider;
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return Wrappers.wrap(this, match.getT2(), javadocProvider);
|
||||
}
|
||||
|
||||
private Stream<Tuple2<File, IndexView>> streamOfIndices() {
|
||||
return index.entrySet().parallelStream().map(e -> Tuples.of(e.getKey(), e.getValue().get()))
|
||||
.filter(t -> t.getT2().isPresent()).map(t -> Tuples.of(t.getT1(), t.getT2().get()));
|
||||
}
|
||||
|
||||
private Stream<Tuple2<String, IType>> getKnownTypesStream(File file) {
|
||||
Optional<IndexView> indexView = index.get(file).get();
|
||||
if (indexView.isPresent()) {
|
||||
return indexView.get().getKnownClasses().parallelStream()
|
||||
.map(info -> Tuples.of(info.name().toString(), createType(Tuples.of(file, info))));
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
private Stream<String> getKnownPackages(File file) {
|
||||
Optional<IndexView> indexView = index.get(file).get();
|
||||
if (indexView.isPresent()) {
|
||||
return indexView.get().getKnownClasses().parallelStream().map(info -> {
|
||||
String name = info.name().toString();
|
||||
return name.substring(0, name.lastIndexOf('.'));
|
||||
}).distinct();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
|
||||
Flux<Tuple2<IType, Double>> flux = Flux.fromIterable(knownTypes.values()).publishOn(Schedulers.parallel())
|
||||
.flatMap(s -> Flux.fromIterable(s.get())).filter(t -> typeFilter == null || typeFilter.test(t.getT2()))
|
||||
.map(t -> Tuples.of(t.getT2(), FuzzyMatcher.matchScore(searchTerm, t.getT1())))
|
||||
.filter(t -> t.getT2() != 0.0);
|
||||
if (baseIndex == null) {
|
||||
return flux;
|
||||
} else {
|
||||
return Flux.merge(flux,
|
||||
Flux.fromArray(baseIndex).flatMap(index -> index.fuzzySearchTypes(searchTerm, typeFilter)));
|
||||
}
|
||||
}
|
||||
|
||||
public Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm) {
|
||||
Flux<Tuple2<String, Double>> flux = Flux.fromIterable(knownPackages.values()).publishOn(Schedulers.parallel())
|
||||
.flatMap(s -> Flux.fromIterable(s.get()))
|
||||
.map(pkg -> Tuples.of(pkg, FuzzyMatcher.matchScore(searchTerm, pkg))).filter(t -> t.getT2() != 0.0);
|
||||
if (baseIndex == null) {
|
||||
return flux;
|
||||
} else {
|
||||
return Flux.merge(flux, Flux.fromArray(baseIndex).flatMap(index -> index.fuzzySearchPackages(searchTerm)));
|
||||
}
|
||||
}
|
||||
|
||||
public Flux<IType> allSubtypesOf(IType type) {
|
||||
DotName name = DotName.createSimple(type.getFullyQualifiedName());
|
||||
Flux<IType> flux = Flux.fromIterable(index.keySet()).publishOn(Schedulers.parallel()).flatMap(file -> {
|
||||
Optional<IndexView> optional = index.get(file).get();
|
||||
if (optional.isPresent()) {
|
||||
return Flux
|
||||
.fromIterable(type.isInterface() ? optional.get().getAllKnownImplementors(name)
|
||||
: optional.get().getAllKnownSubclasses(name))
|
||||
.publishOn(Schedulers.parallel()).map(info -> createType(Tuples.of(file, info)));
|
||||
} else {
|
||||
return Flux.empty();
|
||||
}
|
||||
});
|
||||
if (baseIndex == null) {
|
||||
return flux;
|
||||
} else {
|
||||
return Flux.merge(flux, Flux.fromArray(baseIndex).flatMap(index -> index.allSubtypesOf(type)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.MethodInfo;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public class MethodImpl implements IMethod {
|
||||
|
||||
private static final String JANDEX_CONTRUCTOR_NAME = "<init>";
|
||||
|
||||
|
||||
private JandexIndex index;
|
||||
private MethodInfo method;
|
||||
private IJavadocProvider javadocProvider;
|
||||
|
||||
MethodImpl(JandexIndex index, MethodInfo method, IJavadocProvider javadocProvider) {
|
||||
this.index = index;
|
||||
this.method = method;
|
||||
this.javadocProvider =javadocProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlags() {
|
||||
return method.flags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConstructor() {
|
||||
return method.name().equals(JANDEX_CONTRUCTOR_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getDeclaringType() {
|
||||
return Wrappers.wrap(index, method.declaringClass(), javadocProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return isConstructor() ? getDeclaringType().getElementName() : method.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavaDoc() {
|
||||
return javadocProvider == null ? null : javadocProvider.getJavadoc(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IAnnotation> getAnnotations() {
|
||||
return method.annotations().stream().map(a -> Wrappers.wrap(a, javadocProvider));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaType getReturnType() {
|
||||
return Wrappers.wrap(method.returnType());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getSignature() {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append('(');
|
||||
// method.parameters().forEach(p -> sb.append(signature(p)));
|
||||
// sb.append(')');
|
||||
// sb.append(getReturnType());
|
||||
// return sb.toString();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return method.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IJavaType> parameters() {
|
||||
return method.parameters().stream().map(Wrappers::wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return method.toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof MethodImpl) {
|
||||
return method.toString().equals(((MethodImpl)obj).method.toString());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import static org.springframework.ide.vscode.commons.jandex.Wrappers.wrap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.ParameterizedType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
import org.springframework.ide.vscode.commons.java.IParameterizedType;
|
||||
|
||||
final class ParameterizedTypeWrapper extends TypeWrapper<ParameterizedType> implements IParameterizedType {
|
||||
|
||||
ParameterizedTypeWrapper(ParameterizedType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return getType().name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaType owner() {
|
||||
return wrap(getType().owner());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IJavaType> arguments() {
|
||||
return getType().arguments().stream().map(Wrappers::wrap);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.jandex.Type;
|
||||
import org.springframework.ide.vscode.commons.java.Flags;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
class TypeImpl implements IType {
|
||||
|
||||
private ClassInfo info;
|
||||
private JandexIndex index;
|
||||
private IJavadocProvider javadocProvider;
|
||||
|
||||
TypeImpl(JandexIndex index, ClassInfo info, IJavadocProvider javadocProvider) {
|
||||
this.info = info;
|
||||
this.index = index;
|
||||
this.javadocProvider = javadocProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlags() {
|
||||
return info.flags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getDeclaringType() {
|
||||
DotName enclosingClass = info.enclosingClass();
|
||||
return enclosingClass == null ? null : index.getClassByName(enclosingClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return info.simpleName() == null ? info.name().local() : info.simpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavaDoc() {
|
||||
return javadocProvider == null ? null : javadocProvider.getJavadoc(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IAnnotation> getAnnotations() {
|
||||
// TODO: check correctness!
|
||||
List<AnnotationInstance> annotations = info.annotations().get(info.name());
|
||||
return annotations == null ? Stream.empty() : annotations.stream().map(a -> Wrappers.wrap(a, javadocProvider));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClass() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
return Flags.isEnum(info.flags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterface() {
|
||||
return Flags.isInterface(info.flags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotation() {
|
||||
return Flags.isAnnotation(info.flags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullyQualifiedName() {
|
||||
return info.name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IField getField(String name) {
|
||||
return Wrappers.wrap(index, info.field(name), javadocProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IField> getFields() {
|
||||
return info.fields().stream().map(f -> {
|
||||
return Wrappers.wrap(index, f, javadocProvider);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMethod getMethod(String name, Stream<IJavaType> parameters) {
|
||||
List<Type> typeParameters = parameters.map(Wrappers::from).collect(Collectors.toList());
|
||||
return Wrappers.wrap(index, info.method(name, typeParameters.toArray(new Type[typeParameters.size()])), javadocProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<IMethod> getMethods() {
|
||||
return info.methods().stream().map(m -> {
|
||||
return Wrappers.wrap(index, m, javadocProvider);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return info.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return info.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TypeImpl) {
|
||||
return info.equals(((TypeImpl)obj).info);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import org.jboss.jandex.TypeVariable;
|
||||
import org.springframework.ide.vscode.commons.java.ITypeVariable;
|
||||
|
||||
final class TypeVariableWrapper extends TypeWrapper<TypeVariable> implements ITypeVariable {
|
||||
|
||||
TypeVariableWrapper(TypeVariable type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return getType().name().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
class TypeWrapper<T> {
|
||||
|
||||
private T type;
|
||||
|
||||
TypeWrapper(T type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
T getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return type.hashCode();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TypeWrapper) {
|
||||
return type.equals(((TypeWrapper<T>)obj).type);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import org.jboss.jandex.UnresolvedTypeVariable;
|
||||
import org.springframework.ide.vscode.commons.java.IUnresolvedTypeVariable;
|
||||
|
||||
final class UnresolvedTypeVariableWrapper extends TypeWrapper<UnresolvedTypeVariable> implements IUnresolvedTypeVariable {
|
||||
|
||||
UnresolvedTypeVariableWrapper(UnresolvedTypeVariable type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return getType().name().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import org.jboss.jandex.WildcardType;
|
||||
import org.springframework.ide.vscode.commons.java.IWildcardType;
|
||||
|
||||
final class WildcardTypeWrapper extends TypeWrapper<WildcardType> implements IWildcardType {
|
||||
|
||||
WildcardTypeWrapper(WildcardType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import static org.springframework.ide.vscode.commons.util.Assert.isNotNull;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationValue;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.FieldInfo;
|
||||
import org.jboss.jandex.MethodInfo;
|
||||
import org.jboss.jandex.PrimitiveType;
|
||||
import org.jboss.jandex.Type;
|
||||
import org.jboss.jandex.Type.Kind;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMemberValuePair;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IPrimitiveType;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.IVoidType;
|
||||
|
||||
public class Wrappers {
|
||||
|
||||
public static IType wrap(JandexIndex index, ClassInfo info, IJavadocProvider javadocProvider) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
return new TypeImpl(index, info, javadocProvider);
|
||||
}
|
||||
|
||||
public static IField wrap(JandexIndex index, FieldInfo field, IJavadocProvider javadocProvider) {
|
||||
if (field == null) {
|
||||
return null;
|
||||
}
|
||||
return new FieldImpl(index, field, javadocProvider);
|
||||
}
|
||||
|
||||
public static IMethod wrap(JandexIndex index, MethodInfo method, IJavadocProvider javadocProvider) {
|
||||
isNotNull(index);
|
||||
isNotNull(method);
|
||||
return new MethodImpl(index, method, javadocProvider);
|
||||
}
|
||||
|
||||
public static IAnnotation wrap(AnnotationInstance annotation, IJavadocProvider javadocProvider) {
|
||||
isNotNull(annotation);
|
||||
return new AnnotationImpl(annotation, javadocProvider);
|
||||
}
|
||||
|
||||
public static IMemberValuePair wrap(AnnotationValue annotationValue) {
|
||||
if (annotationValue == null) {
|
||||
return null;
|
||||
}
|
||||
return new IMemberValuePair() {
|
||||
|
||||
@Override
|
||||
public String getMemberName() {
|
||||
return annotationValue.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return annotationValue.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotationValue.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static IPrimitiveType wrap(PrimitiveType type) {
|
||||
switch (type.primitive()) {
|
||||
case SHORT:
|
||||
return IPrimitiveType.SHORT;
|
||||
case LONG:
|
||||
return IPrimitiveType.LONG;
|
||||
case BYTE:
|
||||
return IPrimitiveType.BYTE;
|
||||
case DOUBLE:
|
||||
return IPrimitiveType.DOUBLE;
|
||||
case BOOLEAN:
|
||||
return IPrimitiveType.BOOLEAN;
|
||||
case CHAR:
|
||||
return IPrimitiveType.CHAR;
|
||||
case FLOAT:
|
||||
return IPrimitiveType.FLOAT;
|
||||
case INT:
|
||||
return IPrimitiveType.INT;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid Java primitive type! " + type.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Type from(IJavaType type) {
|
||||
if (type == IPrimitiveType.BOOLEAN) {
|
||||
return PrimitiveType.BOOLEAN;
|
||||
} else if (type == IPrimitiveType.BYTE) {
|
||||
return PrimitiveType.BYTE;
|
||||
} else if (type == IPrimitiveType.CHAR) {
|
||||
return PrimitiveType.CHAR;
|
||||
} else if (type == IPrimitiveType.DOUBLE) {
|
||||
return PrimitiveType.DOUBLE;
|
||||
} else if (type == IPrimitiveType.FLOAT) {
|
||||
return PrimitiveType.FLOAT;
|
||||
} else if (type == IPrimitiveType.INT) {
|
||||
return PrimitiveType.INT;
|
||||
} else if (type == IPrimitiveType.LONG) {
|
||||
return PrimitiveType.LONG;
|
||||
} else if (type == IPrimitiveType.SHORT) {
|
||||
return PrimitiveType.SHORT;
|
||||
} else if (type == IVoidType.DEFAULT) {
|
||||
return Type.create(null, Kind.VOID);
|
||||
} else if (type instanceof TypeWrapper) {
|
||||
return ((TypeWrapper<Type>)type).getType();
|
||||
}
|
||||
throw new IllegalArgumentException("Not a Jandex wrapped typed!");
|
||||
}
|
||||
|
||||
public static IJavaType wrap(Type type) {
|
||||
switch (type.kind()) {
|
||||
case ARRAY:
|
||||
return new ArrayTypeWrapper(type.asArrayType());
|
||||
case CLASS:
|
||||
return new ClassTypeWrapper(type.asClassType());
|
||||
case PARAMETERIZED_TYPE:
|
||||
return new ParameterizedTypeWrapper(type.asParameterizedType());
|
||||
case PRIMITIVE:
|
||||
return wrap(type.asPrimitiveType());
|
||||
case TYPE_VARIABLE:
|
||||
return new TypeVariableWrapper(type.asTypeVariable());
|
||||
case UNRESOLVED_TYPE_VARIABLE:
|
||||
return new UnresolvedTypeVariableWrapper(type.asUnresolvedTypeVariable());
|
||||
case VOID:
|
||||
return IVoidType.DEFAULT;
|
||||
case WILDCARD_TYPE:
|
||||
return new WildcardTypeWrapper(type.asWildcardType());
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid Java Type " + type.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2014 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Jesper S Moller - Contributions for
|
||||
* Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335
|
||||
* Bug 406982 - [1.8][compiler] Generation of MethodParameters Attribute in classfile
|
||||
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
|
||||
* Bug 405104 - [1.8][compiler][codegen] Implement support for serializeable lambdas
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface ClassFileConstants {
|
||||
|
||||
int AccDefault = 0;
|
||||
/*
|
||||
* Modifiers
|
||||
*/
|
||||
int AccPublic = 0x0001;
|
||||
int AccPrivate = 0x0002;
|
||||
int AccProtected = 0x0004;
|
||||
int AccStatic = 0x0008;
|
||||
int AccFinal = 0x0010;
|
||||
int AccSynchronized = 0x0020;
|
||||
int AccVolatile = 0x0040;
|
||||
int AccBridge = 0x0040;
|
||||
int AccTransient = 0x0080;
|
||||
int AccVarargs = 0x0080;
|
||||
int AccNative = 0x0100;
|
||||
int AccInterface = 0x0200;
|
||||
int AccAbstract = 0x0400;
|
||||
int AccStrictfp = 0x0800;
|
||||
int AccSynthetic = 0x1000;
|
||||
int AccAnnotation = 0x2000;
|
||||
int AccEnum = 0x4000;
|
||||
|
||||
/**
|
||||
* From classfile version 52 (compliance 1.8 up), meaning that a formal parameter is mandated
|
||||
* by a language specification, so all compilers for the language must emit it.
|
||||
*/
|
||||
int AccMandated = 0x8000;
|
||||
|
||||
|
||||
/**
|
||||
* Other VM flags.
|
||||
*/
|
||||
int AccSuper = 0x0020;
|
||||
|
||||
// /**
|
||||
// * Extra flags for types and members attributes (not from the JVMS, should have been defined in ExtraCompilerModifiers).
|
||||
// */
|
||||
// int AccAnnotationDefault = ASTNode.Bit18; // indicate presence of an attribute "DefaultValue" (annotation method)
|
||||
// int AccDeprecated = ASTNode.Bit21; // indicate presence of an attribute "Deprecated"
|
||||
|
||||
int Utf8Tag = 1;
|
||||
int IntegerTag = 3;
|
||||
int FloatTag = 4;
|
||||
int LongTag = 5;
|
||||
int DoubleTag = 6;
|
||||
int ClassTag = 7;
|
||||
int StringTag = 8;
|
||||
int FieldRefTag = 9;
|
||||
int MethodRefTag = 10;
|
||||
int InterfaceMethodRefTag = 11;
|
||||
int NameAndTypeTag = 12;
|
||||
int MethodHandleTag = 15;
|
||||
int MethodTypeTag = 16;
|
||||
int InvokeDynamicTag = 18;
|
||||
|
||||
int ConstantMethodRefFixedSize = 5;
|
||||
int ConstantClassFixedSize = 3;
|
||||
int ConstantDoubleFixedSize = 9;
|
||||
int ConstantFieldRefFixedSize = 5;
|
||||
int ConstantFloatFixedSize = 5;
|
||||
int ConstantIntegerFixedSize = 5;
|
||||
int ConstantInterfaceMethodRefFixedSize = 5;
|
||||
int ConstantLongFixedSize = 9;
|
||||
int ConstantStringFixedSize = 3;
|
||||
int ConstantUtf8FixedSize = 3;
|
||||
int ConstantNameAndTypeFixedSize = 5;
|
||||
int ConstantMethodHandleFixedSize = 4;
|
||||
int ConstantMethodTypeFixedSize = 3;
|
||||
int ConstantInvokeDynamicFixedSize = 5;
|
||||
|
||||
// JVMS 4.4.8
|
||||
int MethodHandleRefKindGetField = 1;
|
||||
int MethodHandleRefKindGetStatic = 2;
|
||||
int MethodHandleRefKindPutField = 3;
|
||||
int MethodHandleRefKindPutStatic = 4;
|
||||
int MethodHandleRefKindInvokeVirtual = 5;
|
||||
int MethodHandleRefKindInvokeStatic = 6;
|
||||
int MethodHandleRefKindInvokeSpecial = 7;
|
||||
int MethodHandleRefKindNewInvokeSpecial = 8;
|
||||
int MethodHandleRefKindInvokeInterface = 9;
|
||||
|
||||
int MAJOR_VERSION_1_1 = 45;
|
||||
int MAJOR_VERSION_1_2 = 46;
|
||||
int MAJOR_VERSION_1_3 = 47;
|
||||
int MAJOR_VERSION_1_4 = 48;
|
||||
int MAJOR_VERSION_1_5 = 49;
|
||||
int MAJOR_VERSION_1_6 = 50;
|
||||
int MAJOR_VERSION_1_7 = 51;
|
||||
int MAJOR_VERSION_1_8 = 52;
|
||||
int MAJOR_VERSION_1_9 = 53; // This might change
|
||||
|
||||
int MINOR_VERSION_0 = 0;
|
||||
int MINOR_VERSION_1 = 1;
|
||||
int MINOR_VERSION_2 = 2;
|
||||
int MINOR_VERSION_3 = 3;
|
||||
int MINOR_VERSION_4 = 4;
|
||||
|
||||
// JDK 1.1 -> 1.9, comparable value allowing to check both major/minor version at once 1.4.1 > 1.4.0
|
||||
// 16 unsigned bits for major, then 16 bits for minor
|
||||
long JDK1_1 = ((long)ClassFileConstants.MAJOR_VERSION_1_1 << 16) + ClassFileConstants.MINOR_VERSION_3; // 1.1. is 45.3
|
||||
long JDK1_2 = ((long)ClassFileConstants.MAJOR_VERSION_1_2 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_3 = ((long)ClassFileConstants.MAJOR_VERSION_1_3 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_4 = ((long)ClassFileConstants.MAJOR_VERSION_1_4 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_5 = ((long)ClassFileConstants.MAJOR_VERSION_1_5 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_6 = ((long)ClassFileConstants.MAJOR_VERSION_1_6 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_7 = ((long)ClassFileConstants.MAJOR_VERSION_1_7 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_8 = ((long)ClassFileConstants.MAJOR_VERSION_1_8 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
long JDK1_9 = ((long)ClassFileConstants.MAJOR_VERSION_1_9 << 16) + ClassFileConstants.MINOR_VERSION_0;
|
||||
|
||||
/*
|
||||
* cldc1.1 is 45.3, but we modify it to be different from JDK1_1.
|
||||
* In the code gen, we will generate the same target value as JDK1_1
|
||||
*/
|
||||
long CLDC_1_1 = ((long)ClassFileConstants.MAJOR_VERSION_1_1 << 16) + ClassFileConstants.MINOR_VERSION_4;
|
||||
|
||||
// jdk level used to denote future releases: optional behavior is not enabled for now, but may become so. In order to enable these,
|
||||
// search for references to this constant, and change it to one of the official JDT constants above.
|
||||
long JDK_DEFERRED = Long.MAX_VALUE;
|
||||
|
||||
int INT_ARRAY = 10;
|
||||
int BYTE_ARRAY = 8;
|
||||
int BOOLEAN_ARRAY = 4;
|
||||
int SHORT_ARRAY = 9;
|
||||
int CHAR_ARRAY = 5;
|
||||
int LONG_ARRAY = 11;
|
||||
int FLOAT_ARRAY = 6;
|
||||
int DOUBLE_ARRAY = 7;
|
||||
|
||||
// Debug attributes
|
||||
int ATTR_SOURCE = 0x1; // SourceFileAttribute
|
||||
int ATTR_LINES = 0x2; // LineNumberAttribute
|
||||
int ATTR_VARS = 0x4; // LocalVariableTableAttribute
|
||||
int ATTR_STACK_MAP_TABLE = 0x8; // Stack map table attribute
|
||||
int ATTR_STACK_MAP = 0x10; // Stack map attribute: cldc
|
||||
int ATTR_TYPE_ANNOTATION = 0x20; // type annotation attribute (jsr 308)
|
||||
int ATTR_METHOD_PARAMETERS = 0x40; // method parameters attribute (jep 118)
|
||||
|
||||
// See java.lang.invoke.LambdaMetafactory constants - option bitflags when calling altMetaFactory()
|
||||
int FLAG_SERIALIZABLE = 0x01;
|
||||
int FLAG_MARKERS = 0x02;
|
||||
int FLAG_BRIDGES = 0x04;
|
||||
}
|
||||
@@ -0,0 +1,473 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2013 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* IBM Corporation - added constant AccDefault
|
||||
* IBM Corporation - added constants AccBridge and AccVarargs for J2SE 1.5
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
/**
|
||||
* Utility class for decoding modifier flags in Java elements.
|
||||
* <p>
|
||||
* This class provides static methods only.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that the numeric values of these flags match the ones for class files
|
||||
* as described in the Java Virtual Machine Specification (except for
|
||||
* {@link #AccDeprecated}, {@link #AccAnnotationDefault}, and {@link #AccDefaultMethod}).
|
||||
* </p>
|
||||
* <p>
|
||||
* The AST class <code>Modifier</code> provides
|
||||
* similar functionality as this class, only in the
|
||||
* <code>org.eclipse.jdt.core.dom</code> package.
|
||||
* </p>
|
||||
*
|
||||
* @see IMember#getFlags()
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public final class Flags {
|
||||
|
||||
/**
|
||||
* Constant representing the absence of any flag.
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int AccDefault = ClassFileConstants.AccDefault;
|
||||
/**
|
||||
* Public access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccPublic = ClassFileConstants.AccPublic;
|
||||
/**
|
||||
* Private access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccPrivate = ClassFileConstants.AccPrivate;
|
||||
/**
|
||||
* Protected access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccProtected = ClassFileConstants.AccProtected;
|
||||
/**
|
||||
* Static access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccStatic = ClassFileConstants.AccStatic;
|
||||
/**
|
||||
* Final access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccFinal = ClassFileConstants.AccFinal;
|
||||
/**
|
||||
* Synchronized access flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccSynchronized = ClassFileConstants.AccSynchronized;
|
||||
/**
|
||||
* Volatile property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccVolatile = ClassFileConstants.AccVolatile;
|
||||
/**
|
||||
* Transient property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccTransient = ClassFileConstants.AccTransient;
|
||||
/**
|
||||
* Native property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccNative = ClassFileConstants.AccNative;
|
||||
/**
|
||||
* Interface property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccInterface = ClassFileConstants.AccInterface;
|
||||
/**
|
||||
* Abstract property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccAbstract = ClassFileConstants.AccAbstract;
|
||||
/**
|
||||
* Strictfp property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccStrictfp = ClassFileConstants.AccStrictfp;
|
||||
/**
|
||||
* Super property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccSuper = ClassFileConstants.AccSuper;
|
||||
/**
|
||||
* Synthetic property flag. See The Java Virtual Machine Specification for more details.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final int AccSynthetic = ClassFileConstants.AccSynthetic;
|
||||
|
||||
// /**
|
||||
// * Deprecated property flag.
|
||||
// * <p>
|
||||
// * Note that this flag's value is internal and is not defined in the
|
||||
// * Virtual Machine specification.
|
||||
// * </p>
|
||||
// * @since 2.0
|
||||
// */
|
||||
// public static final int AccDeprecated = ClassFileConstants.AccDeprecated;
|
||||
|
||||
/**
|
||||
* Bridge method property flag (added in J2SE 1.5). Used to flag a compiler-generated
|
||||
* bridge methods.
|
||||
* See The Java Virtual Machine Specification for more details.
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int AccBridge = ClassFileConstants.AccBridge;
|
||||
|
||||
/**
|
||||
* Varargs method property flag (added in J2SE 1.5).
|
||||
* Used to flag variable arity method declarations.
|
||||
* See The Java Virtual Machine Specification for more details.
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int AccVarargs = ClassFileConstants.AccVarargs;
|
||||
|
||||
/**
|
||||
* Enum property flag (added in J2SE 1.5).
|
||||
* See The Java Virtual Machine Specification for more details.
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int AccEnum = ClassFileConstants.AccEnum;
|
||||
|
||||
/**
|
||||
* Annotation property flag (added in J2SE 1.5).
|
||||
* See The Java Virtual Machine Specification for more details.
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int AccAnnotation = ClassFileConstants.AccAnnotation;
|
||||
|
||||
// /**
|
||||
// * Default method property flag.
|
||||
// * <p>
|
||||
// * Note that this flag's value is internal and is not defined in the
|
||||
// * Virtual Machine specification.
|
||||
// * </p>
|
||||
// * @since 3.10
|
||||
// */
|
||||
// public static final int AccDefaultMethod = ExtraCompilerModifiers.AccDefaultMethod;
|
||||
//
|
||||
// /**
|
||||
// * Annotation method default property flag.
|
||||
// * Used to flag annotation type methods that declare a default value.
|
||||
// * <p>
|
||||
// * Note that this flag's value is internal and is not defined in the
|
||||
// * Virtual Machine specification.
|
||||
// * </p>
|
||||
// * @since 3.10
|
||||
// */
|
||||
// public static final int AccAnnotationDefault = ClassFileConstants.AccAnnotationDefault;
|
||||
|
||||
/**
|
||||
* Not instantiable.
|
||||
*/
|
||||
private Flags() {
|
||||
// Not instantiable
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>abstract</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>abstract</code> modifier is included
|
||||
*/
|
||||
public static boolean isAbstract(int flags) {
|
||||
return (flags & AccAbstract) != 0;
|
||||
}
|
||||
// /**
|
||||
// * Returns whether the given integer includes the indication that the
|
||||
// * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
|
||||
// *
|
||||
// * @param flags the flags
|
||||
// * @return <code>true</code> if the element is marked as deprecated
|
||||
// */
|
||||
// public static boolean isDeprecated(int flags) {
|
||||
// return (flags & AccDeprecated) != 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>final</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>final</code> modifier is included
|
||||
*/
|
||||
public static boolean isFinal(int flags) {
|
||||
return (flags & AccFinal) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>interface</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>interface</code> modifier is included
|
||||
* @since 2.0
|
||||
*/
|
||||
public static boolean isInterface(int flags) {
|
||||
return (flags & AccInterface) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>native</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>native</code> modifier is included
|
||||
*/
|
||||
public static boolean isNative(int flags) {
|
||||
return (flags & AccNative) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer does not include one of the
|
||||
* <code>public</code>, <code>private</code>, or <code>protected</code> flags.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if no visibility flag is set
|
||||
* @since 3.2
|
||||
*/
|
||||
public static boolean isPackageDefault(int flags) {
|
||||
return (flags & (AccPublic | AccPrivate | AccProtected)) == 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>private</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>private</code> modifier is included
|
||||
*/
|
||||
public static boolean isPrivate(int flags) {
|
||||
return (flags & AccPrivate) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>protected</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>protected</code> modifier is included
|
||||
*/
|
||||
public static boolean isProtected(int flags) {
|
||||
return (flags & AccProtected) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>public</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>public</code> modifier is included
|
||||
*/
|
||||
public static boolean isPublic(int flags) {
|
||||
return (flags & AccPublic) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>static</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>static</code> modifier is included
|
||||
*/
|
||||
public static boolean isStatic(int flags) {
|
||||
return (flags & AccStatic) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>super</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>super</code> modifier is included
|
||||
* @since 3.2
|
||||
*/
|
||||
public static boolean isSuper(int flags) {
|
||||
return (flags & AccSuper) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>strictfp</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>strictfp</code> modifier is included
|
||||
*/
|
||||
public static boolean isStrictfp(int flags) {
|
||||
return (flags & AccStrictfp) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>synchronized</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>synchronized</code> modifier is included
|
||||
*/
|
||||
public static boolean isSynchronized(int flags) {
|
||||
return (flags & AccSynchronized) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the indication that the
|
||||
* element is synthetic.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the element is marked synthetic
|
||||
*/
|
||||
public static boolean isSynthetic(int flags) {
|
||||
return (flags & AccSynthetic) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>transient</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>transient</code> modifier is included
|
||||
*/
|
||||
public static boolean isTransient(int flags) {
|
||||
return (flags & AccTransient) != 0;
|
||||
}
|
||||
/**
|
||||
* Returns whether the given integer includes the <code>volatile</code> modifier.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>volatile</code> modifier is included
|
||||
*/
|
||||
public static boolean isVolatile(int flags) {
|
||||
return (flags & AccVolatile) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given integer has the <code>AccBridge</code>
|
||||
* bit set.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>AccBridge</code> flag is included
|
||||
* @see #AccBridge
|
||||
* @since 3.0
|
||||
*/
|
||||
public static boolean isBridge(int flags) {
|
||||
return (flags & AccBridge) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given integer has the <code>AccVarargs</code>
|
||||
* bit set.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>AccVarargs</code> flag is included
|
||||
* @see #AccVarargs
|
||||
* @since 3.0
|
||||
*/
|
||||
public static boolean isVarargs(int flags) {
|
||||
return (flags & AccVarargs) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given integer has the <code>AccEnum</code>
|
||||
* bit set.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>AccEnum</code> flag is included
|
||||
* @see #AccEnum
|
||||
* @since 3.0
|
||||
*/
|
||||
public static boolean isEnum(int flags) {
|
||||
return (flags & AccEnum) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given integer has the <code>AccAnnotation</code>
|
||||
* bit set.
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return <code>true</code> if the <code>AccAnnotation</code> flag is included
|
||||
* @see #AccAnnotation
|
||||
* @since 3.0
|
||||
*/
|
||||
public static boolean isAnnotation(int flags) {
|
||||
return (flags & AccAnnotation) != 0;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns whether the given integer has the <code>AccDefaultMethod</code>
|
||||
// * bit set. Note that this flag represents the usage of the 'default' keyword
|
||||
// * on a method and should not be confused with the 'package' access visibility (which used to be called 'default access').
|
||||
// *
|
||||
// * @return <code>true</code> if the <code>AccDefaultMethod</code> flag is included
|
||||
// * @see #AccDefaultMethod
|
||||
// * @since 3.10
|
||||
// */
|
||||
// public static boolean isDefaultMethod(int flags) {
|
||||
// return (flags & AccDefaultMethod) != 0;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns whether the given integer has the <code>AccAnnnotationDefault</code>
|
||||
// * bit set.
|
||||
// *
|
||||
// * @return <code>true</code> if the <code>AccAnnotationDefault</code> flag is included
|
||||
// * @see #AccAnnotationDefault
|
||||
// * @since 3.10
|
||||
// */
|
||||
// public static boolean isAnnnotationDefault(int flags) {
|
||||
// return (flags & AccAnnotationDefault) != 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns a standard string describing the given modifier flags.
|
||||
* Only modifier flags are included in the output; deprecated,
|
||||
* synthetic, bridge, etc. flags are ignored.
|
||||
* <p>
|
||||
* The flags are output in the following order:
|
||||
* <pre> public protected private
|
||||
* abstract default static final synchronized native strictfp transient volatile</pre>
|
||||
* <p>
|
||||
* This order is consistent with the recommendations in JLS8 ("*Modifier:" rules in chapters 8 and 9).
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that the flags of a method can include the AccVarargs flag that has no standard description. Since the AccVarargs flag has the same value as
|
||||
* the AccTransient flag (valid for fields only), attempting to get the description of method modifiers with the AccVarargs flag set would result in an
|
||||
* unexpected description. Clients should ensure that the AccVarargs is not included in the flags of a method as follows:
|
||||
* <pre>
|
||||
* IMethod method = ...
|
||||
* int flags = method.getFlags() & ~Flags.AccVarargs;
|
||||
* return Flags.toString(flags);
|
||||
* </pre>
|
||||
* </p>
|
||||
* <p>
|
||||
* Examples results:
|
||||
* <pre>
|
||||
* <code>"public static final"</code>
|
||||
* <code>"private native"</code>
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param flags the flags
|
||||
* @return the standard string representation of the given flags
|
||||
*/
|
||||
public static String toString(int flags) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if (isPublic(flags))
|
||||
sb.append("public "); //$NON-NLS-1$
|
||||
if (isProtected(flags))
|
||||
sb.append("protected "); //$NON-NLS-1$
|
||||
if (isPrivate(flags))
|
||||
sb.append("private "); //$NON-NLS-1$
|
||||
if (isAbstract(flags))
|
||||
sb.append("abstract "); //$NON-NLS-1$
|
||||
// if (isDefaultMethod(flags))
|
||||
// sb.append("default "); //$NON-NLS-1$
|
||||
if (isStatic(flags))
|
||||
sb.append("static "); //$NON-NLS-1$
|
||||
if (isFinal(flags))
|
||||
sb.append("final "); //$NON-NLS-1$
|
||||
if (isSynchronized(flags))
|
||||
sb.append("synchronized "); //$NON-NLS-1$
|
||||
if (isNative(flags))
|
||||
sb.append("native "); //$NON-NLS-1$
|
||||
if (isStrictfp(flags))
|
||||
sb.append("strictfp "); //$NON-NLS-1$
|
||||
if (isTransient(flags))
|
||||
sb.append("transient "); //$NON-NLS-1$
|
||||
if (isVolatile(flags))
|
||||
sb.append("volatile "); //$NON-NLS-1$
|
||||
int len = sb.length();
|
||||
if (len == 0)
|
||||
return ""; //$NON-NLS-1$
|
||||
sb.setLength(len - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IAnnotatable extends IJavaElement {
|
||||
|
||||
Stream<IAnnotation> getAnnotations();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2013, 2016 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Pivotal Inc - copied and modified
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IAnnotation extends IJavaElement {
|
||||
|
||||
/**
|
||||
* Returns the member-value pairs of this annotation. Returns an empty
|
||||
* array if this annotation is a marker annotation. Returns a size-1 array if this
|
||||
* annotation is a single member annotation. In this case, the member
|
||||
* name is always <code>"value"</code>.
|
||||
*
|
||||
* @return the member-value pairs of this annotation
|
||||
*/
|
||||
Stream<IMemberValuePair> getMemberValuePairs();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IArrayType extends IJavaType {
|
||||
|
||||
int dimensions();
|
||||
|
||||
IJavaType component();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IClassType extends IJavaType {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
/**
|
||||
* Classpath for a Java artifact
|
||||
*
|
||||
* @author Kris De Volder
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public interface IClasspath {
|
||||
|
||||
String getName();
|
||||
|
||||
boolean exists();
|
||||
|
||||
IType findType(String fqName);
|
||||
|
||||
Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter);
|
||||
|
||||
Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm);
|
||||
|
||||
Flux<IType> allSubtypesOf(IType type);
|
||||
|
||||
Path getOutputFolder();
|
||||
|
||||
/**
|
||||
* Classpath entries paths
|
||||
*
|
||||
* @return collection of classpath entries in a form file/folder paths
|
||||
* @throws Exception
|
||||
*/
|
||||
Stream<Path> getClasspathEntries() throws Exception;
|
||||
|
||||
/**
|
||||
* Classpath resources paths relative to the source folder path
|
||||
* @return classpath resource relative paths
|
||||
*/
|
||||
Stream<String> getClasspathResources();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IField extends IMember {
|
||||
boolean isEnumConstant();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavaElement {
|
||||
String getElementName();
|
||||
IJavadoc getJavaDoc();
|
||||
boolean exists();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavaProject extends IJavaElement {
|
||||
|
||||
IClasspath getClasspath();
|
||||
|
||||
@Override
|
||||
default String getElementName() {
|
||||
return getClasspath().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default IJavadoc getJavaDoc() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean exists() {
|
||||
return getClasspath().exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IJavaType {
|
||||
|
||||
String name();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavadocProvider {
|
||||
|
||||
IJavadoc getJavadoc(IType type);
|
||||
|
||||
IJavadoc getJavadoc(IField field);
|
||||
|
||||
IJavadoc getJavadoc(IMethod method);
|
||||
|
||||
IJavadoc getJavadoc(IAnnotation annotation);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2013, 2016 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Pivotal Inc - Copied and modified
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IMember extends IJavaElement, IAnnotatable {
|
||||
|
||||
/**
|
||||
* Returns the modifier flags for this member. The flags can be examined using class
|
||||
* <code>Flags</code>.
|
||||
* <p>
|
||||
* For {@linkplain #isBinary() binary} members, flags from the class file
|
||||
* as well as derived flags {@link Flags#AccAnnotationDefault} and {@link Flags#AccDefaultMethod} are included.
|
||||
* </p>
|
||||
* <p>
|
||||
* For source members, only flags as indicated in the source are returned. Thus if an interface
|
||||
* defines a method <code>void myMethod();</code>, the flags don't include the
|
||||
* 'public' flag. Source flags include {@link Flags#AccAnnotationDefault} as well.
|
||||
* </p>
|
||||
*
|
||||
* @exception JavaModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its corresponding resource.
|
||||
* @return the modifier flags for this member
|
||||
* @see Flags
|
||||
*/
|
||||
int getFlags();
|
||||
|
||||
/**
|
||||
* Returns the type in which this member is declared, or <code>null</code>
|
||||
* if this member is not declared in a type (for example, a top-level type).
|
||||
* This is a handle-only method.
|
||||
*
|
||||
* @return the type in which this member is declared, or <code>null</code>
|
||||
* if this member is not declared in a type (for example, a top-level type)
|
||||
*/
|
||||
IType getDeclaringType();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2009, 2016 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Pivotal Inc - Copied and modified.
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IMemberValuePair {
|
||||
|
||||
/**
|
||||
* Returns the member's name of this member-value pair.
|
||||
*
|
||||
* @return the member's name of this member-value pair.
|
||||
*/
|
||||
String getMemberName();
|
||||
|
||||
/**
|
||||
* Returns the value of this member-value pair. The type of this value
|
||||
* is function of this member-value pair's {@link #getValueKind() value kind}. It is an
|
||||
* instance of {@link Object}[] if the value is an array.
|
||||
* <p>
|
||||
* If the value kind is {@link #K_UNKNOWN} and the value is not an array, then the
|
||||
* value is <code>null</code>.
|
||||
* If the value kind is {@link #K_UNKNOWN} and the value is an array, then the
|
||||
* value is an array containing {@link Object}s and/or <code>null</code>s for
|
||||
* unknown elements.
|
||||
* See {@link #K_UNKNOWN} for more details.
|
||||
* </p>
|
||||
* @return the value of this member-value pair.
|
||||
*/
|
||||
Object getValue();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2014, 2016 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* IBM Corporation - added J2SE 1.5 support
|
||||
* Pivotal Inc - Copied and modified
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IMethod extends IMember {
|
||||
|
||||
/**
|
||||
* Returns the type signature of the return value of this method.
|
||||
* For constructors, this returns the signature for void.
|
||||
* <p>
|
||||
* For example, a source method declared as <code>public String getName()</code>
|
||||
* would return <code>"QString;"</code>.
|
||||
* </p>
|
||||
* <p>
|
||||
* The type signature may be either unresolved (for source types)
|
||||
* or resolved (for binary types), and either basic (for basic types)
|
||||
* or rich (for parameterized types). See {@link Signature} for details.
|
||||
* </p>
|
||||
*
|
||||
* @exception JavaModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its corresponding resource.
|
||||
* @return the type signature of the return value of this method, void for constructors
|
||||
* @see Signature
|
||||
*/
|
||||
IJavaType getReturnType();
|
||||
|
||||
// /**
|
||||
// * Returns the signature of this method. This includes the signatures for the
|
||||
// * parameter types and return type, but does not include the method name,
|
||||
// * exception types, or type parameters.
|
||||
// * <p>
|
||||
// * For example, a source method declared as <code>public void foo(String text, int length)</code>
|
||||
// * would return <code>"(QString;I)V"</code>.
|
||||
// * </p>
|
||||
// * <p>
|
||||
// * The type signatures embedded in the method signature may be either unresolved
|
||||
// * (for source types) or resolved (for binary types), and either basic (for
|
||||
// * basic types) or rich (for parameterized types). See {@link Signature} for
|
||||
// * details.
|
||||
// * </p>
|
||||
// *
|
||||
// * @return the signature of this method
|
||||
// * @exception JavaModelException if this element does not exist or if an
|
||||
// * exception occurs while accessing its corresponding resource.
|
||||
// * @see Signature
|
||||
// */
|
||||
// String getSignature();
|
||||
|
||||
/**
|
||||
* Returns parameter types of this method
|
||||
* @return
|
||||
*/
|
||||
Stream<IJavaType> parameters();
|
||||
|
||||
boolean isConstructor();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IParameterizedType extends IJavaType {
|
||||
|
||||
IJavaType owner();
|
||||
|
||||
Stream<IJavaType> arguments();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IPrimitiveType extends IJavaType {
|
||||
|
||||
static IPrimitiveType INT = () -> "I";
|
||||
|
||||
static IPrimitiveType BOOLEAN = () -> "Z";
|
||||
|
||||
static IPrimitiveType CHAR = () -> "C";
|
||||
|
||||
static IPrimitiveType FLOAT = () -> "F";
|
||||
|
||||
static IPrimitiveType BYTE = () -> "B";
|
||||
|
||||
static IPrimitiveType DOUBLE = () -> "D";
|
||||
|
||||
static IPrimitiveType LONG = () -> "J";
|
||||
|
||||
static IPrimitiveType SHORT = () -> "S";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* IBM Corporation - added J2SE 1.5 support
|
||||
* Stephan Herrmann - Contribution for
|
||||
* Bug 463533 - Signature.getSignatureSimpleName() returns different results for resolved and unresolved extends
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Replaces eclipse JDT IType.
|
||||
*/
|
||||
public interface IType extends IMember {
|
||||
|
||||
boolean isClass();
|
||||
boolean isEnum();
|
||||
boolean isInterface();
|
||||
boolean isAnnotation();
|
||||
|
||||
/**
|
||||
* Returns the fully qualified name of this type,
|
||||
* including qualification for any containing types and packages.
|
||||
* This is the name of the package, followed by <code>'.'</code>,
|
||||
* followed by the type-qualified name.
|
||||
* <p>
|
||||
* <b>Note</b>: The enclosing type separator used in the type-qualified
|
||||
* name is <code>'$'</code>, not <code>'.'</code>.
|
||||
* </p>
|
||||
* This method is fully equivalent to <code>getFullyQualifiedName('$')</code>.
|
||||
* This is a handle-only method.
|
||||
*
|
||||
* @see IType#getTypeQualifiedName()
|
||||
* @see IType#getFullyQualifiedName(char)
|
||||
* @return the fully qualified name of this type
|
||||
*/
|
||||
String getFullyQualifiedName();
|
||||
|
||||
/**
|
||||
* Returns the field with the specified name
|
||||
* in this type (for example, <code>"bar"</code>).
|
||||
* This is a handle-only method. The field may or may not exist.
|
||||
*
|
||||
* @param name the given name
|
||||
* @return the field with the specified name in this type
|
||||
*/
|
||||
IField getField(String name);
|
||||
|
||||
/**
|
||||
* Returns the fields declared by this type in the order in which they appear
|
||||
* in the source or class file. For binary types, this includes synthetic fields.
|
||||
*
|
||||
* @return the fields declared by this type
|
||||
*/
|
||||
Stream<IField> getFields();
|
||||
|
||||
/**
|
||||
* Returns the method with the specified name and parameter types
|
||||
* in this type (for example, <code>"foo", {"I", "QString;"}</code>).
|
||||
* To get the handle for a constructor, the name specified must be the
|
||||
* simple name of the enclosing type.
|
||||
* This is a handle-only method. The method may or may not be present.
|
||||
* <p>
|
||||
* The type signatures may be either unresolved (for source types)
|
||||
* or resolved (for binary types), and either basic (for basic types)
|
||||
* or rich (for parameterized types). See {@link Signature} for details.
|
||||
* Note that the parameter type signatures for binary methods are expected
|
||||
* to be dot-based.
|
||||
* </p>
|
||||
*
|
||||
* @param name the given name
|
||||
* @param parameterTypeSignatures the given parameter types
|
||||
* @return the method with the specified name and parameter types in this type
|
||||
*/
|
||||
IMethod getMethod(String name, Stream<IJavaType> parameters);
|
||||
|
||||
/**
|
||||
* Returns the methods and constructors declared by this type.
|
||||
* For binary types, this may include the special <code><clinit></code> method
|
||||
* and synthetic methods.
|
||||
* <p>
|
||||
* The results are listed in the order in which they appear in the source or class file.
|
||||
* </p>
|
||||
*
|
||||
* @return the methods and constructors declared by this type
|
||||
*/
|
||||
Stream<IMethod> getMethods();
|
||||
|
||||
// /**
|
||||
// * Resolves the given type name within the context of this type (depending on the type hierarchy
|
||||
// * and its imports).
|
||||
// * <p>
|
||||
// * Multiple answers might be found in case there are ambiguous matches.
|
||||
// * </p>
|
||||
// * <p>
|
||||
// * Each matching type name is decomposed as an array of two strings, the first denoting the package
|
||||
// * name (dot-separated) and the second being the type name. The package name is empty if it is the
|
||||
// * default package. The type name is the type qualified name using a '.' enclosing type separator.
|
||||
// * </p>
|
||||
// * <p>
|
||||
// * Returns <code>null</code> if unable to find any matching type.
|
||||
// * </p>
|
||||
// *<p>
|
||||
// * For example, resolution of <code>"Object"</code> would typically return
|
||||
// * <code>{{"java.lang", "Object"}}</code>. Another resolution that returns
|
||||
// * <code>{{"", "X.Inner"}}</code> represents the inner type Inner defined in type X in the
|
||||
// * default package.
|
||||
// * </p>
|
||||
// *
|
||||
// * @param typeName the given type name
|
||||
// * @return the resolved type names or <code>null</code> if unable to find any matching type
|
||||
// * @see #getTypeQualifiedName(char)
|
||||
// */
|
||||
// String[][] resolveType(String typeName);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface ITypeVariable extends IJavaType {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IUnresolvedTypeVariable extends IJavaType {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IVoidType extends IJavaType {
|
||||
|
||||
static IVoidType DEFAULT = new IVoidType() {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "V";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public interface IWildcardType extends IJavaType {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2011, 2016 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* IBM Corporation - added J2SE 1.5 support
|
||||
* Pivotal Inc. - copied and modified
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
public class Signature {
|
||||
|
||||
//These are the bits of JDTs 'Signature' class. Only we copied the method decls
|
||||
// of stuff we actually use
|
||||
|
||||
//TODO: For performamce reason, JDT probably works with String or even naked char[] instead
|
||||
// of wrapping these in a proper 'TypeSignature' or 'MethodSignature' object. But probably we should
|
||||
// do the proper wrapping and abstract out a interface for these types. A 'client'
|
||||
// using 'Java knowledge' should not have to directly be dealing with the JVM method and
|
||||
// type signature strings.
|
||||
|
||||
/**
|
||||
* Kind constant for a class type signature.
|
||||
* @see #getTypeSignatureKind(String)
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int CLASS_TYPE_SIGNATURE = 1;
|
||||
|
||||
/**
|
||||
* Kind constant for an array type signature.
|
||||
* @see #getTypeSignatureKind(String)
|
||||
* @since 3.0
|
||||
*/
|
||||
public static final int ARRAY_TYPE_SIGNATURE = 4;
|
||||
|
||||
/**
|
||||
* Character constant indicating the start of an unresolved, named type in a
|
||||
* signature. Value is <code>'Q'</code>.
|
||||
*/
|
||||
public static final char C_UNRESOLVED = 'Q';
|
||||
//TODO: unless we use JDT to work with suource-types we probably don't see these?
|
||||
|
||||
/**
|
||||
* Returns the kind of type signature encoded by the given string.
|
||||
*
|
||||
* @param typeSignature the type signature string
|
||||
* @return the kind of type signature; one of the kind constants:
|
||||
* {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
|
||||
* {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE},
|
||||
* or (since 3.1) {@link #WILDCARD_TYPE_SIGNATURE} or {@link #CAPTURE_TYPE_SIGNATURE}
|
||||
* or (since 3.7) {@link #INTERSECTION_TYPE_SIGNATURE}
|
||||
* @exception IllegalArgumentException if this is not a type signature
|
||||
* @since 3.0
|
||||
*/
|
||||
public static int getTypeSignatureKind(String typeSignature) {
|
||||
return getTypeSignatureKind(typeSignature.toCharArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of type signature encoded by the given string.
|
||||
*
|
||||
* @param typeSignature the type signature string
|
||||
* @return the kind of type signature; one of the kind constants:
|
||||
* {@link #ARRAY_TYPE_SIGNATURE}, {@link #CLASS_TYPE_SIGNATURE},
|
||||
* {@link #BASE_TYPE_SIGNATURE}, or {@link #TYPE_VARIABLE_SIGNATURE},
|
||||
* or (since 3.1) {@link #WILDCARD_TYPE_SIGNATURE} or {@link #CAPTURE_TYPE_SIGNATURE},
|
||||
* or (since 3.7) {@link #INTERSECTION_TYPE_SIGNATURE}
|
||||
* @exception IllegalArgumentException if this is not a type signature
|
||||
* @since 3.0
|
||||
*/
|
||||
public static int getTypeSignatureKind(char[] typeSignature) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the type erasure signature from the given parameterized type signature.
|
||||
* Returns the given type signature if it is not parameterized.
|
||||
*
|
||||
* @param parameterizedTypeSignature the parameterized type signature
|
||||
* @return the signature of the type erasure
|
||||
* @exception IllegalArgumentException if the signature is syntactically
|
||||
* incorrect
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public static String getTypeErasure(String parameterizedTypeSignature) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns package fragment of a type signature. The package fragment separator must be '.'
|
||||
* and the type fragment separator must be '$'.
|
||||
* <p>
|
||||
* For example:
|
||||
* <pre>
|
||||
* <code>
|
||||
* getSignatureQualifier("Ljava.util.Map$Entry") -> "java.util"
|
||||
* </code>
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param typeSignature the type signature
|
||||
* @return the package fragment (separators are '.')
|
||||
* @since 3.1
|
||||
*/
|
||||
public static String getSignatureQualifier(String typeSignature) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns type fragment of a type signature. The package fragment separator must be '.'
|
||||
* and the type fragment separator must be '$'.
|
||||
* <p>
|
||||
* For example:
|
||||
* <pre>
|
||||
* <code>
|
||||
* getSignatureSimpleName("Ljava.util.Map$Entry") -> "Map.Entry"
|
||||
* </code>
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param typeSignature the type signature
|
||||
* @return the type fragment (separators are '.')
|
||||
* @since 3.1
|
||||
*/
|
||||
public static String getSignatureSimpleName(String typeSignature) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the type parameter signatures from the given method or type signature.
|
||||
* The method or type signature is expected to be dot-based.
|
||||
*
|
||||
* @param methodOrTypeSignature the method or type signature
|
||||
* @return the list of type parameter signatures
|
||||
* @exception IllegalArgumentException if the signature is syntactically
|
||||
* incorrect
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public static String[] getTypeParameters(String methodOrTypeSignature) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the type argument signatures from the given type signature.
|
||||
* Returns an empty array if the type signature is not a parameterized type signature.
|
||||
*
|
||||
* @param parameterizedTypeSignature the parameterized type signature
|
||||
* @return the signatures of the type arguments
|
||||
* @exception IllegalArgumentException if the signature is syntactically incorrect
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public static String[] getTypeArguments(String parameterizedTypeSignature) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type signature without any array nesting.
|
||||
* <p>
|
||||
* For example:
|
||||
* <pre>
|
||||
* <code>
|
||||
* getElementType("[[I") --> "I".
|
||||
* </code>
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param typeSignature the type signature
|
||||
* @return the type signature without arrays
|
||||
* @exception IllegalArgumentException if the signature is not syntactically
|
||||
* correct
|
||||
*/
|
||||
public static String getElementType(String typeSignature) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array count (array nesting depth) of the given type signature.
|
||||
*
|
||||
* @param typeSignature the type signature
|
||||
* @return the array nesting depth, or 0 if not an array
|
||||
* @exception IllegalArgumentException if the signature is not syntactically
|
||||
* correct
|
||||
*/
|
||||
public static int getArrayCount(String typeSignature) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of parameter types in the given method signature.
|
||||
*
|
||||
* @param methodSignature the method signature
|
||||
* @return the number of parameters
|
||||
* @exception IllegalArgumentException if the signature is not syntactically
|
||||
* correct
|
||||
*/
|
||||
public static int getParameterCount(String methodSignature) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java.parser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseException;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
public interface CompilationUnitIndex {
|
||||
|
||||
static final CompilationUnitIndex DEFAULT = new CompilationUnitIndex() {
|
||||
|
||||
private LoadingCache<URL, CompilationUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, CompilationUnit>() {
|
||||
|
||||
@Override
|
||||
public CompilationUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return JavaParser.parse(in);
|
||||
} catch (ParseException e) {
|
||||
in.close();
|
||||
Log.log("Failed to parse java source file: " + url, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public CompilationUnit getCompilationUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CompilationUnit getCompilationUnit(URL url);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java.parser;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.javadoc.RawJavadoc;
|
||||
import org.springframework.ide.vscode.commons.javadoc.SourceUrlProvider;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumConstantDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumDeclaration;
|
||||
import com.github.javaparser.ast.body.FieldDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.VariableDeclarator;
|
||||
import com.github.javaparser.ast.visitor.GenericVisitorAdapter;
|
||||
|
||||
public class ParserJavadocProvider implements IJavadocProvider {
|
||||
|
||||
private SourceUrlProvider sourceUrlProvider;
|
||||
|
||||
public ParserJavadocProvider(SourceUrlProvider sourceUrlProvider) {
|
||||
this.sourceUrlProvider = sourceUrlProvider;
|
||||
}
|
||||
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
if (type.isEnum()) {
|
||||
EnumDeclaration declaration = getEnumDeclaration(type);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
ClassOrInterfaceDeclaration declaration = getClassOrInterfaceDeclaration(type);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
IType declaringType = field.getDeclaringType();
|
||||
if (declaringType.isEnum()) {
|
||||
EnumConstantDeclaration declaration = createVisitorToFindEnumConstant(field).visit(getEnumDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
FieldDeclaration declaration = createVisitorToFindField(field).visit(getClassOrInterfaceDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
if (method.parameters().findFirst().isPresent()) {
|
||||
throw new UnsupportedOperationException("Only methods with no parameters are supported");
|
||||
}
|
||||
IType declaringType = method.getDeclaringType();
|
||||
if (declaringType.isEnum()) {
|
||||
MethodDeclaration declaration = createVisitorToFindMethod(method).visit(getEnumDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
MethodDeclaration declaration = createVisitorToFindMethod(method).visit(getClassOrInterfaceDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public IJavadoc getJavadoc(IAnnotation annotation) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
private CompilationUnit getCompilationUnit(IType type) {
|
||||
try {
|
||||
URL sourceUrl = sourceUrlProvider.sourceUrl(type);
|
||||
return CompilationUnitIndex.DEFAULT.getCompilationUnit(sourceUrl);
|
||||
} catch (Exception e) {
|
||||
Log.log("Invalid source URL for type " + type, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private EnumDeclaration getEnumDeclaration(IType type) {
|
||||
IType parent = type.getDeclaringType();
|
||||
if (parent == null) {
|
||||
CompilationUnit cu = getCompilationUnit(type);
|
||||
return createVisitorToFindEnum(type).visit(cu, null);
|
||||
} else {
|
||||
if (parent.isEnum()) {
|
||||
EnumDeclaration declaration = getEnumDeclaration(parent);
|
||||
return createVisitorToFindEnum(type).visit(declaration, null);
|
||||
} else {
|
||||
ClassOrInterfaceDeclaration declaration = getClassOrInterfaceDeclaration(parent);
|
||||
return createVisitorToFindEnum(type).visit(declaration, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ClassOrInterfaceDeclaration getClassOrInterfaceDeclaration(IType type) {
|
||||
IType parent = type.getDeclaringType();
|
||||
if (parent == null) {
|
||||
CompilationUnit cu = getCompilationUnit(type);
|
||||
return createVisitorToFindClassOrInterface(type).visit(cu, null);
|
||||
} else {
|
||||
if (parent.isEnum()) {
|
||||
EnumDeclaration declaration = getEnumDeclaration(parent);
|
||||
return createVisitorToFindClassOrInterface(type).visit(declaration, null);
|
||||
} else {
|
||||
ClassOrInterfaceDeclaration declaration = getClassOrInterfaceDeclaration(parent);
|
||||
return createVisitorToFindClassOrInterface(type).visit(declaration, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GenericVisitorAdapter<ClassOrInterfaceDeclaration, Object> createVisitorToFindClassOrInterface(IType type) {
|
||||
return new GenericVisitorAdapter<ClassOrInterfaceDeclaration, Object>() {
|
||||
|
||||
@Override
|
||||
public ClassOrInterfaceDeclaration visit(ClassOrInterfaceDeclaration n, Object arg) {
|
||||
if (n.getName().equals(type.getElementName())) {
|
||||
return n;
|
||||
} else {
|
||||
return super.visit(n, arg);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private GenericVisitorAdapter<EnumDeclaration, Object> createVisitorToFindEnum(IType type) {
|
||||
return new GenericVisitorAdapter<EnumDeclaration, Object>() {
|
||||
|
||||
@Override
|
||||
public EnumDeclaration visit(EnumDeclaration n, Object arg) {
|
||||
if (n.getName().equals(type.getElementName())) {
|
||||
return n;
|
||||
} else {
|
||||
return super.visit(n, arg);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private GenericVisitorAdapter<MethodDeclaration, Object> createVisitorToFindMethod(IMethod method) {
|
||||
return new GenericVisitorAdapter<MethodDeclaration, Object>() {
|
||||
@Override
|
||||
public MethodDeclaration visit(MethodDeclaration n, Object arg) {
|
||||
if (n.getParameters().isEmpty() && n.getName().equals(method.getElementName())) {
|
||||
return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private GenericVisitorAdapter<FieldDeclaration, Object> createVisitorToFindField(IField field) {
|
||||
return new GenericVisitorAdapter<FieldDeclaration, Object>() {
|
||||
@Override
|
||||
public FieldDeclaration visit(FieldDeclaration n, Object arg) {
|
||||
Optional<VariableDeclarator> variable = n.getVariables().stream().filter(v -> v.getId().getName().equals(field.getElementName())).findFirst();
|
||||
return variable.isPresent() ? n : null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private GenericVisitorAdapter<EnumConstantDeclaration, Object> createVisitorToFindEnumConstant(IField field) {
|
||||
return new GenericVisitorAdapter<EnumConstantDeclaration, Object>() {
|
||||
@Override
|
||||
public EnumConstantDeclaration visit(EnumConstantDeclaration n, Object arg) {
|
||||
if (n.getName().equals(field.getElementName())) {
|
||||
return n;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
|
||||
public class HtmlJavadoc implements IJavadoc {
|
||||
|
||||
private String html;
|
||||
|
||||
public HtmlJavadoc(String html) {
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
return Renderables.htmlBlob(html);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
|
||||
public interface HtmlJavadocIndex {
|
||||
|
||||
static JavadocContents NO_HTML_CONTENT = new JavadocContents(null);
|
||||
|
||||
public static final HtmlJavadocIndex DEFAULT = new HtmlJavadocIndex() {
|
||||
|
||||
private Cache<URL, JavadocContents> cache = CacheBuilder.newBuilder().build();
|
||||
|
||||
|
||||
@Override
|
||||
public JavadocContents getHtmlJavadoc(URL url) {
|
||||
try {
|
||||
JavadocContents content = cache.get(url, () -> {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = url.openStream();
|
||||
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
|
||||
return new JavadocContents(buffer.lines().collect(Collectors.joining("\n")));
|
||||
} catch (IOException e) {
|
||||
Log.log("Cannot load javadoc content from " + url, e);
|
||||
return NO_HTML_CONTENT;
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
return content == NO_HTML_CONTENT ? null : content;
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
JavadocContents getHtmlJavadoc(URL url);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
public class HtmlJavadocProvider implements IJavadocProvider {
|
||||
|
||||
private SourceUrlProvider htmlUrlProvider;
|
||||
|
||||
public HtmlJavadocProvider(SourceUrlProvider htmlUrlProvider) {
|
||||
this.htmlUrlProvider = htmlUrlProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
try {
|
||||
JavadocContents javadocContents = findHtml(type);
|
||||
String html = javadocContents == null ? null : javadocContents.getTypeDoc(type);
|
||||
return html == null ? null : new HtmlJavadoc(html);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
try {
|
||||
IType declaringType = field.getDeclaringType();
|
||||
JavadocContents javadocContents = findHtml(declaringType);
|
||||
String html = javadocContents == null ? null : javadocContents.getFieldDoc(field);
|
||||
return html == null ? null : new HtmlJavadoc(html);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
try {
|
||||
IType declaringType = method.getDeclaringType();
|
||||
JavadocContents javadocContents = findHtml(declaringType);
|
||||
String html = javadocContents == null ? null : javadocContents.getMethodDoc(method);
|
||||
return html == null ? null : new HtmlJavadoc(html);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IAnnotation annotation) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
private JavadocContents findHtml(IType type) throws Exception {
|
||||
URL url = htmlUrlProvider.sourceUrl(type);
|
||||
return HtmlJavadocIndex.DEFAULT.getHtmlJavadoc(url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
public interface IJavadoc {
|
||||
|
||||
String raw();
|
||||
|
||||
Renderable getRenderable();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
public class RawJavadoc implements IJavadoc {
|
||||
|
||||
private String rawContent;
|
||||
|
||||
public RawJavadoc(String rawContent) {
|
||||
this.rawContent = rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SourceUrlProvider {
|
||||
|
||||
URL sourceUrl(IType type) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SourceUrlProviderFromSourceContainer {
|
||||
|
||||
public static final SourceUrlProviderFromSourceContainer JAR_SOURCE_URL_PROVIDER = (sourceContainerUrl, type) -> {
|
||||
StringBuilder sourceUrlStr = new StringBuilder();
|
||||
sourceUrlStr.append("jar:");
|
||||
sourceUrlStr.append(sourceContainerUrl);
|
||||
sourceUrlStr.append("!");
|
||||
sourceUrlStr.append('/');
|
||||
sourceUrlStr.append(type.getFullyQualifiedName().replaceAll("\\.", "/"));
|
||||
sourceUrlStr.append(".java");
|
||||
return new URL(sourceUrlStr.toString());
|
||||
|
||||
};
|
||||
|
||||
public static final SourceUrlProviderFromSourceContainer SOURCE_FOLDER_URL_SUPPLIER = (sourceContainerUrl, type) -> {
|
||||
return Paths.get(sourceContainerUrl.toURI()).resolve(type.getFullyQualifiedName().replaceAll("\\.", "/") + ".java").toUri().toURL();
|
||||
};
|
||||
|
||||
public static final SourceUrlProviderFromSourceContainer JAR_JAVADOC_URL_PROVIDER = (javadocContainerUrl, type) -> {
|
||||
StringBuilder sourceUrlStr = new StringBuilder();
|
||||
sourceUrlStr.append("jar:");
|
||||
sourceUrlStr.append(javadocContainerUrl);
|
||||
sourceUrlStr.append("!");
|
||||
sourceUrlStr.append('/');
|
||||
// Inner classes are in separate Top.Nesting1.Nesting2.Nesting3.MyType.html files
|
||||
sourceUrlStr.append(type.getFullyQualifiedName().replaceAll("\\.", "/").replaceAll("\\$", "."));
|
||||
sourceUrlStr.append(".html");
|
||||
return new URL(sourceUrlStr.toString());
|
||||
|
||||
};
|
||||
|
||||
public static final SourceUrlProviderFromSourceContainer JAVADOC_FOLDER_URL_SUPPLIER = (sourceContainerUrl, type) -> {
|
||||
String urlStr = sourceContainerUrl.toString();
|
||||
StringBuilder sb = new StringBuilder(urlStr);
|
||||
if (!urlStr.endsWith("/")) {
|
||||
sb.append('/');
|
||||
}
|
||||
// Inner classes are in separate Top.Nesting1.Nesting2.Nesting3.MyType.html files
|
||||
sb.append(type.getFullyQualifiedName().replaceAll("\\.", "/").replaceAll("\\$", ".") + ".html");
|
||||
return new URL(sb.toString());
|
||||
};
|
||||
|
||||
URL sourceUrl(URL sourceContainerUrl, IType type) throws Exception;
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,169 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc.internal;
|
||||
|
||||
/**
|
||||
* Hashtable of {Object --> int[] }
|
||||
*/
|
||||
public final class HashtableOfObjectToIntArray implements Cloneable {
|
||||
|
||||
// to avoid using Enumerations, walk the individual tables skipping nulls
|
||||
public Object[] keyTable;
|
||||
public int[][] valueTable;
|
||||
|
||||
public int elementSize; // number of elements in the table
|
||||
int threshold;
|
||||
|
||||
public HashtableOfObjectToIntArray() {
|
||||
this(13);
|
||||
}
|
||||
|
||||
public HashtableOfObjectToIntArray(int size) {
|
||||
|
||||
this.elementSize = 0;
|
||||
this.threshold = size; // size represents the expected number of elements
|
||||
int extraRoom = (int) (size * 1.75f);
|
||||
if (this.threshold == extraRoom)
|
||||
extraRoom++;
|
||||
this.keyTable = new Object[extraRoom];
|
||||
this.valueTable = new int[extraRoom][];
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
HashtableOfObjectToIntArray result = (HashtableOfObjectToIntArray) super.clone();
|
||||
result.elementSize = this.elementSize;
|
||||
result.threshold = this.threshold;
|
||||
|
||||
int length = this.keyTable.length;
|
||||
result.keyTable = new Object[length];
|
||||
System.arraycopy(this.keyTable, 0, result.keyTable, 0, length);
|
||||
|
||||
length = this.valueTable.length;
|
||||
result.valueTable = new int[length][];
|
||||
System.arraycopy(this.valueTable, 0, result.valueTable, 0, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
int length = this.keyTable.length,
|
||||
index = (key.hashCode()& 0x7FFFFFFF) % length;
|
||||
Object currentKey;
|
||||
while ((currentKey = this.keyTable[index]) != null) {
|
||||
if (currentKey.equals(key))
|
||||
return true;
|
||||
if (++index == length) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int[] get(Object key) {
|
||||
int length = this.keyTable.length,
|
||||
index = (key.hashCode()& 0x7FFFFFFF) % length;
|
||||
Object currentKey;
|
||||
while ((currentKey = this.keyTable[index]) != null) {
|
||||
if (currentKey.equals(key))
|
||||
return this.valueTable[index];
|
||||
if (++index == length) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void keysToArray(Object[] array) {
|
||||
int index = 0;
|
||||
for (int i=0, length=this.keyTable.length; i<length; i++) {
|
||||
if (this.keyTable[i] != null)
|
||||
array[index++] = this.keyTable[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int[] put(Object key, int[] value) {
|
||||
int length = this.keyTable.length,
|
||||
index = (key.hashCode()& 0x7FFFFFFF) % length;
|
||||
Object currentKey;
|
||||
while ((currentKey = this.keyTable[index]) != null) {
|
||||
if (currentKey.equals(key))
|
||||
return this.valueTable[index] = value;
|
||||
if (++index == length) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
this.keyTable[index] = key;
|
||||
this.valueTable[index] = value;
|
||||
|
||||
// assumes the threshold is never equal to the size of the table
|
||||
if (++this.elementSize > this.threshold)
|
||||
rehash();
|
||||
return value;
|
||||
}
|
||||
|
||||
public int[] removeKey(Object key) {
|
||||
int length = this.keyTable.length,
|
||||
index = (key.hashCode()& 0x7FFFFFFF) % length;
|
||||
Object currentKey;
|
||||
while ((currentKey = this.keyTable[index]) != null) {
|
||||
if (currentKey.equals(key)) {
|
||||
int[] value = this.valueTable[index];
|
||||
this.elementSize--;
|
||||
this.keyTable[index] = null;
|
||||
rehash();
|
||||
return value;
|
||||
}
|
||||
if (++index == length) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void rehash() {
|
||||
|
||||
HashtableOfObjectToIntArray newHashtable = new HashtableOfObjectToIntArray(this.elementSize * 2); // double the number of expected elements
|
||||
Object currentKey;
|
||||
for (int i = this.keyTable.length; --i >= 0;)
|
||||
if ((currentKey = this.keyTable[i]) != null)
|
||||
newHashtable.put(currentKey, this.valueTable[i]);
|
||||
|
||||
this.keyTable = newHashtable.keyTable;
|
||||
this.valueTable = newHashtable.valueTable;
|
||||
this.threshold = newHashtable.threshold;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.elementSize;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Object key;
|
||||
for (int i = 0, length = this.keyTable.length; i < length; i++) {
|
||||
if ((key = this.keyTable[i]) != null) {
|
||||
buffer.append(key).append(" -> "); //$NON-NLS-1$
|
||||
int[] ints = this.valueTable[i];
|
||||
buffer.append('[');
|
||||
if (ints != null) {
|
||||
for (int j = 0, max = ints.length; j < max; j++) {
|
||||
if (j > 0) {
|
||||
buffer.append(',');
|
||||
}
|
||||
buffer.append(ints[j]);
|
||||
}
|
||||
}
|
||||
buffer.append("]\n"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return String.valueOf(buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc.internal;
|
||||
|
||||
public interface JavadocConstants {
|
||||
|
||||
String ANCHOR_PREFIX_END = "\""; //$NON-NLS-1$
|
||||
char[] ANCHOR_PREFIX_START = "<A NAME=\"".toCharArray(); //$NON-NLS-1$
|
||||
int ANCHOR_PREFIX_START_LENGHT = ANCHOR_PREFIX_START.length;
|
||||
char[] ANCHOR_SUFFIX = "</A>".toCharArray(); //$NON-NLS-1$
|
||||
int ANCHOR_SUFFIX_LENGTH = JavadocConstants.ANCHOR_SUFFIX.length;
|
||||
char[] CONSTRUCTOR_DETAIL = "<!-- ========= CONSTRUCTOR DETAIL ======== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] CONSTRUCTOR_SUMMARY = "<!-- ======== CONSTRUCTOR SUMMARY ======== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] FIELD_DETAIL= "<!-- ============ FIELD DETAIL =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] FIELD_SUMMARY = "<!-- =========== FIELD SUMMARY =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] ENUM_CONSTANT_SUMMARY = "<!-- =========== ENUM CONSTANT SUMMARY =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] ENUM_CONSTANT_DETAIL = "<!-- ============ ENUM CONSTANT DETAIL =========== -->".toCharArray();
|
||||
char[] ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY = "<!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] ANNOTATION_TYPE_OPTIONAL_MEMBER_SUMMARY = "<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] END_OF_CLASS_DATA = "<!-- ========= END OF CLASS DATA ========= -->".toCharArray(); //$NON-NLS-1$
|
||||
String HTML_EXTENSION = ".html"; //$NON-NLS-1$
|
||||
String INDEX_FILE_NAME = "index.html"; //$NON-NLS-1$
|
||||
char[] METHOD_DETAIL = "<!-- ============ METHOD DETAIL ========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] METHOD_SUMMARY = "<!-- ========== METHOD SUMMARY =========== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] NESTED_CLASS_SUMMARY = "<!-- ======== NESTED CLASS SUMMARY ======== -->".toCharArray(); //$NON-NLS-1$
|
||||
String PACKAGE_FILE_NAME = "package-summary.html"; //$NON-NLS-1$
|
||||
char[] PACKAGE_DESCRIPTION_START = "name=\"package_description\"".toCharArray(); //$NON-NLS-1$
|
||||
char[] PACKAGE_DESCRIPTION_START2 = "name=\"package.description\"".toCharArray(); //$NON-NLS-1$
|
||||
char[] H2_PREFIX = "<H2".toCharArray(); //$NON-NLS-1$
|
||||
char[] H2_SUFFIX = "</H2>".toCharArray(); //$NON-NLS-1$
|
||||
int H2_SUFFIX_LENGTH = H2_SUFFIX.length;
|
||||
char[] BOTTOM_NAVBAR = "<!-- ======= START OF BOTTOM NAVBAR ====== -->".toCharArray(); //$NON-NLS-1$
|
||||
char[] SEPARATOR_START = "<!-- =".toCharArray(); //$NON-NLS-1$
|
||||
char[] START_OF_CLASS_DATA = "<!-- ======== START OF CLASS DATA ======== -->".toCharArray(); //$NON-NLS-1$
|
||||
int START_OF_CLASS_DATA_LENGTH = JavadocConstants.START_OF_CLASS_DATA.length;
|
||||
String P = "<P>"; //$NON-NLS-1$
|
||||
String DIV_CLASS_BLOCK = "<DIV CLASS=\"BLOCK\">"; //$NON-NLS-1$
|
||||
}
|
||||
@@ -0,0 +1,656 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
|
||||
public class JavadocContents {
|
||||
private static final int[] UNKNOWN_FORMAT = new int[0];
|
||||
|
||||
// private IType type;
|
||||
private char[] content;
|
||||
|
||||
private int childrenStart;
|
||||
|
||||
private boolean hasComputedChildrenSections = false;
|
||||
private int indexOfFieldDetails;
|
||||
private int indexOfEnumConstantsDetails;
|
||||
private int indexOfConstructorDetails;
|
||||
private int indexOfMethodDetails;
|
||||
private int indexOfEndOfClassData;
|
||||
|
||||
private int indexOfFieldsBottom;
|
||||
private int indexOfEnumConstantsBottom;
|
||||
private int indexOfAllMethodsTop;
|
||||
private int indexOfAllMethodsBottom;
|
||||
|
||||
private int[] typeDocRange;
|
||||
private HashtableOfObjectToIntArray fieldDocRanges;
|
||||
private HashtableOfObjectToIntArray methodDocRanges;
|
||||
|
||||
private int[] fieldAnchorIndexes;
|
||||
private int fieldAnchorIndexesCount;
|
||||
private int fieldLastAnchorFoundIndex;
|
||||
private int[] methodAnchorIndexes;
|
||||
private int methodAnchorIndexesCount;
|
||||
private int methodLastAnchorFoundIndex;
|
||||
private int[] unknownFormatAnchorIndexes;
|
||||
private int unknownFormatAnchorIndexesCount;
|
||||
private int unknownFormatLastAnchorFoundIndex;
|
||||
private int[] tempAnchorIndexes;
|
||||
private int tempAnchorIndexesCount;
|
||||
private int tempLastAnchorFoundIndex;
|
||||
|
||||
// public JavadocContents(IType type, String content) {
|
||||
// this(content);
|
||||
// this.type = type;
|
||||
// }
|
||||
|
||||
public JavadocContents(String content) {
|
||||
this.content = content != null ? content.toCharArray() : null;
|
||||
}
|
||||
/*
|
||||
* Returns the part of the javadoc that describe the type
|
||||
*/
|
||||
public String getTypeDoc(IType type) throws Exception {
|
||||
if (this.content == null) return null;
|
||||
|
||||
synchronized (this) {
|
||||
if (this.typeDocRange == null) {
|
||||
computeTypeRange(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.typeDocRange != null) {
|
||||
if (this.typeDocRange == UNKNOWN_FORMAT) throw new Exception("Unknown javadoc format " + type);
|
||||
return String.valueOf(CharOperation.subarray(this.content, this.typeDocRange[0], this.typeDocRange[1]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// public String getPackageDoc() throws JavaModelException {
|
||||
// if (this.content == null) return null;
|
||||
// int[] range = null;
|
||||
// int index = CharOperation.indexOf(JavadocConstants.PACKAGE_DESCRIPTION_START2, this.content, false, 0);
|
||||
// if (index == -1) {
|
||||
// index = CharOperation.indexOf(JavadocConstants.PACKAGE_DESCRIPTION_START, this.content, false, 0);
|
||||
// }
|
||||
// if (index == -1) return null;
|
||||
// index = CharOperation.indexOf(JavadocConstants.ANCHOR_SUFFIX, this.content, false, index);
|
||||
// if (index == -1) return null;
|
||||
//
|
||||
// int start = CharOperation.indexOf(JavadocConstants.H2_PREFIX, this.content, false, index);
|
||||
// if (start != -1) {
|
||||
// start = CharOperation.indexOf(JavadocConstants.H2_SUFFIX, this.content, false, start);
|
||||
// if (start != -1) index = start + JavadocConstants.H2_SUFFIX_LENGTH;
|
||||
// }
|
||||
// if (index != -1) {
|
||||
// int end = CharOperation.indexOf(JavadocConstants.BOTTOM_NAVBAR, this.content, false, index);
|
||||
// if (end == -1) end = this.content.length -1;
|
||||
// range = new int[]{index, end};
|
||||
// return String.valueOf(CharOperation.subarray(this.content, range[0], range[1]));
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/*
|
||||
* Returns the part of the javadoc that describe a field of the type
|
||||
*/
|
||||
public String getFieldDoc(IField child) throws Exception {
|
||||
if (this.content == null) return null;
|
||||
|
||||
int[] range = null;
|
||||
synchronized (this) {
|
||||
if (this.fieldDocRanges == null) {
|
||||
this.fieldDocRanges = new HashtableOfObjectToIntArray();
|
||||
} else {
|
||||
range = this.fieldDocRanges.get(child);
|
||||
}
|
||||
|
||||
if (range == null) {
|
||||
range = computeFieldRange(child);
|
||||
this.fieldDocRanges.put(child, range);
|
||||
}
|
||||
}
|
||||
|
||||
if (range != null) {
|
||||
if (range == UNKNOWN_FORMAT) throw new Exception("Unknown javadoc format " + child);
|
||||
return String.valueOf(CharOperation.subarray(this.content, range[0], range[1]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the part of the javadoc that describe a method of the type
|
||||
*/
|
||||
public String getMethodDoc(IMethod method) throws Exception {
|
||||
if (this.content == null) return null;
|
||||
|
||||
int[] range = null;
|
||||
synchronized (this) {
|
||||
if (this.methodDocRanges == null) {
|
||||
this.methodDocRanges = new HashtableOfObjectToIntArray();
|
||||
} else {
|
||||
range = this.methodDocRanges.get(method);
|
||||
}
|
||||
|
||||
if (range == null) {
|
||||
range = computeMethodRange(method);
|
||||
this.methodDocRanges.put(method, range);
|
||||
}
|
||||
}
|
||||
|
||||
if (range != null) {
|
||||
if (range == UNKNOWN_FORMAT) {
|
||||
throw new Exception("Unknown javadoc format " + method);
|
||||
}
|
||||
return String.valueOf(CharOperation.subarray(this.content, range[0], range[1]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the ranges of the parts of the javadoc that describe each method of the type
|
||||
*/
|
||||
private int[] computeChildRange(char[] anchor, int indexOfSectionBottom) throws Exception {
|
||||
|
||||
// checks each known anchor locations
|
||||
if (this.tempAnchorIndexesCount > 0) {
|
||||
for (int i = 0; i < this.tempAnchorIndexesCount; i++) {
|
||||
int anchorEndStart = this.tempAnchorIndexes[i];
|
||||
|
||||
if (anchorEndStart != -1 && CharOperation.prefixEquals(anchor, this.content, false, anchorEndStart)) {
|
||||
|
||||
this.tempAnchorIndexes[i] = -1;
|
||||
|
||||
return computeChildRange(anchorEndStart, anchor, indexOfSectionBottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fromIndex = this.tempLastAnchorFoundIndex;
|
||||
int index;
|
||||
|
||||
// check each next unknown anchor locations
|
||||
while ((index = CharOperation.indexOf(JavadocConstants.ANCHOR_PREFIX_START, this.content, false, fromIndex)) != -1 && (index < indexOfSectionBottom || indexOfSectionBottom == -1)) {
|
||||
fromIndex = index + 1;
|
||||
|
||||
int anchorEndStart = index + JavadocConstants.ANCHOR_PREFIX_START_LENGHT;
|
||||
|
||||
this.tempLastAnchorFoundIndex = anchorEndStart;
|
||||
|
||||
if (CharOperation.prefixEquals(anchor, this.content, false, anchorEndStart)) {
|
||||
return computeChildRange(anchorEndStart, anchor, indexOfSectionBottom);
|
||||
} else {
|
||||
if (this.tempAnchorIndexes.length == this.tempAnchorIndexesCount) {
|
||||
System.arraycopy(this.tempAnchorIndexes, 0, this.tempAnchorIndexes = new int[this.tempAnchorIndexesCount + 20], 0, this.tempAnchorIndexesCount);
|
||||
}
|
||||
|
||||
this.tempAnchorIndexes[this.tempAnchorIndexesCount++] = anchorEndStart;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int[] computeChildRange(int anchorEndStart, char[] anchor, int indexOfBottom) {
|
||||
int[] range = null;
|
||||
|
||||
// try to find the bottom of the section
|
||||
if (indexOfBottom != -1) {
|
||||
// try to find the end of the anchor
|
||||
int indexOfEndLink = CharOperation.indexOf(JavadocConstants.ANCHOR_SUFFIX, this.content, false, anchorEndStart + anchor.length);
|
||||
if (indexOfEndLink != -1) {
|
||||
// try to find the next anchor
|
||||
int indexOfNextElement = CharOperation.indexOf(JavadocConstants.ANCHOR_PREFIX_START, this.content, false, indexOfEndLink);
|
||||
|
||||
int javadocStart = indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH;
|
||||
int javadocEnd = indexOfNextElement == -1 ? indexOfBottom : Math.min(indexOfNextElement, indexOfBottom);
|
||||
range = sanitizeRange(new int[]{javadocStart, javadocEnd}, "ul", "li");
|
||||
} else {
|
||||
// the anchor has no suffix
|
||||
range = UNKNOWN_FORMAT;
|
||||
}
|
||||
} else {
|
||||
// the detail section has no bottom
|
||||
range = UNKNOWN_FORMAT;
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
private void computeChildrenSections() {
|
||||
// try to find the next separator part
|
||||
int lastIndex = CharOperation.indexOf(JavadocConstants.SEPARATOR_START, this.content, false, this.childrenStart);
|
||||
lastIndex = lastIndex == -1 ? this.childrenStart : lastIndex;
|
||||
|
||||
// try to find enum cosntants detail start
|
||||
this.indexOfEnumConstantsDetails = CharOperation.indexOf(JavadocConstants.ENUM_CONSTANT_DETAIL, this.content, false, lastIndex);
|
||||
lastIndex = this.indexOfEnumConstantsDetails == -1 ? lastIndex : this.indexOfEnumConstantsDetails;
|
||||
|
||||
// try to find field detail start
|
||||
this.indexOfFieldDetails = CharOperation.indexOf(JavadocConstants.FIELD_DETAIL, this.content, false, lastIndex);
|
||||
lastIndex = this.indexOfFieldDetails == -1 ? lastIndex : this.indexOfFieldDetails;
|
||||
|
||||
// try to find constructor detail start
|
||||
this.indexOfConstructorDetails = CharOperation.indexOf(JavadocConstants.CONSTRUCTOR_DETAIL, this.content, false, lastIndex);
|
||||
lastIndex = this.indexOfConstructorDetails == -1 ? lastIndex : this.indexOfConstructorDetails;
|
||||
|
||||
// try to find method detail start
|
||||
this.indexOfMethodDetails = CharOperation.indexOf(JavadocConstants.METHOD_DETAIL, this.content, false, lastIndex);
|
||||
lastIndex = this.indexOfMethodDetails == -1 ? lastIndex : this.indexOfMethodDetails;
|
||||
|
||||
// we take the end of class data
|
||||
final int indexOfStartOfClassData = CharOperation.indexOf(JavadocConstants.START_OF_CLASS_DATA, this.content, false);
|
||||
this.indexOfEndOfClassData = CharOperation.indexOf(JavadocConstants.END_OF_CLASS_DATA, this.content, false, lastIndex);
|
||||
int[] classDataRange = sanitizeRange(new int[] { indexOfStartOfClassData + JavadocConstants.START_OF_CLASS_DATA.length, indexOfEndOfClassData}, "ul", "li", "div");
|
||||
this.indexOfEndOfClassData = classDataRange[1];
|
||||
|
||||
// try to find enum constants bottom
|
||||
this.indexOfEnumConstantsBottom = this.indexOfFieldDetails != -1 ? this.indexOfFieldDetails
|
||||
: this.indexOfConstructorDetails != -1 ? this.indexOfConstructorDetails
|
||||
: this.indexOfMethodDetails != -1 ? this.indexOfMethodDetails : this.indexOfEndOfClassData;
|
||||
|
||||
// Get rid of possible <ul><li> tag wrappers
|
||||
int[] fieldsRange = sanitizeRange(new int[] {indexOfEnumConstantsDetails + JavadocConstants.ENUM_CONSTANT_DETAIL.length, indexOfEnumConstantsBottom}, "ul", "li", "div");
|
||||
indexOfEnumConstantsDetails = fieldsRange[0];
|
||||
indexOfEnumConstantsBottom = fieldsRange[1];
|
||||
|
||||
// try to find the field detail end
|
||||
this.indexOfFieldsBottom =
|
||||
this.indexOfConstructorDetails != -1 ? this.indexOfConstructorDetails :
|
||||
this.indexOfMethodDetails != -1 ? this.indexOfMethodDetails:
|
||||
this.indexOfEndOfClassData;
|
||||
|
||||
this.indexOfAllMethodsTop =
|
||||
this.indexOfConstructorDetails != -1 ?
|
||||
this.indexOfConstructorDetails :
|
||||
this.indexOfMethodDetails;
|
||||
|
||||
this.indexOfAllMethodsBottom = this.indexOfEndOfClassData;
|
||||
|
||||
// Get rid of possible <ul><li> tag wrappers
|
||||
fieldsRange = sanitizeRange(new int[] {indexOfFieldDetails + JavadocConstants.FIELD_DETAIL.length, indexOfFieldsBottom}, "ul", "li", "div");
|
||||
indexOfFieldDetails = fieldsRange[0];
|
||||
indexOfFieldsBottom = fieldsRange[1];
|
||||
|
||||
int[] methodsRange = sanitizeRange(new int[] {
|
||||
indexOfAllMethodsTop + (indexOfAllMethodsTop == indexOfConstructorDetails
|
||||
? JavadocConstants.CONSTRUCTOR_DETAIL.length : JavadocConstants.METHOD_DETAIL.length),
|
||||
indexOfAllMethodsBottom }, "ul", "li", "div");
|
||||
indexOfAllMethodsTop = methodsRange[0];
|
||||
indexOfAllMethodsBottom = methodsRange[1];
|
||||
|
||||
// Remove trailing extra tag closings
|
||||
String badEnding = "</li>\n</ul>\n</li>\n</ul>";
|
||||
indexOfAllMethodsBottom = trimBadEnding(badEnding, indexOfAllMethodsBottom, badEnding.length() / 2);
|
||||
|
||||
this.hasComputedChildrenSections = true;
|
||||
|
||||
}
|
||||
|
||||
private int trimBadEnding(String badEnding, int end) {
|
||||
return trimBadEnding(badEnding, end, badEnding.length());
|
||||
}
|
||||
|
||||
private int trimBadEnding(String badEnding, int end, int numberOfCharsToTrim) {
|
||||
if (Arrays.equals(CharOperation.subarray(content, end - badEnding.length(), end), badEnding.toCharArray())) {
|
||||
return end - numberOfCharsToTrim;
|
||||
} else {
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the ranges of the parts of the javadoc that describe each child of the type (fields, methods)
|
||||
*/
|
||||
private int[] computeFieldRange(IField field) throws Exception {
|
||||
IType type = field.getDeclaringType();
|
||||
|
||||
if (!this.hasComputedChildrenSections) {
|
||||
computeChildrenSections();
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer(field.getElementName());
|
||||
buffer.append(JavadocConstants.ANCHOR_PREFIX_END);
|
||||
char[] anchor = String.valueOf(buffer).toCharArray();
|
||||
|
||||
int[] range = null;
|
||||
int top = field.isEnumConstant() ? this.indexOfEnumConstantsDetails : this.indexOfFieldDetails;
|
||||
int bottom = field.isEnumConstant() ? this.indexOfEnumConstantsBottom : this.indexOfFieldsBottom;
|
||||
|
||||
if (top == -1 || bottom == -1) {
|
||||
// the detail section has no top or bottom, so the doc has an unknown format
|
||||
if (this.unknownFormatAnchorIndexes == null) {
|
||||
this.unknownFormatAnchorIndexes = new int[(int)type.getFields().count()];
|
||||
this.unknownFormatAnchorIndexesCount = 0;
|
||||
this.unknownFormatLastAnchorFoundIndex = this.childrenStart;
|
||||
}
|
||||
|
||||
this.tempAnchorIndexes = this.unknownFormatAnchorIndexes;
|
||||
this.tempAnchorIndexesCount = this.unknownFormatAnchorIndexesCount;
|
||||
this.tempLastAnchorFoundIndex = this.unknownFormatLastAnchorFoundIndex;
|
||||
|
||||
range = computeChildRange(anchor, bottom);
|
||||
|
||||
this.unknownFormatLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
|
||||
this.unknownFormatAnchorIndexesCount = this.tempAnchorIndexesCount;
|
||||
this.unknownFormatAnchorIndexes = this.tempAnchorIndexes;
|
||||
} else {
|
||||
if (this.fieldAnchorIndexes == null) {
|
||||
this.fieldAnchorIndexes = new int[(int)type.getFields().count()];
|
||||
this.fieldAnchorIndexesCount = 0;
|
||||
this.fieldLastAnchorFoundIndex = top;
|
||||
}
|
||||
|
||||
this.tempAnchorIndexes = this.fieldAnchorIndexes;
|
||||
this.tempAnchorIndexesCount = this.fieldAnchorIndexesCount;
|
||||
this.tempLastAnchorFoundIndex = this.fieldLastAnchorFoundIndex;
|
||||
|
||||
range = computeChildRange(anchor, bottom);
|
||||
|
||||
this.fieldLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
|
||||
this.fieldAnchorIndexesCount = this.tempAnchorIndexesCount;
|
||||
this.fieldAnchorIndexes = this.tempAnchorIndexes;
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the ranges of the parts of the javadoc that describe each method of the type
|
||||
*/
|
||||
private int[] computeMethodRange(IMethod method) throws Exception {
|
||||
IType type = method.getDeclaringType();
|
||||
|
||||
if (!this.hasComputedChildrenSections) {
|
||||
computeChildrenSections();
|
||||
}
|
||||
|
||||
char[] anchor = computeMethodAnchorPrefixEnd(method).toCharArray();
|
||||
|
||||
int[] range = null;
|
||||
|
||||
|
||||
if (this.indexOfAllMethodsTop == -1 || this.indexOfAllMethodsBottom == -1) {
|
||||
// the detail section has no top or bottom, so the doc has an unknown format
|
||||
if (this.unknownFormatAnchorIndexes == null) {
|
||||
int childernCount = (int)(type.getMethods().count() + type.getFields().count());
|
||||
this.unknownFormatAnchorIndexes = new int[childernCount];
|
||||
this.unknownFormatAnchorIndexesCount = 0;
|
||||
this.unknownFormatLastAnchorFoundIndex = this.childrenStart;
|
||||
}
|
||||
|
||||
this.tempAnchorIndexes = this.unknownFormatAnchorIndexes;
|
||||
this.tempAnchorIndexesCount = this.unknownFormatAnchorIndexesCount;
|
||||
this.tempLastAnchorFoundIndex = this.unknownFormatLastAnchorFoundIndex;
|
||||
|
||||
range = computeChildRange(anchor, this.indexOfFieldsBottom);
|
||||
if (range == null) {
|
||||
range = computeChildRange(getJavadoc8Anchor(anchor), this.indexOfAllMethodsBottom);
|
||||
}
|
||||
|
||||
this.unknownFormatLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
|
||||
this.unknownFormatAnchorIndexesCount = this.tempAnchorIndexesCount;
|
||||
this.unknownFormatAnchorIndexes = this.tempAnchorIndexes;
|
||||
} else {
|
||||
if (this.methodAnchorIndexes == null) {
|
||||
this.methodAnchorIndexes = new int[(int)type.getMethods().count()];
|
||||
this.methodAnchorIndexesCount = 0;
|
||||
this.methodLastAnchorFoundIndex = this.indexOfAllMethodsTop;
|
||||
}
|
||||
|
||||
this.tempAnchorIndexes = this.methodAnchorIndexes;
|
||||
this.tempAnchorIndexesCount = this.methodAnchorIndexesCount;
|
||||
this.tempLastAnchorFoundIndex = this.methodLastAnchorFoundIndex;
|
||||
|
||||
range = computeChildRange(anchor, this.indexOfAllMethodsBottom);
|
||||
if (range == null) {
|
||||
range = computeChildRange(getJavadoc8Anchor(anchor), this.indexOfAllMethodsBottom);
|
||||
}
|
||||
|
||||
this.methodLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
|
||||
this.methodAnchorIndexesCount = this.tempAnchorIndexesCount;
|
||||
this.methodAnchorIndexes = this.tempAnchorIndexes;
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
private static char[] getJavadoc8Anchor(char[] anchor) {
|
||||
// fix for bug 432284: [1.8] Javadoc-8-style anchors not found by IMethod#getAttachedJavadoc(..)
|
||||
char[] anchor8 = new char[anchor.length];
|
||||
int i8 = 0;
|
||||
for (int i = 0; i < anchor.length; i++) {
|
||||
char ch = anchor[i];
|
||||
switch (ch) {
|
||||
case '(':
|
||||
case ')':
|
||||
case ',':
|
||||
anchor8[i8++] = '-';
|
||||
break;
|
||||
case '[':
|
||||
anchor8[i8++] = ':';
|
||||
anchor8[i8++] = 'A';
|
||||
break;
|
||||
case ' ': // handled by preceding ','
|
||||
case ']': // handled by preceding '['
|
||||
break;
|
||||
default:
|
||||
anchor8[i8++] = ch;
|
||||
}
|
||||
}
|
||||
if (i8 != anchor.length) {
|
||||
anchor8 = CharOperation.subarray(anchor8, 0, i8);
|
||||
}
|
||||
return anchor8;
|
||||
}
|
||||
|
||||
private String computeMethodAnchorPrefixEnd(IMethod method) throws Exception {
|
||||
// String typeQualifiedName = null;
|
||||
// if (this.type.isMember()) {
|
||||
// IType currentType = this.type;
|
||||
// StringBuffer buffer = new StringBuffer();
|
||||
// while (currentType != null) {
|
||||
// buffer.insert(0, currentType.getElementName());
|
||||
// currentType = currentType.getDeclaringType();
|
||||
// if (currentType != null) {
|
||||
// buffer.insert(0, '.');
|
||||
// }
|
||||
// }
|
||||
// typeQualifiedName = new String(buffer.toString());
|
||||
// } else {
|
||||
// typeQualifiedName = this.type.getElementName();
|
||||
// }
|
||||
|
||||
// String methodName = method.getElementName();
|
||||
// if (method.getElementName().equals(method.getDeclaringType().getElementName())) {
|
||||
// methodName = typeQualifiedName;
|
||||
// }
|
||||
|
||||
String anchor = createMethodAnchor(method);
|
||||
|
||||
// char[] genericSignature = info.getGenericSignature();
|
||||
// if (genericSignature != null) {
|
||||
// genericSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
|
||||
// anchor = Util.toAnchor(0, genericSignature, methodName, Flags.isVarargs(method.getFlags()));
|
||||
// if (anchor == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, method));
|
||||
// } else {
|
||||
// anchor = Signature.toString(method.getSignature().replace('/', '.'), methodName, null, true, false, Flags.isVarargs(method.getFlags()));
|
||||
// }
|
||||
|
||||
// IType declaringType = /*this.type*/method.getDeclaringType();
|
||||
// if (declaringType.isMember()) {
|
||||
// // might need to remove a part of the signature corresponding to the synthetic argument (only for constructor)
|
||||
// if (method.getElementName().equals(method.getDeclaringType().getElementName()) && !Flags.isStatic(declaringType.getFlags())) {
|
||||
// int indexOfOpeningParen = anchor.indexOf('(');
|
||||
// if (indexOfOpeningParen == -1) {
|
||||
// // should not happen as this is a method signature
|
||||
// return null;
|
||||
// }
|
||||
// int index = indexOfOpeningParen;
|
||||
// indexOfOpeningParen++;
|
||||
// int indexOfComma = anchor.indexOf(',', index);
|
||||
// if (indexOfComma != -1) {
|
||||
// index = indexOfComma + 2;
|
||||
// } else {
|
||||
// // no argument, but a synthetic argument
|
||||
// index = anchor.indexOf(')', index);
|
||||
// }
|
||||
// anchor = anchor.substring(0, indexOfOpeningParen) + anchor.substring(index);
|
||||
// }
|
||||
// }
|
||||
return anchor + JavadocConstants.ANCHOR_PREFIX_END;
|
||||
}
|
||||
|
||||
private String createMethodAnchor(IMethod method) {
|
||||
StringBuilder sb = new StringBuilder(method.getElementName());
|
||||
sb.append('(');
|
||||
sb.append(String.join(",", method.parameters().map(p -> p.toString()).collect(Collectors.toList())));
|
||||
sb.append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the range of the part of the javadoc that describe the type
|
||||
*/
|
||||
private void computeTypeRange(IType type) throws Exception {
|
||||
final int indexOfStartOfClassData = CharOperation.indexOf(JavadocConstants.START_OF_CLASS_DATA, this.content, false);
|
||||
if (indexOfStartOfClassData == -1) {
|
||||
this.typeDocRange = UNKNOWN_FORMAT;
|
||||
return;
|
||||
}
|
||||
int indexOfNextSeparator = CharOperation.indexOf(JavadocConstants.SEPARATOR_START, this.content, false, indexOfStartOfClassData);
|
||||
if (indexOfNextSeparator == -1) {
|
||||
this.typeDocRange = UNKNOWN_FORMAT;
|
||||
return;
|
||||
}
|
||||
int indexOfNextSummary = CharOperation.indexOf(JavadocConstants.NESTED_CLASS_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
if (indexOfNextSummary == -1 && type.isEnum()) {
|
||||
// try to find enum constant summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.ENUM_CONSTANT_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
}
|
||||
if (indexOfNextSummary == -1 && type.isAnnotation()) {
|
||||
// try to find required enum constant summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
if (indexOfNextSummary == -1) {
|
||||
// try to find optional enum constant summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.ANNOTATION_TYPE_OPTIONAL_MEMBER_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
}
|
||||
}
|
||||
if (indexOfNextSummary == -1) {
|
||||
// try to find field summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.FIELD_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
}
|
||||
if (indexOfNextSummary == -1) {
|
||||
// try to find constructor summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.CONSTRUCTOR_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
}
|
||||
if (indexOfNextSummary == -1) {
|
||||
// try to find method summary start
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.METHOD_SUMMARY, this.content, false, indexOfNextSeparator);
|
||||
}
|
||||
|
||||
if (indexOfNextSummary == -1) {
|
||||
// we take the end of class data
|
||||
indexOfNextSummary = CharOperation.indexOf(JavadocConstants.END_OF_CLASS_DATA, this.content, false, indexOfNextSeparator);
|
||||
} else {
|
||||
// improve performance of computation of children ranges
|
||||
this.childrenStart = indexOfNextSummary + 1;
|
||||
}
|
||||
|
||||
if (indexOfNextSummary == -1) {
|
||||
this.typeDocRange = UNKNOWN_FORMAT;
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Cut off the type hierarchy, see bug 119844.
|
||||
* We remove the contents between the start of class data and where
|
||||
* we guess the actual class comment starts.
|
||||
*/
|
||||
int start = indexOfStartOfClassData + JavadocConstants.START_OF_CLASS_DATA_LENGTH;
|
||||
int indexOfFirstParagraph = CharOperation.indexOf(JavadocConstants.P.toCharArray(), this.content, false, start, indexOfNextSummary);
|
||||
int indexOfFirstDiv = CharOperation.indexOf(JavadocConstants.DIV_CLASS_BLOCK.toCharArray(), this.content, false, start, indexOfNextSummary);
|
||||
int afterHierarchy = indexOfNextSummary;
|
||||
if (indexOfFirstParagraph != -1 && indexOfFirstParagraph < afterHierarchy) {
|
||||
afterHierarchy = indexOfFirstParagraph;
|
||||
}
|
||||
if (indexOfFirstDiv != -1 && indexOfFirstDiv < afterHierarchy) {
|
||||
afterHierarchy = indexOfFirstDiv;
|
||||
}
|
||||
if (afterHierarchy != indexOfNextSummary) {
|
||||
start = afterHierarchy;
|
||||
|
||||
int indexOfClassDescriptionEnd = trimBadEnding("<div class=\"summary\">\n<ul class=\"blockList\">\n<li class=\"blockList\">\n", indexOfNextSummary);
|
||||
indexOfClassDescriptionEnd = trimBadEnding("</li>\n</ul>\n</div>\n", indexOfClassDescriptionEnd);
|
||||
this.typeDocRange = new int[]{start, indexOfClassDescriptionEnd};
|
||||
this.typeDocRange = sanitizeRange(typeDocRange, "ul", "li");
|
||||
} else {
|
||||
// No room left for class comment;
|
||||
this.typeDocRange = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private int[] trimRange(int[] range) {
|
||||
int start = range[0];
|
||||
int end = range[1];
|
||||
|
||||
while (start < content.length && start < end && Character.isWhitespace(content[start])) {
|
||||
start++;
|
||||
}
|
||||
|
||||
while (end > 0 && start < end && Character.isWhitespace(content[end-1])) {
|
||||
end--;
|
||||
}
|
||||
|
||||
return new int[] { start, end };
|
||||
}
|
||||
|
||||
private int[] trimTag(int[] range, CharSequence tag) {
|
||||
int start = range[0];
|
||||
int end = range[1];
|
||||
|
||||
char[] startingTag = ("<" + tag).toCharArray();
|
||||
char[] closingTag = ("</" + tag + ">").toCharArray();
|
||||
char[] ending = CharOperation.subarray(content, end - closingTag.length, end);
|
||||
char[] starting = CharOperation.subarray(content, start, start + startingTag.length);
|
||||
if (Arrays.equals(closingTag, ending) && Arrays.equals(startingTag, starting)) {
|
||||
return new int[] { CharOperation.indexOf('>', content, start, end) + 1, end - closingTag.length};
|
||||
} else {
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
private int[] sanitizeRange(int[] range, CharSequence... removeWrapperTags) {
|
||||
boolean changed = false;
|
||||
do {
|
||||
int[] newRange = trimRange(range);
|
||||
for (CharSequence tag : removeWrapperTags) {
|
||||
newRange = trimTag(newRange, tag);
|
||||
}
|
||||
// newRange = trimTag(newRange, "div");
|
||||
// newRange = trimTag(newRange, "ul");
|
||||
// newRange = trimTag(newRange, "li");
|
||||
changed = !Arrays.equals(newRange, range);
|
||||
range = newRange;
|
||||
} while (changed);
|
||||
return range;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,580 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.javadoc.internal;
|
||||
|
||||
public class ScannerHelper {
|
||||
|
||||
// storage for internal flags (32 bits) BIT USAGE
|
||||
public final static int Bit1 = 0x1; // return type (operator) | name reference kind (name ref) | add assertion (type decl) | useful empty statement (empty statement)
|
||||
public final static int Bit2 = 0x2; // return type (operator) | name reference kind (name ref) | has local type (type, method, field decl) | if type elided (local)
|
||||
public final static int Bit3 = 0x4; // return type (operator) | name reference kind (name ref) | implicit this (this ref) | is argument(local)
|
||||
public final static int Bit4 = 0x8; // return type (operator) | first assignment to local (name ref,local decl) | undocumented empty block (block, type and method decl)
|
||||
public final static int Bit5 = 0x10; // value for return (expression) | has all method bodies (unit) | supertype ref (type ref) | resolved (field decl)
|
||||
public final static int Bit6 = 0x20; // depth (name ref, msg) | ignore need cast check (cast expression) | error in signature (method declaration/ initializer) | is recovered (annotation reference)
|
||||
public final static int Bit7 = 0x40; // depth (name ref, msg) | operator (operator) | need runtime checkcast (cast expression) | label used (labelStatement) | needFreeReturn (AbstractMethodDeclaration)
|
||||
public final static int Bit8 = 0x80; // depth (name ref, msg) | operator (operator) | unsafe cast (cast expression) | is default constructor (constructor declaration) | isElseStatementUnreachable (if statement)
|
||||
public final static int Bit9 = 0x100; // depth (name ref, msg) | operator (operator) | is local type (type decl) | isThenStatementUnreachable (if statement) | can be static
|
||||
public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
|
||||
public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operator) | is member type (type decl)
|
||||
public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
|
||||
public final static int Bit13 = 0x1000; // depth (name ref, msg) | is secondary type (type decl)
|
||||
public final static int Bit14 = 0x2000; // strictly assigned (reference lhs) | discard enclosing instance (explicit constr call) | hasBeenGenerated (type decl)
|
||||
public final static int Bit15 = 0x4000; // is unnecessary cast (expression) | is varargs (type ref) | isSubRoutineEscaping (try statement) | superAccess (javadoc allocation expression/javadoc message send/javadoc return statement)
|
||||
public final static int Bit16 = 0x8000; // in javadoc comment (name ref, type ref, msg)
|
||||
public final static int Bit17 = 0x10000; // compound assigned (reference lhs) | unchecked (msg, alloc, explicit constr call)
|
||||
public final static int Bit18 = 0x20000; // non null (expression) | onDemand (import reference)
|
||||
public final static int Bit19 = 0x40000; // didResolve (parameterized qualified type ref/parameterized single type ref) | empty (javadoc return statement) | needReceiverGenericCast (msg/fieldref)
|
||||
public final static int Bit20 = 0x80000; // contains syntax errors (method declaration, type declaration, field declarations, initializer), typeref: <> name ref: lambda capture)
|
||||
public final static int Bit21 = 0x100000;
|
||||
public final static int Bit22 = 0x200000; // parenthesis count (expression) | used (import reference) shadows outer local (local declarations)
|
||||
public final static int Bit23 = 0x400000; // parenthesis count (expression)
|
||||
public final static int Bit24 = 0x800000; // parenthesis count (expression)
|
||||
public final static int Bit25 = 0x1000000; // parenthesis count (expression)
|
||||
public final static int Bit26 = 0x2000000; // parenthesis count (expression)
|
||||
public final static int Bit27 = 0x4000000; // parenthesis count (expression)
|
||||
public final static int Bit28 = 0x8000000; // parenthesis count (expression)
|
||||
public final static int Bit29 = 0x10000000; // parenthesis count (expression)
|
||||
public final static int Bit30 = 0x20000000; // elseif (if statement) | try block exit (try statement) | fall-through (case statement) | ignore no effect assign (expression ref) | needScope (for statement) | isAnySubRoutineEscaping (return statement) | blockExit (synchronized statement)
|
||||
public final static int Bit31 = 0x40000000; // local declaration reachable (local decl) | ignore raw type check (type ref) | discard entire assignment (assignment) | isSynchronized (return statement) | thenExit (if statement)
|
||||
public final static int Bit32 = 0x80000000; // reachable (statement)
|
||||
|
||||
// public final static long[] Bits = {
|
||||
// ASTNode.Bit1, ASTNode.Bit2, ASTNode.Bit3, ASTNode.Bit4, ASTNode.Bit5, ASTNode.Bit6,
|
||||
// ASTNode.Bit7, ASTNode.Bit8, ASTNode.Bit9, ASTNode.Bit10, ASTNode.Bit11, ASTNode.Bit12,
|
||||
// ASTNode.Bit13, ASTNode.Bit14, ASTNode.Bit15, ASTNode.Bit16, ASTNode.Bit17, ASTNode.Bit18,
|
||||
// ASTNode.Bit19, ASTNode.Bit20, ASTNode.Bit21, ASTNode.Bit22, ASTNode.Bit23, ASTNode.Bit24,
|
||||
// ASTNode.Bit25, ASTNode.Bit26, ASTNode.Bit27, ASTNode.Bit28, ASTNode.Bit29, ASTNode.Bit30,
|
||||
// ASTNode.Bit31, ASTNode.Bit32L, ASTNode.Bit33L, ASTNode.Bit34L, ASTNode.Bit35L, ASTNode.Bit36L,
|
||||
// ASTNode.Bit37L, ASTNode.Bit38L, ASTNode.Bit39L, ASTNode.Bit40L, ASTNode.Bit41L, ASTNode.Bit42L,
|
||||
// ASTNode.Bit43L, ASTNode.Bit44L, ASTNode.Bit45L, ASTNode.Bit46L, ASTNode.Bit47L, ASTNode.Bit48L,
|
||||
// ASTNode.Bit49L, ASTNode.Bit50L, ASTNode.Bit51L, ASTNode.Bit52L, ASTNode.Bit53L, ASTNode.Bit54L,
|
||||
// ASTNode.Bit55L, ASTNode.Bit56L, ASTNode.Bit57L, ASTNode.Bit58L, ASTNode.Bit59L, ASTNode.Bit60L,
|
||||
// ASTNode.Bit61L, ASTNode.Bit62L, ASTNode.Bit63L, ASTNode.Bit64L,
|
||||
// };
|
||||
//
|
||||
// private static final int START_INDEX = 0;
|
||||
// private static final int PART_INDEX = 1;
|
||||
//
|
||||
// private static long[][][] Tables;
|
||||
// private static long[][][] Tables7;
|
||||
// private static long[][][] Tables8;
|
||||
|
||||
public final static int MAX_OBVIOUS = 128;
|
||||
public final static int[] OBVIOUS_IDENT_CHAR_NATURES = new int[MAX_OBVIOUS];
|
||||
|
||||
public final static int C_JLS_SPACE = Bit9;
|
||||
public final static int C_SPECIAL = Bit8;
|
||||
public final static int C_IDENT_START = Bit7;
|
||||
public final static int C_UPPER_LETTER = Bit6;
|
||||
public final static int C_LOWER_LETTER = Bit5;
|
||||
public final static int C_IDENT_PART = Bit4;
|
||||
public final static int C_DIGIT = Bit3;
|
||||
public final static int C_SEPARATOR = Bit2;
|
||||
public final static int C_SPACE = Bit1;
|
||||
|
||||
static {
|
||||
OBVIOUS_IDENT_CHAR_NATURES[0] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[1] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[2] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[3] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[4] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[5] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[6] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[7] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[8] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[14] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[15] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[16] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[17] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[18] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[19] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[20] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[21] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[22] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[23] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[24] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[25] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[26] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[27] = C_IDENT_PART;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[127] = C_IDENT_PART;
|
||||
|
||||
for (int i = '0'; i <= '9'; i++)
|
||||
OBVIOUS_IDENT_CHAR_NATURES[i] = C_DIGIT | C_IDENT_PART;
|
||||
|
||||
for (int i = 'a'; i <= 'z'; i++)
|
||||
OBVIOUS_IDENT_CHAR_NATURES[i] = C_LOWER_LETTER | C_IDENT_PART | C_IDENT_START;
|
||||
for (int i = 'A'; i <= 'Z'; i++)
|
||||
OBVIOUS_IDENT_CHAR_NATURES[i] = C_UPPER_LETTER | C_IDENT_PART | C_IDENT_START;
|
||||
|
||||
OBVIOUS_IDENT_CHAR_NATURES['_'] = C_SPECIAL | C_IDENT_PART | C_IDENT_START;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['$'] = C_SPECIAL | C_IDENT_PART | C_IDENT_START;
|
||||
|
||||
OBVIOUS_IDENT_CHAR_NATURES[9] = C_SPACE | C_JLS_SPACE; // \ u0009: HORIZONTAL TABULATION
|
||||
OBVIOUS_IDENT_CHAR_NATURES[10] = C_SPACE | C_JLS_SPACE; // \ u000a: LINE FEED
|
||||
OBVIOUS_IDENT_CHAR_NATURES[11] = C_SPACE;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[12] = C_SPACE | C_JLS_SPACE; // \ u000c: FORM FEED
|
||||
OBVIOUS_IDENT_CHAR_NATURES[13] = C_SPACE | C_JLS_SPACE; // \ u000d: CARRIAGE RETURN
|
||||
OBVIOUS_IDENT_CHAR_NATURES[28] = C_SPACE;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[29] = C_SPACE;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[30] = C_SPACE;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[31] = C_SPACE;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[32] = C_SPACE | C_JLS_SPACE; // \ u0020: SPACE
|
||||
|
||||
OBVIOUS_IDENT_CHAR_NATURES['.'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[':'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[';'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[','] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['['] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[']'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['('] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES[')'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['{'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['}'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['+'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['-'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['*'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['/'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['='] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['&'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['|'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['?'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['<'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['>'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['!'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['%'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['^'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['~'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['"'] = C_SEPARATOR;
|
||||
OBVIOUS_IDENT_CHAR_NATURES['\''] = C_SEPARATOR;
|
||||
}
|
||||
//static void initializeTable() {
|
||||
// Tables = initializeTables("unicode"); //$NON-NLS-1$
|
||||
//}
|
||||
//static void initializeTable17() {
|
||||
// Tables7 = initializeTables("unicode6"); //$NON-NLS-1$
|
||||
//}
|
||||
//static void initializeTable18() {
|
||||
// Tables8 = initializeTables("unicode6_2"); //$NON-NLS-1$
|
||||
//}
|
||||
//static long[][][] initializeTables(String unicode_path) {
|
||||
// long[][][] tempTable = new long[2][][];
|
||||
// tempTable[START_INDEX] = new long[3][];
|
||||
// tempTable[PART_INDEX] = new long[4][];
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/start0.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[START_INDEX][0] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/start1.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[START_INDEX][1] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/start2.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[START_INDEX][2] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/part0.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[PART_INDEX][0] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/part1.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[PART_INDEX][1] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/part2.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[PART_INDEX][2] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// DataInputStream inputStream = new DataInputStream(new BufferedInputStream(ScannerHelper.class.getResourceAsStream(unicode_path + "/part14.rsc"))); //$NON-NLS-1$
|
||||
// long[] readValues = new long[1024];
|
||||
// for (int i = 0; i < 1024; i++) {
|
||||
// readValues[i] = inputStream.readLong();
|
||||
// }
|
||||
// inputStream.close();
|
||||
// tempTable[PART_INDEX][3] = readValues;
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return tempTable;
|
||||
//}
|
||||
//private final static boolean isBitSet(long[] values, int i) {
|
||||
// try {
|
||||
// return (values[i / 64] & Bits[i % 64]) != 0;
|
||||
// } catch (NullPointerException e) {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
//public static boolean isJavaIdentifierPart(char c) {
|
||||
// if (c < MAX_OBVIOUS) {
|
||||
// return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_IDENT_PART) != 0;
|
||||
// }
|
||||
// return Character.isJavaIdentifierPart(c);
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param c
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierPart(long complianceLevel, char c) {
|
||||
// if (c < MAX_OBVIOUS) {
|
||||
// return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_IDENT_PART) != 0;
|
||||
// }
|
||||
// return isJavaIdentifierPart(complianceLevel, (int) c);
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param codePoint
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierPart(long complianceLevel, int codePoint) {
|
||||
// if (complianceLevel <= ClassFileConstants.JDK1_6) {
|
||||
// if (Tables == null) {
|
||||
// initializeTable();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables[PART_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables[PART_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables[PART_INDEX][2], codePoint & 0xFFFF);
|
||||
// case 14 :
|
||||
// return isBitSet(Tables[PART_INDEX][3], codePoint & 0xFFFF);
|
||||
// }
|
||||
// } else if (complianceLevel <= ClassFileConstants.JDK1_7) {
|
||||
// // java 7 supports Unicode 6
|
||||
// if (Tables7 == null) {
|
||||
// initializeTable17();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables7[PART_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables7[PART_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables7[PART_INDEX][2], codePoint & 0xFFFF);
|
||||
// case 14 :
|
||||
// return isBitSet(Tables7[PART_INDEX][3], codePoint & 0xFFFF);
|
||||
// }
|
||||
// } else {
|
||||
// // java 7 supports Unicode 6.2
|
||||
// if (Tables8 == null) {
|
||||
// initializeTable18();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables8[PART_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables8[PART_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables8[PART_INDEX][2], codePoint & 0xFFFF);
|
||||
// case 14 :
|
||||
// return isBitSet(Tables8[PART_INDEX][3], codePoint & 0xFFFF);
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param high
|
||||
// * @param low
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierPart(long complianceLevel, char high, char low) {
|
||||
// return isJavaIdentifierPart(complianceLevel, toCodePoint(high, low));
|
||||
//}
|
||||
///**
|
||||
// * @param c
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierStart(char c) {
|
||||
// if (c < MAX_OBVIOUS) {
|
||||
// return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_IDENT_START) != 0;
|
||||
// }
|
||||
// return Character.isJavaIdentifierStart(c);
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param c
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierStart(long complianceLevel, char c) {
|
||||
// if (c < MAX_OBVIOUS) {
|
||||
// return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_IDENT_START) != 0;
|
||||
// }
|
||||
// return ScannerHelper.isJavaIdentifierStart(complianceLevel, (int) c);
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param high
|
||||
// * @param low
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierStart(long complianceLevel, char high, char low) {
|
||||
// return isJavaIdentifierStart(complianceLevel, toCodePoint(high, low));
|
||||
//}
|
||||
///**
|
||||
// * @param complianceLevel
|
||||
// * @param codePoint
|
||||
// * @return
|
||||
// */
|
||||
//public static boolean isJavaIdentifierStart(long complianceLevel, int codePoint) {
|
||||
// if (complianceLevel <= ClassFileConstants.JDK1_6) {
|
||||
// if (Tables == null) {
|
||||
// initializeTable();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables[START_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables[START_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables[START_INDEX][2], codePoint & 0xFFFF);
|
||||
// }
|
||||
// } else if (complianceLevel <= ClassFileConstants.JDK1_7) {
|
||||
// // java 7 supports Unicode 6
|
||||
// if (Tables7 == null) {
|
||||
// initializeTable17();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables7[START_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables7[START_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables7[START_INDEX][2], codePoint & 0xFFFF);
|
||||
// }
|
||||
// } else {
|
||||
// // java 7 supports Unicode 6
|
||||
// if (Tables8 == null) {
|
||||
// initializeTable18();
|
||||
// }
|
||||
// switch((codePoint & 0x1F0000) >> 16) {
|
||||
// case 0 :
|
||||
// return isBitSet(Tables8[START_INDEX][0], codePoint & 0xFFFF);
|
||||
// case 1 :
|
||||
// return isBitSet(Tables8[START_INDEX][1], codePoint & 0xFFFF);
|
||||
// case 2 :
|
||||
// return isBitSet(Tables8[START_INDEX][2], codePoint & 0xFFFF);
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
//private static int toCodePoint(char high, char low) {
|
||||
// return (high - Scanner.HIGH_SURROGATE_MIN_VALUE) * 0x400 + (low - Scanner.LOW_SURROGATE_MIN_VALUE) + 0x10000;
|
||||
//}
|
||||
//public static boolean isDigit(char c) throws InvalidInputException {
|
||||
// if(c < ScannerHelper.MAX_OBVIOUS) {
|
||||
// return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_DIGIT) != 0;
|
||||
// }
|
||||
// if (Character.isDigit(c)) {
|
||||
// throw new InvalidStateException(Scanner.INVALID_DIGIT);
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
public static int digit(char c, int radix) {
|
||||
if (c < ScannerHelper.MAX_OBVIOUS) {
|
||||
switch(radix) {
|
||||
case 8 :
|
||||
if (c >= 48 && c <= 55) {
|
||||
return c - 48;
|
||||
}
|
||||
return -1;
|
||||
case 10 :
|
||||
if (c >= 48 && c <= 57) {
|
||||
return c - 48;
|
||||
}
|
||||
return -1;
|
||||
case 16 :
|
||||
if (c >= 48 && c <= 57) {
|
||||
return c - 48;
|
||||
}
|
||||
if (c >= 65 && c <= 70) {
|
||||
return c - 65 + 10;
|
||||
}
|
||||
if (c >= 97 && c <= 102) {
|
||||
return c - 97 + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return Character.digit(c, radix);
|
||||
}
|
||||
public static int getNumericValue(char c) {
|
||||
if (c < ScannerHelper.MAX_OBVIOUS) {
|
||||
switch(ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c]) {
|
||||
case C_DIGIT :
|
||||
return c - '0';
|
||||
case C_LOWER_LETTER :
|
||||
return 10 + c - 'a';
|
||||
case C_UPPER_LETTER :
|
||||
return 10 + c - 'A';
|
||||
}
|
||||
}
|
||||
return Character.getNumericValue(c);
|
||||
}
|
||||
public static int getHexadecimalValue(char c) {
|
||||
switch(c) {
|
||||
case '0' :
|
||||
return 0;
|
||||
case '1' :
|
||||
return 1;
|
||||
case '2' :
|
||||
return 2;
|
||||
case '3' :
|
||||
return 3;
|
||||
case '4' :
|
||||
return 4;
|
||||
case '5' :
|
||||
return 5;
|
||||
case '6' :
|
||||
return 6;
|
||||
case '7' :
|
||||
return 7;
|
||||
case '8' :
|
||||
return 8;
|
||||
case '9' :
|
||||
return 9;
|
||||
case 'A' :
|
||||
case 'a' :
|
||||
return 10;
|
||||
case 'B' :
|
||||
case 'b' :
|
||||
return 11;
|
||||
case 'C' :
|
||||
case 'c' :
|
||||
return 12;
|
||||
case 'D' :
|
||||
case 'd' :
|
||||
return 13;
|
||||
case 'E' :
|
||||
case 'e' :
|
||||
return 14;
|
||||
case 'F' :
|
||||
case 'f' :
|
||||
return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public static char toUpperCase(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
if ((ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_UPPER_LETTER) != 0) {
|
||||
return c;
|
||||
} else if ((ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_LOWER_LETTER) != 0) {
|
||||
return (char) (c - 32);
|
||||
}
|
||||
}
|
||||
return Character.toUpperCase(c);
|
||||
}
|
||||
public static char toLowerCase(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
if ((ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_LOWER_LETTER) != 0) {
|
||||
return c;
|
||||
} else if ((ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_UPPER_LETTER) != 0) {
|
||||
return (char) (32 + c);
|
||||
}
|
||||
}
|
||||
return Character.toLowerCase(c);
|
||||
}
|
||||
public static boolean isLowerCase(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_LOWER_LETTER) != 0;
|
||||
}
|
||||
return Character.isLowerCase(c);
|
||||
}
|
||||
public static boolean isUpperCase(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_UPPER_LETTER) != 0;
|
||||
}
|
||||
return Character.isUpperCase(c);
|
||||
}
|
||||
/**
|
||||
* Include also non JLS whitespaces.
|
||||
*
|
||||
* return true if Character.isWhitespace(c) would return true
|
||||
*/
|
||||
public static boolean isWhitespace(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & ScannerHelper.C_SPACE) != 0;
|
||||
}
|
||||
return Character.isWhitespace(c);
|
||||
}
|
||||
public static boolean isLetter(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & (ScannerHelper.C_UPPER_LETTER | ScannerHelper.C_LOWER_LETTER)) != 0;
|
||||
}
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
public static boolean isLetterOrDigit(char c) {
|
||||
if (c < MAX_OBVIOUS) {
|
||||
return (ScannerHelper.OBVIOUS_IDENT_CHAR_NATURES[c] & (ScannerHelper.C_UPPER_LETTER | ScannerHelper.C_LOWER_LETTER | ScannerHelper.C_DIGIT)) != 0;
|
||||
}
|
||||
return Character.isLetterOrDigit(c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
public class DefaultJavaProjectFinder implements JavaProjectFinder {
|
||||
|
||||
private final IJavaProjectFinderStrategy[] strategies;
|
||||
|
||||
public DefaultJavaProjectFinder(IJavaProjectFinderStrategy[] strategies) {
|
||||
this.strategies = strategies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaProject find(IDocument d) {
|
||||
for (IJavaProjectFinderStrategy strategy : strategies) {
|
||||
try {
|
||||
IJavaProject project = strategy.find(d);
|
||||
if (project != null) {
|
||||
return project;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
* Strategy foe finding Java project for a document
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IJavaProjectFinderStrategy {
|
||||
|
||||
IJavaProject find(IDocument document) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface JavaProjectFinder {
|
||||
IJavaProject find(IDocument doc);
|
||||
}
|
||||
Reference in New Issue
Block a user