Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 253410 Details for
Bug 366007
[render][hovering] Render implicit null annotations due to a default
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
UI part concerning part (2)
Bug-366007--renderhovering-Render-implicit-null-anno.patch (text/plain), 9.29 KB, created by
Stephan Herrmann
on 2015-05-12 09:27:16 EDT
(
hide
)
Description:
UI part concerning part (2)
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2015-05-12 09:27:16 EDT
Size:
9.29 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java >index 9f705d6..365cae1 100644 >--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java >+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java >@@ -10,15 +10,25 @@ > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.core; > >+import java.io.File; >+import java.io.IOException; > import java.util.regex.Matcher; > import java.util.regex.Pattern; > >+import org.osgi.framework.Bundle; >+ > import org.eclipse.jdt.testplugin.JavaProjectHelper; >+ >+import org.eclipse.core.runtime.FileLocator; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; > > import org.eclipse.jface.preference.IPreferenceStore; > > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.dom.AST; > import org.eclipse.jdt.core.dom.ASTParser; > import org.eclipse.jdt.core.dom.IBinding; >@@ -35,6 +45,7 @@ > > protected IJavaProject fJProject1; > protected boolean fHaveSource= true; >+ private String ANNOTATION_JAR_PATH; > > protected void setUp() throws Exception { > fJProject1= ProjectTestSetup.getProject(); >@@ -45,9 +56,23 @@ > > > protected void tearDown() throws Exception { >+ fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.DISABLED); > JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath()); > } > >+ protected void setupForNullAnnotations(String version) throws IOException, JavaModelException { >+ fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); >+ if (this.ANNOTATION_JAR_PATH == null) { >+ Bundle[] bundles= Platform.getBundles("org.eclipse.jdt.annotation", version); >+ File bundleFile= FileLocator.getBundleFile(bundles[0]); >+ if (bundleFile.isDirectory()) >+ this.ANNOTATION_JAR_PATH= bundleFile.getPath() + "/bin"; >+ else >+ this.ANNOTATION_JAR_PATH= bundleFile.getPath(); >+ } >+ JavaProjectHelper.addLibrary(fJProject1, new Path(ANNOTATION_JAR_PATH)); >+ } >+ > protected String getBindingLabel(IJavaElement elem, long flags) { > ASTParser parser= ASTParser.newParser(AST.JLS8); > parser.setResolveBindings(true); >diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java >index 1b7019a..604fd9e 100644 >--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java >+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java >@@ -732,7 +732,7 @@ > lab= getBindingLabel(foo2, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.F_PRE_TYPE_SIGNATURE); > assertLinkMatch(lab, "{{org.test.LambdaTests.{...}|Local}} toStringL - {{org}}.{{test}}.{{LambdaTests}}.{...}"); > >-// can't select the constructor, only the type (label computation works fine once we find the binding) >+// can't select the constructor, only the type (label computation works fine once we find the binding) > // IJavaElement ctor= cu.codeSelect(content.indexOf("Local()"), 0)[0]; > // lab= getBindingLabel(ctor, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED); > // assertLinkMatch(lab, "{{org.test.LambdaTests}}.{...}.{{org.test.LambdaTests.{...}.|Local}}.Local()"); >@@ -768,4 +768,35 @@ > lab= getBindingLabel(foo2, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.F_PRE_TYPE_SIGNATURE); > assertLinkMatch(lab, "{{org.test.LambdaTests.{...}|Local}} toStringL - {{org}}.{{test}}.{{LambdaTests}}.{...}"); > } >+ >+ public void testNonNullByDefault() throws Exception { >+ setupForNullAnnotations("[1.1.0,2.0.0)"); // tests run at 1.5, need the "old" null annotations >+ IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); >+ >+ IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package org.test;\n"); >+ buf.append("import org.eclipse.jdt.annotation.*;\n"); >+ buf.append("\n"); >+ buf.append("@interface Ann {}\n"); >+ buf.append("@NonNullByDefault;\n"); >+ buf.append("public class Default {\n"); >+ buf.append(" public String test(@Nullable Integer t, int i, @Ann Object o) {\n"); >+ buf.append(" return \"\";\n"); >+ buf.append(" }\n"); >+ buf.append(" String s = test(1,2,new Object());\n"); >+ buf.append("}\n"); >+ String content= buf.toString(); >+ ICompilationUnit cu= pack1.createCompilationUnit("Default.java", content, false, null); >+ >+ IJavaElement test= cu.codeSelect(content.indexOf("test(1"), 4)[0]; >+ long flags1= JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_NAMES; >+ String lab= getBindingLabel(test, flags1); >+ assertLinkMatch(lab, "{{java.lang|String}} {{org.test.Default}}.test({{java.lang|Integer}} t, int i, {{java.lang|Object}} o)"); >+ >+ lab= getBindingLabel(test, flags1 | JavaElementLabels.M_PARAMETER_ANNOTATIONS); >+ assertLinkMatch(lab, "@{{org.eclipse.jdt.annotation|NonNull}} {{java.lang|String}} {{org.test.Default}}.test(" >+ + "@{{org.eclipse.jdt.annotation|Nullable}} {{java.lang|Integer}} t, int i, @{{org.test|Ann}} @{{org.eclipse.jdt.annotation|NonNull}} {{java.lang|Object}} o)"); >+ >+ } > } >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/BindingLinkedLabelComposer.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/BindingLinkedLabelComposer.java >index 8bb53a9..cb86ee4 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/BindingLinkedLabelComposer.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/BindingLinkedLabelComposer.java >@@ -20,8 +20,10 @@ > > import org.eclipse.jdt.core.Flags; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.dom.IAnnotationBinding; > import org.eclipse.jdt.core.dom.IBinding; >@@ -101,7 +103,7 @@ > case IBinding.ANNOTATION: > case IBinding.MEMBER_VALUE_PAIR: > // not used for hovers >- } >+ } > } > > private void appendMethodBindingLabel(IMethodBinding method, long flags) { >@@ -140,6 +142,9 @@ > > // return type > if (getFlag(flags, JavaElementLabels.M_PRE_RETURNTYPE) && !method.isConstructor() && !isInitializer) { >+ if (getFlag(flags, JavaElementLabels.M_PARAMETER_ANNOTATIONS)) { // for consistency >+ appendMethodDeclarationNullAnnotation(method.getAnnotations(), flags); >+ } > appendTypeBindingLabel(method.getReturnType(), flags); > fBuffer.append(' '); > } >@@ -297,6 +302,25 @@ > } > } > >+ private void appendMethodDeclarationNullAnnotation(IAnnotationBinding[] annotations, long flags) { >+ IJavaProject javaProject= fEnclosingElement.getJavaProject(); >+ if (javaProject != null && JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) { >+ String nonNullName= javaProject.getOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, true); >+ String nullableName= javaProject.getOption(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, true); >+ for (IAnnotationBinding annotation : annotations) { >+ ITypeBinding annotationType= annotation.getAnnotationType(); >+ if (annotationType != null) { >+ String annotationName= annotationType.getQualifiedName(); >+ if (annotationName.equals(nonNullName) || annotationName.equals(nullableName)) { >+ appendAnnotationLabel(annotation, flags); >+ fBuffer.append(' '); >+ return; >+ } >+ } >+ } >+ } >+ } >+ > private void appendVariableLabel(IVariableBinding variable, long flags) { > long qualificationFlags = flags & (QUALIFIER_FLAGS | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED); > if (fIsFromSource) { >@@ -391,7 +415,7 @@ > if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) > qualificationFlags |= JavaElementLabels.ALL_FULLY_QUALIFIED; > else if (getFlag(flags, JavaElementLabels.T_CONTAINER_QUALIFIED)) >- qualificationFlags |= (JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED); >+ qualificationFlags |= (JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED); > appendBindingLabel(declaringMember, qualificationFlags); > fBuffer.append('.'); > flags &= ~(JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED); // qualification is done >@@ -550,7 +574,7 @@ > appendTypeBindingLabel((ITypeBinding) value, flags); > fBuffer.append(".class"); //$NON-NLS-1$ > } else if (value instanceof String) { >- fBuffer.append(htmlEscape(ASTNodes.getEscapedStringLiteral((String) value))); >+ fBuffer.append(htmlEscape(ASTNodes.getEscapedStringLiteral((String) value))); > } else if (value instanceof IVariableBinding) { > appendVariableLabel((IVariableBinding) value, flags); > } else if (value instanceof IAnnotationBinding) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 366007
: 253410