summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2013-08-19 15:04:12 (EDT)
committer Mike Rennie2013-08-19 15:04:28 (EDT)
commitddbdc5aecddc3fbc2810a3e1dbd2d7506948ee16 (patch)
tree9b96016f20efd208a8c765a5b19982e74ee0df2b
parent64804bff5da49be0d4e0e1540e1191c318f367b4 (diff)
downloadeclipse.pde.ui-ddbdc5aecddc3fbc2810a3e1dbd2d7506948ee16.zip
eclipse.pde.ui-ddbdc5aecddc3fbc2810a3e1dbd2d7506948ee16.tar.gz
eclipse.pde.ui-ddbdc5aecddc3fbc2810a3e1dbd2d7506948ee16.tar.bz2
Bug 409428 - Consistently handle implicitly public members pt 1I20130820-0800
-rw-r--r--apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/completion/APIToolsJavadocCompletionProposalComputer.java77
-rw-r--r--apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/JavaUtils.java73
2 files changed, 76 insertions, 74 deletions
diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/completion/APIToolsJavadocCompletionProposalComputer.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/completion/APIToolsJavadocCompletionProposalComputer.java
index d2739ac..edf4387 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/completion/APIToolsJavadocCompletionProposalComputer.java
+++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/completion/APIToolsJavadocCompletionProposalComputer.java
@@ -22,7 +22,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
@@ -47,6 +46,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.pde.api.tools.internal.JavadocTagManager;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.IApiJavadocTag;
+import org.eclipse.pde.api.tools.internal.util.JavaUtils;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
import org.eclipse.swt.graphics.Image;
@@ -122,7 +122,7 @@ public class APIToolsJavadocCompletionProposalComputer implements IJavaCompletio
try {
int offset = jcontext.getInvocationOffset();
IJavaElement element = cunit.getElementAt(offset);
- if (element == null) {
+ if (!JavaUtils.isVisible(element)) {
return Collections.EMPTY_LIST;
}
ImageDescriptor imagedesc = jcontext.getLabelProvider().createImageDescriptor(
@@ -131,24 +131,9 @@ public class APIToolsJavadocCompletionProposalComputer implements IJavaCompletio
fImageHandle = (imagedesc == null ? null : imagedesc.createImage());
int type = getType(element);
int member = IApiJavadocTag.MEMBER_NONE;
- int elementtype = element.getElementType();
- switch(elementtype) {
- case IJavaElement.TYPE: {
- IType itype = (IType) element;
- if(hasNonVisibleParent(element, itype.isInterface())) {
- return Collections.EMPTY_LIST;
- }
- break;
- }
+ switch(element.getElementType()) {
case IJavaElement.METHOD: {
IMethod method = (IMethod) element;
- int flags = method.getFlags();
- boolean inter = method.getDeclaringType().isInterface();
- if(Flags.isPrivate(flags) ||
- (Flags.isPackageDefault(flags) && !inter) ||
- hasNonVisibleParent(element, inter)) {
- return Collections.EMPTY_LIST;
- }
member = IApiJavadocTag.MEMBER_METHOD;
if(method.isConstructor()) {
member = IApiJavadocTag.MEMBER_CONSTRUCTOR;
@@ -156,16 +141,6 @@ public class APIToolsJavadocCompletionProposalComputer implements IJavaCompletio
break;
}
case IJavaElement.FIELD: {
- IField field = (IField) element;
- int flags = field.getFlags();
- boolean inter = field.getDeclaringType().isInterface();
- if(Flags.isFinal(flags) ||
- field.isEnumConstant() ||
- Flags.isPrivate(flags) ||
- (Flags.isPackageDefault(flags) && !inter) ||
- hasNonVisibleParent(element, inter)) {
- return Collections.EMPTY_LIST;
- }
member = IApiJavadocTag.MEMBER_FIELD;
break;
}
@@ -203,52 +178,6 @@ public class APIToolsJavadocCompletionProposalComputer implements IJavaCompletio
}
/**
- * Returns if the given element has a non-visible parent in its parent hierarchy
- *
- * @param element
- * @return <code>true</code> if a parent type is non-visible, <code>false</code> otherwise
- * @throws JavaModelException
- * @since 1.0.400
- */
- boolean hasNonVisibleParent(IJavaElement element, boolean isinterface) throws JavaModelException {
- if(element == null) {
- return false;
- }
- boolean isinter = isinterface;
- switch(element.getElementType()) {
- case IJavaElement.TYPE: {
- IType type = (IType) element;
- int flags = type.getFlags();
- IType ptype = type.getDeclaringType();
- if(type.isInterface()) {
- if(ptype == null) {
- return false;
- }
- isinter &= true;
- if(Flags.isPublic(flags) || isinter) {
- return hasNonVisibleParent(ptype, isinter);
- }
- if(ptype.isClass()) {
- if(Flags.isPrivate(flags) || Flags.isPackageDefault(flags)) {
- return true;
- }
- }
- }
- if(ptype != null) {
- if(!Flags.isStatic(flags) && ! Flags.isPublic(flags)) {
- return true;
- }
- }
- if(Flags.isPrivate(flags) || Flags.isPackageDefault(flags)) {
- return true;
- }
- break;
- }
- }
- return hasNonVisibleParent(element.getParent(), isinter);
- }
-
- /**
* Method to post process returned flags from the {@link org.eclipse.pde.api.tools.internal.JavadocTagManager}
* @param tag the tag to process
* @param element the {@link IJavaElement} the tag will appear on
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/JavaUtils.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/JavaUtils.java
new file mode 100644
index 0000000..7e11e7c
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/JavaUtils.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) Aug 13, 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
+ *******************************************************************************/
+package org.eclipse.pde.api.tools.internal.util;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * A collection of utility methods to help with handling {@link org.eclipse.jdt.core.IJavaElement}s
+ * and {@link org.eclipse.jdt.core.dom.AST} elements
+ *
+ * @since 1.0.600
+ */
+public class JavaUtils {
+
+ private JavaUtils() {}
+
+ /**
+ * Returns if the given {@link IJavaElement} is externally visible
+ *
+ * @param element
+ * @return <code>true</code> if the given element is visible <code>false</code> otherwise
+ * @throws JavaModelException if a model lookup fails
+ */
+ public static final boolean isVisible(IJavaElement element) throws JavaModelException {
+ if(element != null) {
+ switch(element.getElementType()) {
+ case IJavaElement.FIELD:
+ case IJavaElement.METHOD: {
+ IMember member = (IMember) element;
+ int flags = member.getFlags();
+ IType type = member.getDeclaringType();
+ if(Flags.isPublic(flags) || Flags.isProtected(flags) || (type != null && type.isInterface())) {
+ return isVisible(type);
+ }
+ break;
+ }
+ case IJavaElement.TYPE: {
+ IType type = (IType) element;
+ int flags = type.getFlags();
+ if(type.isLocal() && !type.isAnonymous()) {
+ return false;
+ }
+ if(type.isMember()) {
+ if((Flags.isPublic(flags) && Flags.isStatic(flags)) || type.isInterface()) {
+ return isVisible(type.getDeclaringType());
+ }
+ }
+ else {
+ return Flags.isPublic(flags) || type.isInterface();
+ }
+ break;
+ }
+ default: {
+ break;
+ }
+
+ }
+ }
+ return false;
+ }
+}