This is an automated email from the ASF dual-hosted git repository. jlahoda pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 5f675e8 Eliminating remaining usages of old javadoc API and implementation 5f675e8 is described below commit 5f675e88a3ae3fee652332f9faf2f1985508c272 Author: Jan Lahoda <lah...@gmail.com> AuthorDate: Tue Apr 9 21:48:57 2019 +0200 Eliminating remaining usages of old javadoc API and implementation Includes patch by arusinha to update nb-javac in libs.javacapi/libs.javacimpl to nb-javac without the old javadoc API. --- .../nbproject/project.properties | 2 - enterprise/web.jsf/nbproject/project.properties | 1 - .../websvc/design/javamodel/JavadocModel.java | 33 -- .../modules/websvc/design/javamodel/Utils.java | 37 +- .../netbeans/api/java/source/ElementUtilities.java | 42 -- .../netbeans/modules/java/source/JavadocEnv.java | 438 --------------------- .../java/source/indexing/VanillaCompileWorker.java | 16 +- .../modules/java/source/parsing/JavacParser.java | 21 +- .../nbjavac/parsing/ContextEnhancerImpl.java | 5 +- .../netbeans/modules/javadoc/hints/Analyzer.java | 92 +++-- .../modules/javadoc/hints/JavadocUtilities.java | 23 +- .../modules/javadoc/hints/Analyzer2Test.java | 19 +- .../lib/nbjavac/services/NBClassWriter.java | 2 - .../lib/nbjavac/services/NBJavadocClassFinder.java | 59 --- .../lib/nbjavac/services/NBJavadocEnter.java | 94 ----- .../lib/nbjavac/services/NBJavadocMemberEnter.java | 102 ----- .../services/{NBMessager.java => NBLog.java} | 36 +- .../lib/nbjavac/services/NBMemberEnter.java | 18 +- .../netbeans/lib/nbjavac/services/NBAttrTest.java | 2 +- .../lib/nbjavac/services/NBClassWriterTest.java | 4 +- .../netbeans/lib/nbjavac/services/Utilities.java | 5 +- java/libs.javacapi/external/binaries-list | 2 +- java/libs.javacapi/nbproject/project.xml | 1 - java/libs.javacimpl/external/binaries-list | 2 +- .../IntroduceLocalExtensionTransformer.java | 14 +- .../java/plugins/MoveMembersTransformer.java | 36 +- .../refactoring/java/ui/ChangeParametersPanel.java | 6 +- .../java/ui/IntroduceParameterPanel.java | 6 +- .../modules/java/hints/spiimpl/Utilities.java | 21 +- .../netbeans/spi/java/hints/JavaFixUtilities.java | 15 +- nbbuild/build.xml | 5 +- nbbuild/templates/projectized.xml | 3 + 32 files changed, 205 insertions(+), 957 deletions(-) diff --git a/enterprise/j2ee.ejbverification/nbproject/project.properties b/enterprise/j2ee.ejbverification/nbproject/project.properties index 2804a56..4afe2d4 100644 --- a/enterprise/j2ee.ejbverification/nbproject/project.properties +++ b/enterprise/j2ee.ejbverification/nbproject/project.properties @@ -19,7 +19,5 @@ javac.source=1.7 # requires nb.javac for compiling of tests on Mac requires.nb.javac=true -# 183728: hack to make java.hints compilable even though javac impl is on the bootclasspath: -bootclasspath.prepend=${nb_all}/libs.javacapi/external/nb-javac-api.jar${path.separator}${nb_all}/libs.javacimpl/external/nb-javac-impl.jar # JavaEE API classes test.unit.cp.extra=${nb_all}/enterprise/javaee7.api/external/javaee-api-7.0.jar diff --git a/enterprise/web.jsf/nbproject/project.properties b/enterprise/web.jsf/nbproject/project.properties index 74718b9..ce2b934 100644 --- a/enterprise/web.jsf/nbproject/project.properties +++ b/enterprise/web.jsf/nbproject/project.properties @@ -33,4 +33,3 @@ test.config.stableBTD.excludes=\ **/SyncUpdateTest.class requires.nb.javac=true -bootclasspath.prepend=${nb_all}/libs.javacapi/external/nb-javac-api.jar${path.separator}${nb_all}/libs.javacimpl/external/nb-javac-impl.jar diff --git a/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/JavadocModel.java b/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/JavadocModel.java index 08c4183..cc6260b 100644 --- a/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/JavadocModel.java +++ b/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/JavadocModel.java @@ -50,39 +50,6 @@ public class JavadocModel { this.text=text; } - public List<String> getInlineJavadoc() { - return inlineJavadoc; - } - - void setInlineJavadoc(List<String> inlineJavadoc) { - this.inlineJavadoc = inlineJavadoc; - } - - public List<String> getParamJavadoc() { - return paramJavadoc; - } - - void setParamJavadoc(List<String> paramJavadoc) { - this.paramJavadoc = paramJavadoc; - } - - public List<String> getThrowsJavadoc() { - return throwsJavadoc; - } - - void setThrowsJavadoc(List<String> throwsJavadoc) { - this.throwsJavadoc = throwsJavadoc; - } - - public String getReturnJavadoc() { - return returnJavadoc; - } - - void setReturnJavadoc(String returnJavadoc) { - this.returnJavadoc = returnJavadoc; - } - - public boolean isEqualTo(JavadocModel model) { if (!Utils.isEqualTo(text,model.text)) return false; return true; diff --git a/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/Utils.java b/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/Utils.java index ff6e694..5367157 100644 --- a/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/Utils.java +++ b/enterprise/websvc.design/src/org/netbeans/modules/websvc/design/javamodel/Utils.java @@ -94,8 +94,7 @@ import org.openide.util.Mutex; import org.openide.util.MutexException; import org.openide.util.NbBundle; -import com.sun.javadoc.Doc; -import com.sun.javadoc.Tag; +import com.sun.source.doctree.DocCommentTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; @@ -505,38 +504,10 @@ public class Utils { ExecutableElement methodEl, MethodModel methodModel ) { // populate javadoc - Doc javadoc = controller.getElementUtilities().javaDocFor(methodEl); + DocCommentTree javadoc = controller.getDocTrees().getDocCommentTree(methodEl); if (javadoc!=null) { //methodModel.setJavadoc(javadoc.getRawCommentText()); - JavadocModel javadocModel = new JavadocModel(javadoc.getRawCommentText()); - // @param part - Tag[] paramTags = javadoc.tags("@param"); //NOI18N - List<String> paramJavadoc = new ArrayList<String>(); - for (Tag paramTag:paramTags) { - paramJavadoc.add(paramTag.text()); - } - javadocModel.setParamJavadoc(paramJavadoc); - - // @return part - Tag[] returnTags = javadoc.tags("@return"); //NOI18N - if (returnTags.length>0) { - javadocModel.setReturnJavadoc(returnTags[0].text()); - } - // @throws part - Tag[] throwsTags = javadoc.tags("@throws"); //NOI18N - List<String> throwsJavadoc = new ArrayList<String>(); - for (Tag throwsTag:throwsTags) { - throwsJavadoc.add(throwsTag.text()); - } - javadocModel.setThrowsJavadoc(throwsJavadoc); - - // rest part - Tag[] inlineTags = javadoc.inlineTags(); //NOI18N - List<String> inlineJavadoc = new ArrayList<String>(); - for (Tag inlineTag:inlineTags) { - throwsJavadoc.add(inlineTag.text()); - } - javadocModel.setInlineJavadoc(inlineJavadoc); + JavadocModel javadocModel = new JavadocModel(javadoc.toString()); methodModel.setJavadoc(javadocModel); } } @@ -801,7 +772,7 @@ public class Utils { return; } - Doc javadoc = workingCopy.getElementUtilities().javaDocFor(method); + DocCommentTree javadoc = workingCopy.getDocTrees().getDocCommentTree(method); if ( javadoc != null ){ make.removeComment(newMethod, 0, true); } diff --git a/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java b/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java index 665c0e7..0c1737d 100644 --- a/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java +++ b/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java @@ -18,7 +18,6 @@ */ package org.netbeans.api.java.source; -import com.sun.javadoc.Doc; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Scope; import com.sun.source.util.DocTrees; @@ -47,7 +46,6 @@ import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.model.JavacTypes; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Names; -import com.sun.tools.javadoc.main.DocEnv; import java.util.ArrayDeque; import java.util.ArrayList; @@ -88,7 +86,6 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.modules.java.source.builder.ElementsService; -import org.netbeans.modules.java.source.JavadocEnv; import org.netbeans.modules.java.source.base.SourceLevelUtils; import org.openide.util.Parameters; @@ -208,45 +205,6 @@ public final class ElementUtilities { } } - /**Get javadoc for given element. - * @deprecated The new DocTree API should be used to traverse Javadoc comments. - * Use {@link DocTrees#getDocCommentTree(javax.lang.model.element.Element)} instead. - */ - @Deprecated - public Doc javaDocFor(Element element) { - if (element != null) { - DocEnv env = DocEnv.instance(ctx); - switch (element.getKind()) { - case ANNOTATION_TYPE: - case CLASS: - case ENUM: - case INTERFACE: - return env.getClassDoc((ClassSymbol)element); - case ENUM_CONSTANT: - case FIELD: - return env.getFieldDoc((VarSymbol)element); - case METHOD: - if (((MethodSymbol)element).enclClass().getKind() == ElementKind.ANNOTATION_TYPE) - return env.getAnnotationTypeElementDoc((MethodSymbol)element); - return env.getMethodDoc((MethodSymbol)element); - case CONSTRUCTOR: - return env.getConstructorDoc((MethodSymbol)element); - case PACKAGE: - return env.getPackageDoc((PackageSymbol)element); - } - } - return null; - } - - /**Find a {@link Element} corresponding to a given {@link Doc}. - * @deprecated The new DocTree API should be used to traverse Javadoc comments. - * Use {@link DocTrees#getElement(com.sun.source.util.DocTreePath)} instead. - */ - @Deprecated - public Element elementFor(Doc doc) { - return (doc instanceof JavadocEnv.ElementHolder) ? ((JavadocEnv.ElementHolder)doc).getElement() : null; - } - /** * Returns all members of a type, whether inherited or * declared directly. For a class the result also includes its diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocEnv.java b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocEnv.java deleted file mode 100644 index 1de5a75..0000000 --- a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocEnv.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.modules.java.source; - -import com.sun.javadoc.ClassDoc; -import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.code.Symbol.MethodSymbol; -import com.sun.tools.javac.code.Symbol.PackageSymbol; -import com.sun.tools.javac.code.Symbol.TypeSymbol; -import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Name; -import com.sun.tools.javac.util.Names; -import com.sun.tools.javadoc.main.AnnotationTypeDocImpl; -import com.sun.tools.javadoc.main.AnnotationTypeElementDocImpl; -import com.sun.tools.javadoc.main.ClassDocImpl; -import com.sun.tools.javadoc.main.ConstructorDocImpl; -import com.sun.tools.javadoc.main.DocEnv; -import com.sun.tools.javadoc.main.ExecutableMemberDocImpl; -import com.sun.tools.javadoc.main.FieldDocImpl; -import com.sun.tools.javadoc.main.MethodDocImpl; -import com.sun.tools.javadoc.main.ModifierFilter; -import com.sun.tools.javadoc.main.PackageDocImpl; -import com.sun.tools.javadoc.main.ProgramElementDocImpl; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.lang.model.element.Element; -import org.netbeans.api.java.source.Task; -import org.netbeans.api.java.source.ClasspathInfo; -import org.netbeans.api.java.source.CompilationController; -import org.netbeans.api.java.source.ElementHandle; -import org.netbeans.api.java.source.JavaSource; -import org.netbeans.api.java.source.JavaSource.Phase; -import org.netbeans.api.java.source.SourceUtils; -import org.openide.filesystems.FileObject; -import org.openide.util.Exceptions; - -/** - * - * @author Dusan Balek - */ -public class JavadocEnv extends DocEnv { - - public static void preRegister(final Context context, final ClasspathInfo cpInfo) { - context.put(docEnvKey, new Context.Factory<DocEnv>() { - public DocEnv make(Context c) { - return new JavadocEnv(c, cpInfo); - } - }); - } - - private ClasspathInfo cpInfo; - private Context ctx; - - private JavadocEnv(Context context, ClasspathInfo cpInfo) { - super(context); - this.ctx = context; - this.cpInfo = cpInfo; - this.showAccess = new ModifierFilter(ModifierFilter.ALL_ACCESS); - this.legacyDoclet = false; - } - - @Override - public ClassDocImpl getClassDoc(ClassSymbol clazz) { - if (clazz.type.hasTag(TypeTag.UNKNOWN)) { - return null; - } - ClassDocImpl result = classMap.get(clazz); - if (result != null) return result; - if (isAnnotationType(clazz)) { - result = new JavadocAnnotation(this, clazz); - } else { - result = new JavadocClass(this, clazz); - } - classMap.put(clazz, result); - return result; - } - - @Override - protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) { - if (clazz.type.hasTag(TypeTag.UNKNOWN)) { - return; - } - ClassDocImpl result = classMap.get(clazz); - if (result != null) { - if (treePath != null) setTreePath(result, treePath); - return; - } - if (isAnnotationType((JCClassDecl)treePath.getLeaf())) { // flags of clazz may not yet be set - result = new JavadocAnnotation(this, clazz, treePath); - } else { - result = new JavadocClass(this, clazz, treePath); - } - classMap.put(clazz, result); - } - - @Override - public FieldDocImpl getFieldDoc(VarSymbol var) { - FieldDocImpl result = fieldMap.get(var); - if (result != null) return result; - result = new JavadocField(this, var); - fieldMap.put(var, result); - return result; - } - - @Override - protected void makeFieldDoc(VarSymbol var, TreePath treePath) { - FieldDocImpl result = fieldMap.get(var); - if (result != null) { - if (treePath != null) setTreePath(result, treePath); - } else { - result = new JavadocField(this, var, treePath); - fieldMap.put(var, result); - } - } - - @Override - public MethodDocImpl getMethodDoc(MethodSymbol meth) { - ExecutableMemberDocImpl docImpl = methodMap.get(meth); - if (docImpl != null && !docImpl.isMethod()) - return null; - MethodDocImpl result = (MethodDocImpl)docImpl; - if (result != null) return result; - result = new JavadocMethod(this, meth); - methodMap.put(meth, result); - return result; - } - - @Override - protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) { - MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) setTreePath(result, treePath); - } else { - result = new JavadocMethod(this, meth, treePath); - methodMap.put(meth, result); - } - } - - @Override - public ConstructorDocImpl getConstructorDoc(MethodSymbol meth) { - ExecutableMemberDocImpl docImpl = methodMap.get(meth); - if (docImpl != null && !docImpl.isConstructor()) - return null; - ConstructorDocImpl result = (ConstructorDocImpl)docImpl; - if (result != null) return result; - result = new JavadocConstructor(this, meth); - methodMap.put(meth, result); - return result; - } - - @Override - protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) { - ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) setTreePath(result, treePath); - } else { - result = new JavadocConstructor(this, meth, treePath); - methodMap.put(meth, result); - } - } - - @Override - public AnnotationTypeElementDocImpl getAnnotationTypeElementDoc(MethodSymbol meth) { - ExecutableMemberDocImpl docImpl = methodMap.get(meth); - if (docImpl != null && !docImpl.isAnnotationTypeElement()) - return null; - AnnotationTypeElementDocImpl result = (AnnotationTypeElementDocImpl)docImpl; - if (result != null) return result; - result = new JavadocAnnotationTypeElement(this, meth); - methodMap.put(meth, result); - return result; - } - - @Override - protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) { - AnnotationTypeElementDocImpl result = (AnnotationTypeElementDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) setTreePath(result, treePath); - } else { - result = new JavadocAnnotationTypeElement(this, meth, treePath); - methodMap.put(meth, result); - } - } - - private void setTreePath(ProgramElementDocImpl pe, TreePath treePath) { - try { - Method setTreePath = ProgramElementDocImpl.class.getDeclaredMethod("setTreePath", TreePath.class); - setTreePath.setAccessible(true); - setTreePath.invoke(pe, treePath); - } catch (Throwable ex) { - Logger.getLogger(JavadocEnv.class.getName()).log(Level.FINE, null, ex); - } - } - - /** - * Return the AnnotationTypeElementDoc for a MethodSymbol. - * Should be called only on symbols representing annotation type elements. - */ - @Override - public PackageDocImpl getPackageDoc(PackageSymbol pack) { - PackageDocImpl result = packageMap.get(pack); - if (result != null) return result; - result = new JavaDocPackage(this, pack, ctx); - packageMap.put(pack, result); - return result; - } - - @Override - public ClassDocImpl lookupClass(String name) { - ClassDocImpl cls = super.lookupClass(name); - if (cls == null && name != null && !name.isEmpty()) - cls = loadClass(name); - return cls; - } - - public interface ElementHolder { - Element getElement(); - } - - private String getRawCommentFor(Element element) { - try { - FileObject fo = SourceUtils.getFile(element, cpInfo); - if (fo != null) { - JavaSource js = JavaSource.forFileObject(fo); - if (js != null) { - final String[] ret = new String[1]; - final ElementHandle<? extends Element> handle = ElementHandle.create(element); - js.runUserActionTask(new Task<CompilationController>() { - public void run(CompilationController controller) throws Exception { - controller.toPhase(Phase.ELEMENTS_RESOLVED); - Element e = handle.resolve(controller); - if (e != null) - ret[0] = controller.getElements().getDocComment(e); - } - },true); - return ret[0] != null ? ret[0] : ""; //NOI18N - } - } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - return ""; //NOI18N - } - - private class JavadocClass extends ClassDocImpl implements ElementHolder { - - private JavadocClass(DocEnv env, ClassSymbol sym) { - super(env, sym); - } - - private JavadocClass(DocEnv env, ClassSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return tsym; - } - } - - private class JavadocAnnotation extends AnnotationTypeDocImpl implements ElementHolder { - - private JavadocAnnotation(DocEnv env, ClassSymbol sym) { - super(env, sym); - } - - private JavadocAnnotation(DocEnv env, ClassSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return tsym; - } - } - - private class JavadocField extends FieldDocImpl implements ElementHolder { - - private JavadocField(DocEnv env, VarSymbol sym) { - super(env, sym); - } - - private JavadocField(DocEnv env, VarSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return sym; - } - } - - private class JavadocMethod extends MethodDocImpl implements ElementHolder { - - private JavadocMethod(DocEnv env, MethodSymbol sym) { - super(env, sym); - } - - private JavadocMethod(DocEnv env, MethodSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return sym; - } - } - - private class JavadocConstructor extends ConstructorDocImpl implements ElementHolder { - - private JavadocConstructor(DocEnv env, MethodSymbol sym) { - super(env, sym); - } - - private JavadocConstructor(DocEnv env, MethodSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return sym; - } - } - - private class JavadocAnnotationTypeElement extends AnnotationTypeElementDocImpl implements ElementHolder { - - private JavadocAnnotationTypeElement(DocEnv env, MethodSymbol sym) { - super(env, sym); - } - - private JavadocAnnotationTypeElement(DocEnv env, MethodSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - @Override - protected String documentation() { - if (documentation == null) { - setRawCommentText(getRawCommentFor(getElement())); - } - return documentation; - } - - public Element getElement() { - return sym; - } - } - - private class JavaDocPackage extends PackageDocImpl implements ElementHolder { - - private JavaDocPackage(DocEnv env, PackageSymbol sym, Context ctx) { - super(env, sym); - } - - public ClassDoc findClass(String className) { - Names nameTable = Names.instance(ctx); - StringTokenizer st = new StringTokenizer(className, "."); //NOI18N - TypeSymbol s = sym; - while(s != null && st.hasMoreTokens()) { - Name clsName = nameTable.fromString(st.nextToken()); - TypeSymbol ts = null; - for (Symbol symbol : s.members().getSymbolsByName(clsName)) { - if (symbol.kind == Kinds.Kind.TYP && (symbol.flags_field & Flags.SYNTHETIC) == 0) { - ts = (TypeSymbol)symbol; - break; - } - } - s = ts; - } - return s instanceof ClassSymbol ? env.getClassDoc((ClassSymbol)s) : null; - } - - public Element getElement() { - return sym; - } - } -} diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java index fcf16a2..a7f4cb0 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java @@ -66,6 +66,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Field; import java.net.URL; import java.util.*; import java.util.Map.Entry; @@ -598,8 +599,19 @@ final class VanillaCompileWorker extends CompileWorker { Type.WildcardType wt = ((Type.WildcardType) t); wt.type = error2Object(wt.type); TypeVar tv = wt.bound; - tv.bound = error2Object(tv.bound); - tv.lower = error2Object(tv.lower); + if (tv != null) { + String[] boundNames = {"bound", "_bound"}; + for (String boundName : boundNames) { + try { + Field bound = tv.getClass().getDeclaredField(boundName); + bound.setAccessible(true); + bound.set(tv, error2Object((Type) bound.get(tv))); + } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) { + JavaIndex.LOG.log(Level.FINEST, null, ex); + } + } + tv.lower = error2Object(tv.lower); + } break; } } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java index b6e8017..10dba1d 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java @@ -88,7 +88,6 @@ import org.netbeans.lib.editor.util.swing.PositionRegion; import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation; import org.netbeans.modules.java.source.JavaFileFilterQuery; import org.netbeans.modules.java.source.JavaSourceAccessor; -import org.netbeans.modules.java.source.JavadocEnv; import org.netbeans.modules.java.source.PostFlowAnalysis; import org.netbeans.modules.java.source.indexing.APTUtils; import org.netbeans.modules.java.source.indexing.FQN2Files; @@ -97,14 +96,11 @@ import org.netbeans.lib.nbjavac.services.NBClassFinder; import org.netbeans.lib.nbjavac.services.NBClassReader; import org.netbeans.lib.nbjavac.services.NBEnter; import org.netbeans.lib.nbjavac.services.NBJavaCompiler; -import org.netbeans.lib.nbjavac.services.NBJavadocEnter; -import org.netbeans.lib.nbjavac.services.NBJavadocMemberEnter; import org.netbeans.lib.nbjavac.services.NBMemberEnter; import org.netbeans.lib.nbjavac.services.NBParserFactory; import org.netbeans.lib.nbjavac.services.NBClassWriter; import org.netbeans.lib.nbjavac.services.NBJavacTrees; -import org.netbeans.lib.nbjavac.services.NBJavadocClassFinder; -import org.netbeans.lib.nbjavac.services.NBMessager; +import org.netbeans.lib.nbjavac.services.NBLog; import org.netbeans.lib.nbjavac.services.NBResolve; import org.netbeans.lib.nbjavac.services.NBTreeMaker; import org.netbeans.modules.java.source.base.SourceLevelUtils; @@ -893,7 +889,7 @@ public class JavacParser extends Parser { Context context = new Context(); //need to preregister the Messages here, because the getTask below requires Log instance: - NBMessager.preRegister(context, null, DEV_NULL, DEV_NULL, DEV_NULL); + NBLog.preRegister(context, DEV_NULL, DEV_NULL, DEV_NULL); JavacTaskImpl task = (JavacTaskImpl)JavacTool.create().getTask(null, ClasspathInfoAccessor.getINSTANCE().createFileManager(cpInfo, validatedSourceLevel.name), diagnosticListener, options, files.iterator().hasNext() ? null : Arrays.asList("java.lang.Object"), files, @@ -921,14 +917,10 @@ public class JavacParser extends Parser { NBJavacTrees.preRegister(context); if (!backgroundCompilation) { JavacFlowListener.preRegister(context, task); - NBJavadocEnter.preRegister(context); - NBJavadocMemberEnter.preRegister(context); - JavadocEnv.preRegister(context, cpInfo); NBResolve.preRegister(context); - } else { - NBEnter.preRegister(context); - NBMemberEnter.preRegister(context); } + NBEnter.preRegister(context); + NBMemberEnter.preRegister(context, backgroundCompilation); TIME_LOGGER.log(Level.FINE, "JavaC", context); return task; } @@ -1345,10 +1337,7 @@ public class JavacParser extends Parser { public static class VanillaJavacContextEnhancer implements ContextEnhancer { @Override public void enhance(Context context, boolean backgroundCompilation) { - if (!backgroundCompilation) - NBJavadocClassFinder.preRegister(context); - else - NBClassFinder.preRegister(context); + NBClassFinder.preRegister(context); NBJavaCompiler.preRegister(context); } } diff --git a/java/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/ContextEnhancerImpl.java b/java/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/ContextEnhancerImpl.java index e596ccb..fbe4108 100644 --- a/java/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/ContextEnhancerImpl.java +++ b/java/java.source.nbjavac/src/org/netbeans/modules/java/source/nbjavac/parsing/ContextEnhancerImpl.java @@ -19,7 +19,7 @@ package org.netbeans.modules.java.source.nbjavac.parsing; import com.sun.tools.javac.util.Context; -import com.sun.tools.javadoc.main.JavadocClassFinder; +import org.netbeans.lib.nbjavac.services.NBClassFinder; import org.netbeans.modules.java.source.parsing.JavacParser.ContextEnhancer; import org.openide.util.lookup.ServiceProvider; @@ -32,8 +32,7 @@ public class ContextEnhancerImpl implements ContextEnhancer { @Override public void enhance(Context context, boolean backgroundCompilation) { - if (!backgroundCompilation) - JavadocClassFinder.preRegister(context); + NBClassFinder.preRegister(context); } } diff --git a/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java b/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java index ab8f293..9ef27aa 100644 --- a/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java +++ b/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java @@ -19,10 +19,6 @@ package org.netbeans.modules.javadoc.hints; -import com.sun.javadoc.MethodDoc; -import com.sun.javadoc.ParamTag; -import com.sun.javadoc.ThrowsTag; -import com.sun.javadoc.Type; import com.sun.source.doctree.AttributeTree; import com.sun.source.doctree.AuthorTree; import com.sun.source.doctree.CommentTree; @@ -55,12 +51,14 @@ import com.sun.source.doctree.VersionTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodTree; +import com.sun.source.tree.ThrowTree; import com.sun.source.tree.Tree; import com.sun.source.util.DocSourcePositions; import com.sun.source.util.DocTreePath; import com.sun.source.util.DocTreePathScanner; import com.sun.source.util.TreePath; import com.sun.tools.doclint.HtmlTag; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Deque; @@ -75,6 +73,7 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Name; +import javax.lang.model.element.QualifiedNameable; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -82,7 +81,11 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.DocTreePathHandle; +import org.netbeans.api.java.source.ElementHandle; import org.netbeans.api.java.source.ElementUtilities; +import org.netbeans.api.java.source.JavaSource; +import org.netbeans.api.java.source.JavaSource.Phase; +import org.netbeans.api.java.source.SourceUtils; import static org.netbeans.modules.javadoc.hints.Bundle.*; import static org.netbeans.modules.javadoc.hints.JavadocUtilities.resolveSourceVersion; import org.netbeans.spi.editor.hints.ErrorDescription; @@ -172,19 +175,6 @@ final class Analyzer extends DocTreePathScanner<Void, List<ErrorDescription>> { case METHOD: { ExecutableElement method = (ExecutableElement) currentElement; ElementUtilities elUtils = javac.getElementUtilities(); - ExecutableElement overridden = method; - do { - MethodDoc methodDoc = (MethodDoc) elUtils.javaDocFor(overridden); - if(methodDoc != null) { - for (ParamTag paramTag : methodDoc.paramTags()) { - inheritedParams.add(paramTag.parameterName()); - } - for (ParamTag paramTag : methodDoc.typeParamTags()) { - inheritedTypeParams.add(paramTag.parameterName()); - } - } - - } while((overridden = elUtils.getOverriddenMethod(overridden)) != null); if(ctx.isCanceled()) { break; } TypeElement typeElement = elUtils.enclosingTypeElement(currentElement); findInheritedParams(method, typeElement, inheritedParams, inheritedTypeParams, inheritedThrows); @@ -751,31 +741,57 @@ final class Analyzer extends DocTreePathScanner<Void, List<ErrorDescription>> { private void findInheritedParams(ExecutableElement method, TypeElement typeElement, Set<String> inheritedParams, Set<String> inheritedTypeParams, Set<String> inheritedThrows) { if(typeElement == null) return; - for (TypeMirror typeMirror : typeElement.getInterfaces()) { - for (Element el : javac.getElementUtilities().getMembers(typeMirror, new ElementUtilities.ElementAcceptor() { + List<TypeMirror> superTypes = new ArrayList<>(); - @Override - public boolean accept(Element e, TypeMirror type) { - return e.getKind() == ElementKind.METHOD; - } - })) { + superTypes.add(typeElement.getSuperclass()); + superTypes.addAll(typeElement.getInterfaces()); + + for (TypeMirror typeMirror : superTypes) { + for (Element el : javac.getElementUtilities().getMembers(typeMirror, (e, type) -> e.getKind() == ElementKind.METHOD)) { if(ctx.isCanceled()) { return; } if(javac.getElements().overrides(method, (ExecutableElement) el, typeElement)) { - MethodDoc methodDoc = (MethodDoc) javac.getElementUtilities().javaDocFor(el); - if(methodDoc != null) { - for (ParamTag paramTag : methodDoc.paramTags()) { - inheritedParams.add(paramTag.parameterName()); - } - for (ParamTag paramTag : methodDoc.typeParamTags()) { - inheritedTypeParams.add(paramTag.parameterName()); - } - for (ThrowsTag throwsTag : methodDoc.throwsTags()) { - Type exceptionType = throwsTag.exceptionType(); - if(exceptionType != null) { - inheritedThrows.add(exceptionType.qualifiedTypeName()); + ElementHandle<ExecutableElement> overriddenMethod = ElementHandle.create((ExecutableElement) el); + FileObject source = SourceUtils.getFile(overriddenMethod, ctx.getInfo().getClasspathInfo()); + if (source == null) { + continue; + } + try { + JavaSource.forFileObject(source).runUserActionTask(cc -> { + cc.toPhase(Phase.ELEMENTS_RESOLVED); + if (ctx.isCanceled()) { + return ; //cancel } - } - returnTypeFound |= methodDoc.tags("return").length > 0; + ExecutableElement m = overriddenMethod.resolve(cc); + TreePath tp = m != null ? cc.getTrees().getPath(m) : null; + if (tp == null) { + return ; //TODO: log??? + } + DocCommentTree methodDoc = cc.getDocTrees().getDocCommentTree(tp); + if(methodDoc != null) { + for (DocTree tag : methodDoc.getBlockTags()) { + switch (tag.getKind()) { + case PARAM: + String name = ((ParamTree) tag).getName().getName().toString(); + if (((ParamTree) tag).isTypeParameter()) { + inheritedTypeParams.add(name); + } else { + inheritedParams.add(name); + } + break; + case THROWS: + Element thrownType = cc.getDocTrees().getElement(new DocTreePath(new DocTreePath(new DocTreePath(tp, methodDoc), tag), ((ThrowsTree) tag).getExceptionName())); + if (thrownType != null && thrownType.getKind().isClass()) { + inheritedThrows.add(((TypeElement) thrownType).getQualifiedName().toString()); + } + break; + case RETURN: + returnTypeFound |= true; + } + } + } + }, true); + } catch (IOException ex) { + LOG.log(Level.FINE, null, ex); } } } diff --git a/java/javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java b/java/javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java index 9502d67..9b17ba7 100644 --- a/java/javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java +++ b/java/javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java @@ -19,8 +19,7 @@ package org.netbeans.modules.javadoc.hints; -import com.sun.javadoc.Doc; -import com.sun.javadoc.MethodDoc; +import com.sun.source.doctree.DocCommentTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.ExpressionTree; @@ -103,7 +102,7 @@ public class JavadocUtilities { return findInheritedDoc(javac, elm) != null; } - public static MethodDoc findInheritedDoc(CompilationInfo javac, Element elm) { + public static DocCommentTree findInheritedDoc(CompilationInfo javac, Element elm) { if (elm.getKind() == ElementKind.METHOD) { TypeElement clazz = (TypeElement) elm.getEnclosingElement(); return searchInInterfaces(javac, clazz, clazz, @@ -119,7 +118,7 @@ public class JavadocUtilities { * <p>Do not use MethodDoc.overriddenMethod() instead since it fails for * interfaces! */ - private static MethodDoc searchInInterfaces( + private static DocCommentTree searchInInterfaces( CompilationInfo javac, TypeElement class2query, TypeElement overriderClass, ExecutableElement overrider, Set<TypeElement> exclude) { @@ -131,7 +130,7 @@ public class JavadocUtilities { continue; } // check methods - MethodDoc jdoc = searchInMethods(javac, ifceEl, overriderClass, overrider); + DocCommentTree jdoc = searchInMethods(javac, ifceEl, overriderClass, overrider); if (jdoc != null) { return jdoc; } @@ -142,7 +141,7 @@ public class JavadocUtilities { for (TypeMirror ifceMirror : class2query.getInterfaces()) { if (ifceMirror.getKind() == TypeKind.DECLARED) { TypeElement ifceEl = (TypeElement) ((DeclaredType) ifceMirror).asElement(); - MethodDoc jdoc = searchInInterfaces(javac, ifceEl, overriderClass, overrider, exclude); + DocCommentTree jdoc = searchInInterfaces(javac, ifceEl, overriderClass, overrider, exclude); if (jdoc != null) { return jdoc; } @@ -152,7 +151,7 @@ public class JavadocUtilities { return searchInSuperclass(javac, class2query, overriderClass, overrider, exclude); } - private static MethodDoc searchInSuperclass( + private static DocCommentTree searchInSuperclass( CompilationInfo javac, TypeElement class2query, TypeElement overriderClass, ExecutableElement overrider, Set<TypeElement> exclude) { @@ -163,7 +162,7 @@ public class JavadocUtilities { } TypeElement superclass = (TypeElement) ((DeclaredType) superclassMirror).asElement(); // check methods - MethodDoc jdoc = searchInMethods(javac, superclass, overriderClass, overrider); + DocCommentTree jdoc = searchInMethods(javac, superclass, overriderClass, overrider); if (jdoc != null) { return jdoc; } @@ -172,16 +171,16 @@ public class JavadocUtilities { return searchInInterfaces(javac, superclass, overriderClass, overrider, exclude); } - private static MethodDoc searchInMethods( + private static DocCommentTree searchInMethods( CompilationInfo javac, TypeElement class2query, TypeElement overriderClass, ExecutableElement overrider) { for (Element elm : class2query.getEnclosedElements()) { if (elm.getKind() == ElementKind.METHOD && javac.getElements().overrides(overrider, (ExecutableElement) elm, overriderClass)) { - Doc jdoc = javac.getElementUtilities().javaDocFor(elm); - return (jdoc != null && jdoc.getRawCommentText().length() > 0)? - (MethodDoc) jdoc: null; + DocCommentTree jdoc = javac.getDocTrees().getDocCommentTree(elm); + return (jdoc != null && !jdoc.getFullBody().isEmpty())? + jdoc: null; } } return null; diff --git a/java/javadoc/test/unit/src/org/netbeans/modules/javadoc/hints/Analyzer2Test.java b/java/javadoc/test/unit/src/org/netbeans/modules/javadoc/hints/Analyzer2Test.java index c981ee3..d5a5d03 100644 --- a/java/javadoc/test/unit/src/org/netbeans/modules/javadoc/hints/Analyzer2Test.java +++ b/java/javadoc/test/unit/src/org/netbeans/modules/javadoc/hints/Analyzer2Test.java @@ -186,7 +186,13 @@ public class Analyzer2Test extends NbTestCase { HintTest.create() .input( "package test;\n" + - "class ZimaImpl implements Zima {\n" + + "class ZimaImpl extends Intermediate implements Zima {\n" + + " /**\n" + + " * \n" + + " */\n" + + " public <T> String base(T prvniho) throws Exception {\n" + + " return \"\";\n" + + " }\n" + " /**\n" + " * \n" + " */\n" + @@ -194,6 +200,17 @@ public class Analyzer2Test extends NbTestCase { " return \"\";\n" + " }\n" + "}\n" + + "abstract class Intermediate extends Base {}\n" + + "abstract class Base {\n" + + " /**\n" + + " * \n" + + " * @param prvniho \n" + + " * @param <T> \n" + + " * @return \n" + + " * @throws Exception \n" + + " */\n" + + " abstract <T> String base(T prvniho) throws Exception;\n" + + "}\n" + "interface Zima {\n" + " /**\n" + " * \n" + diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBClassWriter.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBClassWriter.java index 984cabc..9a16f9e 100644 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBClassWriter.java +++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBClassWriter.java @@ -48,13 +48,11 @@ public class NBClassWriter extends ClassWriter { } private final NBNames nbNames; - private final NBMessager nbMessager; private final Types types; protected NBClassWriter(Context context) { super(context); nbNames = NBNames.instance(context); - nbMessager = NBMessager.instance(context); types = Types.instance(context); } diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocClassFinder.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocClassFinder.java deleted file mode 100644 index ad08163..0000000 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocClassFinder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.netbeans.lib.nbjavac.services; - -import com.sun.tools.javac.code.ClassFinder; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javadoc.main.JavadocClassFinder; -import javax.tools.JavaFileObject; - -/** - * - * @author lahvac - */ -public class NBJavadocClassFinder extends JavadocClassFinder { - - public static void preRegister(Context context) { - context.put(classFinderKey, new Context.Factory<ClassFinder>() { - public ClassFinder make(Context c) { - return new NBJavadocClassFinder(c); - } - }); - } - - public NBJavadocClassFinder(Context context) { - super(context); - } - - @Override - protected JavaFileObject preferredFileObject(JavaFileObject a, JavaFileObject b) { - if (b.getName().toLowerCase().endsWith(".sig")) { - //do not prefer sources over sig files (unless sources are newer): - boolean prevPreferSource = preferSource; - try { - preferSource = false; - return super.preferredFileObject(a, b); - } finally { - preferSource = prevPreferSource; - } - } - return super.preferredFileObject(a, b); - } - -} diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocEnter.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocEnter.java deleted file mode 100644 index 0f98e47..0000000 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocEnter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.lib.nbjavac.services; - -import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.comp.Enter; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import com.sun.tools.javac.tree.TreeInfo; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; -import com.sun.tools.javac.util.JCDiagnostic.Error; -import com.sun.tools.javadoc.main.JavadocEnter; -import com.sun.tools.javadoc.main.Messager; -import org.netbeans.lib.nbjavac.services.NBTreeMaker.IndexedClassDecl; - -/** - * JavadocEnter which doesn't ignore class duplicates unlike the base JavadocEnter - * Enter - does't ignore duplicates - * JavadocEnter - ignors duplicates - * NBJavadocEnter - does't ignore duplicates - * @author Tomas Zezula - */ -public class NBJavadocEnter extends JavadocEnter { - - public static void preRegister(final Context context) { - context.put(enterKey, new Context.Factory<Enter>() { - public Enter make(Context c) { - return new NBJavadocEnter(c); - } - }); - } - - private final Messager messager; - private final CancelService cancelService; - private final Symtab syms; - - protected NBJavadocEnter(Context context) { - super(context); - messager = Messager.instance0(context); - cancelService = CancelService.instance(context); - syms = Symtab.instance(context); - } - - public @Override void main(com.sun.tools.javac.util.List<JCCompilationUnit> trees) { - //Todo: Check everytime after the java update that JavaDocEnter.main or Enter.main - //are not changed. - this.complete(trees, null); - } - - @Override - protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) { - messager.error(pos, new Error("compiler", "duplicate.class", c.fullname)); - } - - @Override - public void visitClassDef(JCClassDecl tree) { - cancelService.abortIfCanceled(); - super.visitClassDef(tree); - } - - @Override - public void visitTopLevel(JCTree.JCCompilationUnit tree) { - if (TreeInfo.isModuleInfo(tree) && tree.modle == syms.noModule) { - //workaround: when source level is == 8, then visitTopLevel crashes for module-info.java - return ; - } - super.visitTopLevel(tree); - } - - //no @Override to ensure compatibility with ordinary javac: - protected int getIndex(JCClassDecl clazz) { - return clazz instanceof IndexedClassDecl ? ((IndexedClassDecl) clazz).index : -1; - } -} diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocMemberEnter.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocMemberEnter.java deleted file mode 100644 index 258059c..0000000 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavadocMemberEnter.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.netbeans.lib.nbjavac.services; - -import com.sun.source.util.TreePath; -import com.sun.tools.javac.api.JavacTrees; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.comp.MemberEnter; -import com.sun.tools.javac.tree.JCTree.JCBlock; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import com.sun.tools.javac.tree.JCTree.JCExpression; -import com.sun.tools.javac.tree.JCTree.JCImport; -import com.sun.tools.javac.tree.JCTree.JCMethodDecl; -import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javadoc.main.JavadocMemberEnter; - -/** - * - * @author lahvac - */ -public class NBJavadocMemberEnter extends JavadocMemberEnter { - - public static void preRegister(Context context) { - context.put(memberEnterKey, new Context.Factory<MemberEnter>() { - public MemberEnter make(Context c) { - return new NBJavadocMemberEnter(c); - } - }); - } - - private final CancelService cancelService; - private final JavacTrees trees; - - public NBJavadocMemberEnter(Context context) { - super(context); - cancelService = CancelService.instance(context); - trees = NBJavacTrees.instance(context); - } - - @Override - public void visitTopLevel(JCCompilationUnit tree) { - cancelService.abortIfCanceled(); - super.visitTopLevel(tree); - } - - @Override - public void visitImport(JCImport tree) { - cancelService.abortIfCanceled(); - super.visitImport(tree); - } - - @Override - public void visitMethodDef(JCMethodDecl tree) { - cancelService.abortIfCanceled(); - JCBlock body = tree.body; - try { - super.visitMethodDef(tree); - } finally { - //reinstall body: - tree.body = body; - } - if (trees instanceof NBJavacTrees && !env.enclClass.defs.contains(tree)) { - TreePath path = trees.getPath(env.toplevel, env.enclClass); - if (path != null) { - ((NBJavacTrees)trees).addPathForElement(tree.sym, new TreePath(path, tree)); - } - } - } - - @Override - public void visitVarDef(JCVariableDecl tree) { - cancelService.abortIfCanceled(); - JCExpression init = tree.init; - try { - super.visitVarDef(tree); - } finally { - //reinstall init: - tree.init = init; - if (init != null) { - tree.sym.flags_field |= Flags.HASINIT; //XXX: hack - } - } - } - -} diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMessager.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBLog.java similarity index 76% rename from java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMessager.java rename to java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBLog.java index 3b5241f..e268ad7 100644 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMessager.java +++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBLog.java @@ -18,58 +18,55 @@ */ package org.netbeans.lib.nbjavac.services; -import com.sun.javadoc.SourcePosition; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.Log; -import com.sun.tools.javadoc.main.Messager; import java.io.PrintWriter; import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import javax.tools.Diagnostic; import javax.tools.JavaFileObject; /** * * @author Tomas Zezula */ -public final class NBMessager extends Messager { +public final class NBLog extends Log { private static final String ERR_NOT_IN_PROFILE = "not.in.profile"; //NOI18N private final Map<URI,Collection<Symbol.ClassSymbol>> notInProfiles = new HashMap<>(); - private NBMessager( + private NBLog( final Context context, - final String programName, final PrintWriter errWriter, final PrintWriter warnWriter, final PrintWriter noticeWriter) { - super(context, programName, errWriter, warnWriter, noticeWriter); + super(context, errWriter, warnWriter, noticeWriter); } - public static NBMessager instance(Context context) { + public static NBLog instance(Context context) { final Log log = Log.instance(context); - if (!(log instanceof NBMessager)) { - throw new InternalError("No NBMessager instance!"); //NOI18N + if (!(log instanceof NBLog)) { + throw new InternalError("No NBLog instance!"); //NOI18N } - return (NBMessager) log; + return (NBLog) log; } public static void preRegister(Context context, - final String programName, final PrintWriter errWriter, final PrintWriter warnWriter, final PrintWriter noticeWriter) { context.put(logKey, new Context.Factory<Log>() { @Override public Log make(Context c) { - return new NBMessager( + return new NBLog( c, - programName, errWriter, warnWriter, noticeWriter); @@ -78,15 +75,14 @@ public final class NBMessager extends Messager { } @Override - public void error( - final SourcePosition pos, - final String key, - final Object ... args) { - if (ERR_NOT_IN_PROFILE.equals(key)) { + public void report(JCDiagnostic diagnostic) { + //XXX: needs testing! + if (diagnostic.getKind() == Diagnostic.Kind.ERROR && + ERR_NOT_IN_PROFILE.equals(diagnostic.getCode())) { final JavaFileObject currentFile = currentSourceFile(); if (currentFile != null) { final URI uri = currentFile.toUri(); - Symbol.ClassSymbol type = (Symbol.ClassSymbol) args[0]; + Symbol.ClassSymbol type = (Symbol.ClassSymbol) diagnostic.getArgs()[0]; Collection<Symbol.ClassSymbol> types = notInProfiles.get(uri); if (types == null) { types = new ArrayList<>(); @@ -95,7 +91,7 @@ public final class NBMessager extends Messager { types.add(type); } } - super.error(pos, key, args); + super.report(diagnostic); } Collection<? extends Symbol.ClassSymbol> removeNotInProfile(final URI uri) { diff --git a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMemberEnter.java b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMemberEnter.java index 107a4ec..134e342 100644 --- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMemberEnter.java +++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBMemberEnter.java @@ -18,6 +18,8 @@ */ package org.netbeans.lib.nbjavac.services; +import com.sun.source.util.TreePath; +import com.sun.tools.javac.api.JavacTrees; import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCImport; @@ -31,19 +33,23 @@ import com.sun.tools.javac.util.Context; */ public class NBMemberEnter extends MemberEnter { - public static void preRegister(Context context) { + public static void preRegister(Context context, boolean backgroundScan) { context.put(MemberEnter.class, new Context.Factory<MemberEnter>() { public MemberEnter make(Context c) { - return new NBMemberEnter(c); + return new NBMemberEnter(c, backgroundScan); } }); } private final CancelService cancelService; + private final JavacTrees trees; + private final boolean backgroundScan; - public NBMemberEnter(Context context) { + public NBMemberEnter(Context context, boolean backgroundScan) { super(context); cancelService = CancelService.instance(context); + trees = NBJavacTrees.instance(context); + this.backgroundScan = backgroundScan; } @Override @@ -62,6 +68,12 @@ public class NBMemberEnter extends MemberEnter { public void visitMethodDef(JCMethodDecl tree) { cancelService.abortIfCanceled(); super.visitMethodDef(tree); + if (!backgroundScan && trees instanceof NBJavacTrees && !env.enclClass.defs.contains(tree)) { + TreePath path = trees.getPath(env.toplevel, env.enclClass); + if (path != null) { + ((NBJavacTrees)trees).addPathForElement(tree.sym, new TreePath(path, tree)); + } + } } @Override diff --git a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBAttrTest.java b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBAttrTest.java index 683613a..5891631 100644 --- a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBAttrTest.java +++ b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBAttrTest.java @@ -130,7 +130,7 @@ public class NBAttrTest extends NbTestCase { std.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(workingDir)); Context context = new Context(); - NBMessager.preRegister(context, null, DEV_NULL, DEV_NULL, DEV_NULL); + NBLog.preRegister(context, DEV_NULL, DEV_NULL, DEV_NULL); NBAttr.preRegister(context); final JavacTaskImpl ct = (JavacTaskImpl) ((JavacTool)tool).getTask(null, std, null, Arrays.asList("-source", "1.8", "-target", "1.8"), null, Arrays.asList(new MyFileObject(code)), context); diff --git a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBClassWriterTest.java b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBClassWriterTest.java index 7035775..c987a2b 100644 --- a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBClassWriterTest.java +++ b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/NBClassWriterTest.java @@ -89,7 +89,7 @@ public class NBClassWriterTest extends NbTestCase { std.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(workingDir)); Context context = new Context(); - NBMessager.preRegister(context, null, DEV_NULL, DEV_NULL, DEV_NULL); + NBLog.preRegister(context, DEV_NULL, DEV_NULL, DEV_NULL); final JavacTaskImpl ct = (JavacTaskImpl) ((JavacTool)tool).getTask(null, std, null, Arrays.asList("-bootclasspath", bootPath, "-source", "1.7", "-target", "1.7"), null, Arrays.asList(new MyFileObject(code)), context); NBClassReader.preRegister(ct.getContext()); @@ -109,7 +109,7 @@ public class NBClassWriterTest extends NbTestCase { std.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(workingDir)); Context context = new Context(); - NBMessager.preRegister(context, null, DEV_NULL, DEV_NULL, DEV_NULL); + NBLog.preRegister(context, DEV_NULL, DEV_NULL, DEV_NULL); JavacTaskImpl ct = (JavacTaskImpl)((JavacTool)tool).getTask(null, std, null, Arrays.asList("-bootclasspath", bootPath, "-source", "1.8", "-target", "1.8"), null, Arrays.<JavaFileObject>asList(), context); NBClassReader.preRegister(ct.getContext()); diff --git a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/Utilities.java b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/Utilities.java index ca52d7f..cc1d1df 100644 --- a/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/Utilities.java +++ b/java/lib.nbjavac/test/unit/src/org/netbeans/lib/nbjavac/services/Utilities.java @@ -21,8 +21,7 @@ package org.netbeans.lib.nbjavac.services; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.util.Context; -import com.sun.tools.javadoc.main.JavadocClassFinder; -import com.sun.tools.javadoc.main.Messager; +import com.sun.tools.javac.util.Log; import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; @@ -50,7 +49,7 @@ public class Utilities { assert tool != null; Context context = new Context(); //need to preregister the Messages here, because the getTask below requires Log instance: - Messager.preRegister(context, null, DEV_NULL, DEV_NULL, DEV_NULL); + Log.preRegister(context, DEV_NULL); JavacTaskImpl task = (JavacTaskImpl)JavacTool.create().getTask(null, fm, null, Arrays.asList("-bootclasspath", bootPath, "-source", version, "-target", version, "-Xjcov", "-XDshouldStopPolicy=GENERATE"), null, Arrays.asList(sources), diff --git a/java/libs.javacapi/external/binaries-list b/java/libs.javacapi/external/binaries-list index dd9eefc..f730817 100644 --- a/java/libs.javacapi/external/binaries-list +++ b/java/libs.javacapi/external/binaries-list @@ -14,4 +14,4 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -A318D725959B3F102B53BA249F3C35C0F68B1E3D nb-javac-12-api.jar +9FA2C56C15D013C391EF76E9AA07172F20447673 nb-javac-12-api.jar diff --git a/java/libs.javacapi/nbproject/project.xml b/java/libs.javacapi/nbproject/project.xml index 390c985..741e1eb 100644 --- a/java/libs.javacapi/nbproject/project.xml +++ b/java/libs.javacapi/nbproject/project.xml @@ -28,7 +28,6 @@ <public-packages> <!-- TODO: need to specify exports here, because fragments cannot add exports - should be fixed? --> <package>org.netbeans.libs.javacapi</package> - <package>com.sun.javadoc</package> <package>com.sun.source.doctree</package> <package>com.sun.source.tree</package> <package>com.sun.source.util</package> diff --git a/java/libs.javacimpl/external/binaries-list b/java/libs.javacimpl/external/binaries-list index ce2581a..9da924d 100644 --- a/java/libs.javacimpl/external/binaries-list +++ b/java/libs.javacimpl/external/binaries-list @@ -14,4 +14,4 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -48EF66E1C3EABC275295D2E09CD442B4DE13A816 nb-javac-12-impl.jar +3B790BEAE746363CB8EC4C18B0A6187D683BC247 nb-javac-12-impl.jar diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/IntroduceLocalExtensionTransformer.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/IntroduceLocalExtensionTransformer.java index ee9e58a..a53c3bc 100644 --- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/IntroduceLocalExtensionTransformer.java +++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/IntroduceLocalExtensionTransformer.java @@ -18,7 +18,7 @@ */ package org.netbeans.modules.refactoring.java.plugins; -import com.sun.javadoc.Doc; +import com.sun.source.doctree.DocCommentTree; import com.sun.source.tree.*; import com.sun.source.util.SourcePositions; import com.sun.source.util.TreePath; @@ -516,9 +516,9 @@ public class IntroduceLocalExtensionTransformer extends RefactoringVisitor { MethodTree newMethod = make.Method(modifiers, member.getSimpleName(), methodReturnType, newTypeParams, newParameters, newThrownTypes, make.Block(Collections.singletonList(statement), false), null, member.isVarArgs()); newMethod = genUtils.importFQNs(newMethod); - Doc javadoc = workingCopy.getElementUtilities().javaDocFor(member); - if (!javadoc.getRawCommentText().isEmpty()) { - Comment comment = Comment.create(Comment.Style.JAVADOC, javadoc.getRawCommentText()); + DocCommentTree javadoc = workingCopy.getDocTrees().getDocCommentTree(member); + if (javadoc != null && !javadoc.getFullBody().isEmpty()) { + Comment comment = Comment.create(Comment.Style.JAVADOC, javadoc.toString()); make.addComment(newMethod, comment, true); } members.add(newMethod); @@ -671,9 +671,9 @@ public class IntroduceLocalExtensionTransformer extends RefactoringVisitor { newThrownTypes, block, null); newConstr = genUtils.importFQNs(newConstr); - Doc javadoc = workingCopy.getElementUtilities().javaDocFor(constr); - if (!javadoc.getRawCommentText().isEmpty()) { - Comment comment = Comment.create(Comment.Style.JAVADOC, javadoc.getRawCommentText()); + DocCommentTree javadoc = workingCopy.getDocTrees().getDocCommentTree(constr); + if (javadoc != null && !javadoc.getFullBody().isEmpty()) { + Comment comment = Comment.create(Comment.Style.JAVADOC, javadoc.toString()); make.addComment(newConstr, comment, true); } members.add(newConstr); diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java index 9be3927..e9ba1d9 100644 --- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java +++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/MoveMembersTransformer.java @@ -18,8 +18,8 @@ */ package org.netbeans.modules.refactoring.java.plugins; -import com.sun.javadoc.Doc; -import com.sun.javadoc.Tag; +import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; import com.sun.source.tree.*; import com.sun.source.util.SourcePositions; import com.sun.source.util.TreePath; @@ -29,6 +29,7 @@ import com.sun.source.util.Trees; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import javax.lang.model.element.*; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; @@ -853,18 +854,23 @@ public class MoveMembersTransformer extends RefactoringVisitor { } private Comment updateJavadoc(Element method, Element targetElement, boolean addDeprecated) { - Doc javadoc = workingCopy.getElementUtilities().javaDocFor(method); + DocCommentTree javadoc = workingCopy.getDocTrees().getDocCommentTree(method); - List<Tag> otherTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags())); - List<Tag> returnTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@return"))); // NOI18N - List<Tag> throwsTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@throws"))); // NOI18N - List<Tag> paramTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@param"))); // NOI18N - - otherTags.removeAll(returnTags); - otherTags.removeAll(throwsTags); - otherTags.removeAll(paramTags); + List<DocTree> otherTags = new LinkedList<>(); + List<DocTree> returnTags = new LinkedList<>(); + List<DocTree> throwsTags = new LinkedList<>(); + List<DocTree> paramTags = new LinkedList<>(); + + for (DocTree tag : javadoc.getBlockTags()) { + switch (tag.getKind()) { + case RETURN: returnTags.add(tag); break; + case THROWS: throwsTags.add(tag); break; + case PARAM: paramTags.add(tag); break; + default: otherTags.add(tag); + } + } - StringBuilder text = new StringBuilder(javadoc.commentText()).append("\n\n"); // NOI18N + StringBuilder text = new StringBuilder(javadoc.getBody().stream().map(t -> t.toString()).collect(Collectors.joining(""))).append("\n\n"); // NOI18N text.append(tagsToString(paramTags)); text.append(tagsToString(returnTags)); text.append(tagsToString(throwsTags)); @@ -877,10 +883,10 @@ public class MoveMembersTransformer extends RefactoringVisitor { return comment; } - private String tagsToString(List<Tag> tags) { + private String tagsToString(List<DocTree> tags) { StringBuilder sb = new StringBuilder(); - for (Tag tag : tags) { - sb.append(tag.name()).append(" ").append(tag.text()).append("\n"); // NOI18N + for (DocTree tag : tags) { + sb.append(tag.toString()).append("\n"); // NOI18N } return sb.toString(); } diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersPanel.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersPanel.java index a864a03..6f70640 100644 --- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersPanel.java +++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/ChangeParametersPanel.java @@ -18,7 +18,7 @@ */ package org.netbeans.modules.refactoring.java.ui; -import com.sun.javadoc.Doc; +import com.sun.source.doctree.DocCommentTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; import com.sun.source.tree.VariableTree; @@ -201,8 +201,8 @@ public class ChangeParametersPanel extends JPanel implements CustomRefactoringPa Document.StreamDescriptionProperty, dob); } - Doc javadocDoc = info.getElementUtilities().javaDocFor(e); - if(javadocDoc.commentText() == null || javadocDoc.getRawCommentText().equals("")) { + DocCommentTree javadocDoc = info.getDocTrees().getDocCommentTree(e); + if(javadocDoc != null && !javadocDoc.getFullBody().isEmpty()) { chkGenJavadoc.setEnabled(true); chkGenJavadoc.setVisible(true); chkUpdateJavadoc.setVisible(false); diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/IntroduceParameterPanel.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/IntroduceParameterPanel.java index 0ac8b25..5c77c57 100644 --- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/IntroduceParameterPanel.java +++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/IntroduceParameterPanel.java @@ -18,7 +18,7 @@ */ package org.netbeans.modules.refactoring.java.ui; -import com.sun.javadoc.Doc; +import com.sun.source.doctree.DocCommentTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Scope; import com.sun.source.tree.Tree; @@ -140,8 +140,8 @@ public class IntroduceParameterPanel extends JPanel implements CustomRefactoring final String tm = typeMirror == null ? "Object" : typeMirror.toString(); Element methodElement = info.getTrees().getElement(methodPath); - Doc javadocDoc = info.getElementUtilities().javaDocFor(methodElement); - if(javadocDoc != null && javadocDoc.commentText() == null || javadocDoc.getRawCommentText().equals("")) { + DocCommentTree javadocDoc = info.getDocTrees().getDocCommentTree(methodElement); + if(javadocDoc != null && !javadocDoc.getFullBody().isEmpty()) { chkGenJavadoc.setEnabled(true); chkGenJavadoc.setVisible(true); chkUpdateJavadoc.setVisible(false); diff --git a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java index 8f5d9db..75ff372 100644 --- a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java +++ b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java @@ -51,6 +51,7 @@ import com.sun.tools.javac.api.JavacScope; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.api.JavacTrees; import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.comp.Annotate; @@ -87,7 +88,6 @@ import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Names; -import com.sun.tools.javadoc.main.Messager; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -729,7 +729,9 @@ public class Utilities { long count = inc++; - clazz.append("public class $$scopeclass$constraints$" + count + "{"); + String classname = "$$scopeclass$constraints$" + count; + + clazz.append("public class " + classname + "{"); for (Entry<String, TypeMirror> e : constraints.entrySet()) { if (e.getValue() != null) { @@ -752,6 +754,8 @@ public class Utilities { Log log = Log.instance(context); NBResolve resolve = NBResolve.instance(context); Annotate annotate = Annotate.instance(context); + Names names = Names.instance(context); + Symtab syms = Symtab.instance(context); Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(compiler.log); JavaFileObject jfo = FileObjects.memoryFileObject("$", "$", new File("/tmp/$$scopeclass$constraints$" + count + ".java").toURI(), System.currentTimeMillis(), clazz.toString()); @@ -772,7 +776,8 @@ public class Utilities { } JCCompilationUnit cut = compiler.parse(jfo); - modules.enter(com.sun.tools.javac.util.List.of(cut), null); + ClassSymbol enteredClass = syms.enterClass(modules.getDefaultModule(), names.fromString("$$." + classname)); + modules.enter(com.sun.tools.javac.util.List.of(cut), enteredClass); compiler.enterTrees(com.sun.tools.javac.util.List.of(cut)); Todo todo = compiler.todo; @@ -1274,14 +1279,8 @@ public class Utilities { return false; } - public static boolean isJavadocSupported(CompilationInfo info) { - Context c = JavaSourceAccessor.getINSTANCE().getJavacTask(info).getContext(); - - try { - return c.get(Log.logKey) instanceof Messager; - } catch (NoClassDefFoundError e) { - return false; - } + public static boolean isJavadocSupported(CompilationInfo info) { //TODO: unnecessary? + return true; } private static Class<?> parserClass; diff --git a/java/spi.java.hints/src/org/netbeans/spi/java/hints/JavaFixUtilities.java b/java/spi.java.hints/src/org/netbeans/spi/java/hints/JavaFixUtilities.java index bcaee17..25dae5e 100644 --- a/java/spi.java.hints/src/org/netbeans/spi/java/hints/JavaFixUtilities.java +++ b/java/spi.java.hints/src/org/netbeans/spi/java/hints/JavaFixUtilities.java @@ -18,8 +18,9 @@ */ package org.netbeans.spi.java.hints; -import com.sun.javadoc.Doc; -import com.sun.javadoc.Tag; +import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; +import com.sun.source.doctree.SinceTree; import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BinaryTree; @@ -304,12 +305,16 @@ public class JavaFixUtilities { static SpecificationVersion computeSpecVersion(CompilationInfo info, Element el) { if (!Utilities.isJavadocSupported(info)) return null; - Doc javaDoc = info.getElementUtilities().javaDocFor(el); + DocCommentTree javaDoc = info.getDocTrees().getDocCommentTree(el); if (javaDoc == null) return null; - for (Tag since : javaDoc.tags("@since")) { - String text = since.text(); + for (DocTree tag : javaDoc.getBlockTags()) { + if (tag.getKind() != DocTree.Kind.SINCE) { + continue; + } + + String text = ((SinceTree) tag).getBody().toString(); Matcher m = SPEC_VERSION.matcher(text); diff --git a/nbbuild/build.xml b/nbbuild/build.xml index 3cbc361..0a99717 100644 --- a/nbbuild/build.xml +++ b/nbbuild/build.xml @@ -156,16 +156,15 @@ <property name="langtools.jdk.home" value="${java.home}" /> </ant> <mkdir dir="${nb_all}/nbbuild/build/langtools/build/nb" /> - <javac srcdir="${nb_all}/nbbuild/build/langtools/src/java.compiler/share/classes:${nb_all}/nbbuild/build/langtools/src/jdk.compiler/share/classes:${nb_all}/nbbuild/build/langtools/src/jdk.javadoc/share/classes:${nb_all}/nbbuild/build/langtools/src/jdk.jdeps/share/classes:${nb_all}/nbbuild/build/langtools/build/gensrc/jdk.compiler" + <javac srcdir="${nb_all}/nbbuild/build/langtools/src/java.compiler/share/classes:${nb_all}/nbbuild/build/langtools/src/jdk.compiler/share/classes:${nb_all}/nbbuild/build/langtools/src/jdk.jdeps/share/classes:${nb_all}/nbbuild/build/langtools/build/gensrc/jdk.compiler" destdir="${nb_all}/nbbuild/build/langtools/build/nb" excludes="**/module-info.java,com/sun/tools/javac/main/JavacToolProvider.java,com/sun/tools/jdeps/**,com/sun/tools/jdeprscan/**,com/sun/tools/javap/Main.java,jdk/javadoc/internal/tool/JavadocToolProvider.java,com/sun/tools/doclets/standard/Standard.java" /> <copy todir="${nb_all}/nbbuild/build/langtools/build/nb"> <fileset dir="${nb_all}/nbbuild/build/langtools/src/java.compiler/share/classes" includes="**/*.properties"/> <fileset dir="${nb_all}/nbbuild/build/langtools/src/jdk.compiler/share/classes" includes="**/*.properties"/> - <fileset dir="${nb_all}/nbbuild/build/langtools/src/jdk.javadoc/share/classes" includes="**/*.properties"/> <fileset dir="${nb_all}/nbbuild/build/langtools/src/jdk.jdeps/share/classes" includes="**/*.properties"/> </copy> - <jar destfile="${nb_all}/nbbuild/external/vanilla-javac-api.jar" basedir="${nb_all}/nbbuild/build/langtools/build/nb" includes="javax/**,com/sun/source/**,com/sun/javadoc/**" /> + <jar destfile="${nb_all}/nbbuild/external/vanilla-javac-api.jar" basedir="${nb_all}/nbbuild/build/langtools/build/nb" includes="javax/**,com/sun/source/**" /> <jar destfile="${nb_all}/nbbuild/external/vanilla-javac-impl.jar" basedir="${nb_all}/nbbuild/build/langtools/build/nb" excludes="javax/**,com/sun/source/**,com/sun/javadoc/**" /> </target> diff --git a/nbbuild/templates/projectized.xml b/nbbuild/templates/projectized.xml index 36b280a..d6bba53 100644 --- a/nbbuild/templates/projectized.xml +++ b/nbbuild/templates/projectized.xml @@ -112,6 +112,9 @@ If you are sure you want to build with JDK 9+ anyway, use: -Dpermit.jdk9.builds= compilecp="test.qa-functional.compile.cp" compiledep="test.qa-functional.testdep"/> </parseprojectxml> + <condition property="requires.nb.javac" value="true"> + <contains string="${module.classpath}" substring="/org-netbeans-libs-javacapi.jar" /> + </condition> <property name="spec.version.base.fatal.warning" value="true"/> <condition property="is.regular"> <not> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists