Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome lanneluc2002-04-22 12:39:30 +0000
committerJerome lanneluc2002-04-22 12:39:30 +0000
commite7c40dbc434529a8379a830b9ae4ab2c74d0fc13 (patch)
tree9e150a5ba687acad5262a76c011fd17373a0f495
parentb8967fb259bc4122f2d9f6e6be8973482d84bd2f (diff)
downloadeclipse.jdt.core-e7c40dbc434529a8379a830b9ae4ab2c74d0fc13.tar.gz
eclipse.jdt.core-e7c40dbc434529a8379a830b9ae4ab2c74d0fc13.tar.xz
eclipse.jdt.core-e7c40dbc434529a8379a830b9ae4ab2c74d0fc13.zip
*** empty log message ***
-rw-r--r--org.eclipse.jdt.core/buildnotes_jdt-core.html8
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java29
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java24
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/Util.java159
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java18
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java20
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java55
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java18
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java24
9 files changed, 175 insertions, 180 deletions
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index be3a0a7ac3..2728971436 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -15,6 +15,14 @@ Eclipse SDK Build 200204? - ?th April 2002
<h2>
What's new in this drop</h2>
<ul>
+ <li>Java model API additions:
+ <ul>
+ <li><code>IMethod.isMainMethod()</code></li>
+ <li><code>IMethod.isSimilar(IMethod)</code></li>
+ <li><code>IType.getFullyQualifiedName(char)</code></li>
+ <li><code>IType.getTypeQualifiedName(char)</code></li>
+ </ul>
+ </li>
<li> JavaModelOperations now guarantee the JavaModel is up to date when notifying the Java model change listeners. In particular,
a builder running after the Java builder will be able to query the Java model with respect to the changes introduced through Java model
operations (except for index queries). This was never guaranteed in 1.0, but indirectly occurred due to the fact that the previous Java
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java
index f3b6029f54..62f6eeb8ae 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMethod.java
@@ -98,4 +98,33 @@ String getSignature() throws JavaModelException;
* exception occurs while accessing its corresponding resource.
*/
boolean isConstructor() throws JavaModelException;
+/**
+ * Returns whether this method is a main method.
+ * It is a main method if:
+ * <ul>
+ * <li>its name is equal to <code>"main"</code></li>
+ * <li>its return type is <code>void</code></li>
+ * <li>it is <code>static</code> and <code>public</code></li>
+ * <li>it defines one paramater whose type's simple name is </code>String[]</code></li>
+ * </ul>
+ *
+ * @exception JavaModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @since 2.0
+ */
+boolean isMainMethod() throws JavaModelException;
+/**
+ * Returns whether this method is similar to the given method.
+ * Two methods are similar if:
+ * <ul>
+ * <li>their element names are equal</li>
+ * <li>they have the same number of parameters</li>
+ * <li>the simple names of their parameters are equal</li>
+ * <ul>
+ * This is a handle-only method.
+ *
+ * @see Signature#getSimpleName
+ * @since 2.0
+ */
+boolean isSimilar(IMethod method);
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java
index 0db7f33378..eab847b9f8 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IType.java
@@ -191,6 +191,17 @@ IField[] getFields() throws JavaModelException;
*/
String getFullyQualifiedName();
/**
+ * Returns the fully qualified name of this type,
+ * including qualification for any containing types and packages.
+ * This is the name of the package, followed by <code>'.'</code>,
+ * followed by the type-qualified name using the <code>enclosingTypeSeparator<code>.
+ * This is a handle-only method.
+ *
+ * @see IType#getTypeQualifiedName(char)
+ * @since 2.0
+ */
+String getFullyQualifiedName(char enclosingTypeSeparator);
+/**
* Returns the Initializer with the specified position relative to
* the order they are defined in the source.
* Numbering starts at 1 (i.e. the first occurrence is occurrence 1, not occurrence 0).
@@ -272,6 +283,19 @@ IType getType(String name) ;
*/
String getTypeQualifiedName();
/**
+ * Returns the type-qualified name of this type,
+ * including qualification for any enclosing types,
+ * but not including package qualification.
+ * For source types, this consists of the simple names of
+ * any enclosing types, separated by the <code>enclosingTypeSeparator</code>,
+ * followed by the simple name of this type.
+ * For binary types, this is the name of the class file without the ".class" suffix.
+ * This is a handle-only method.
+ *
+ * @since 2.0
+ */
+String getTypeQualifiedName(char enclosingTypeSeparator);
+/**
* Returns the immediate member types declared by this type.
* The results are listed in the order in which they appear in the source or class file.
*
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/Util.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/Util.java
deleted file mode 100644
index e1a0ccf93d..0000000000
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/Util.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/**********************************************************************
-Copyright (c) 2002 IBM Corp. and others.
-All rights reserved.   This program and the accompanying materials
-are made available under the terms of the Common Public License v0.5
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/cpl-v05.html
-Contributors:
-    JDT UI team - Initial implementation copied from internal code in plugin org.eclipse.jdt.ui
-**********************************************************************/
-package org.eclipse.jdt.core.util;
-
-import org.eclipse.jdt.core.Flags;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-
-/**
- * Utility methods for the Java Model.
- */
-public class Util {
-/**
- * Concatenates two names. Uses a dot for separation.
- * If one of the strings is empty, then the other one is retuned and
- * no dot is append.
- * <code>null</code> is interpreted as an empty string, so if both strings
- * are <code>null</code>, the an empty string is returned.
- */
-public static String concatenateName(String name1, String name2) {
- if (name1 == null || name1.length() == 0) {
- return name2 == null ? "" : name2; //$NON-NLS-1$
- } else {
- if (name2 == null || name2.length() == 0) {
- return name1;
- } else {
- return name1 + "." + name2; //$NON-NLS-1$
- }
- }
-}
-/**
- * Returns the fully qualified name of the given type using '.' as separators.
- * This is a replace for IType.getFullyQualifiedTypeName
- * which uses '$' as separators. As '$' is also a valid character in an id
- * this is ambiguous. JavaCore PR: 1GCFUNT
- */
-public static String getFullyQualifiedName(IType type) {
- StringBuffer buf= new StringBuffer();
- String packName= type.getPackageFragment().getElementName();
- if (packName.length() > 0) {
- buf.append(packName);
- buf.append('.');
- }
- getTypeQualifiedName(type, buf);
- return buf.toString();
-}
-/**
- * Resolves a type name in the context of the declaring type.
- * @param refTypeSig the type name in signature notation (for example 'QVector')
- * this can also be an array type, but dimensions will be ignored.
- * @param declaringType the context for resolving (type where the reference was made in)
- * @return returns the fully qualified type name or build-in-type name.
- * if a unresoved type couldn't be resolved null is returned
- */
-public static String getResolvedTypeName(String refTypeSig, IType declaringType) throws JavaModelException {
- int arrayCount= Signature.getArrayCount(refTypeSig);
- char type= refTypeSig.charAt(arrayCount);
- if (type == Signature.C_UNRESOLVED) {
- int semi= refTypeSig.indexOf(Signature.C_SEMICOLON, arrayCount + 1);
- if (semi == -1) {
- throw new IllegalArgumentException();
- }
- String name= refTypeSig.substring(arrayCount + 1, semi);
-
- String[][] resolvedNames= declaringType.resolveType(name);
- if (resolvedNames != null && resolvedNames.length > 0) {
- return concatenateName(resolvedNames[0][0], resolvedNames[0][1]);
- }
- return null;
- } else {
- return Signature.toString(refTypeSig.substring(arrayCount));
- }
-}
-/**
- * Returns the fully qualified name of a type's container. (package name or enclosing type name)
- */
-public static String getTypeContainerName(IType type) {
- IType outerType= type.getDeclaringType();
- if (outerType != null) {
- return getFullyQualifiedName(outerType);
- } else {
- return type.getPackageFragment().getElementName();
- }
-}
-private static void getTypeQualifiedName(IType type, StringBuffer buf) {
- IType outerType= type.getDeclaringType();
- if (outerType != null) {
- getTypeQualifiedName(outerType, buf);
- buf.append('.');
- }
- buf.append(type.getElementName());
-}
-/**
- * Returns the qualified type name of the given type using '.' as separators.
- * This is a replace for IType.getTypeQualifiedName()
- * which uses '$' as separators. As '$' is also a valid character in an id
- * this is ambiguous. JavaCore PR: 1GCFUNT
- */
-public static String getTypeQualifiedName(IType type) {
- StringBuffer buf= new StringBuffer();
- getTypeQualifiedName(type, buf);
- return buf.toString();
-}
-/**
- * Tests if a method is a main method. Does not resolve the parameter types.
- * Method must exist.
- */
-public static boolean isMainMethod(IMethod method) throws JavaModelException {
- if ("main".equals(method.getElementName()) && Signature.SIG_VOID.equals(method.getReturnType())) { //$NON-NLS-1$
- int flags= method.getFlags();
- if (Flags.isStatic(flags) && Flags.isPublic(flags)) {
- String[] paramTypes= method.getParameterTypes();
- if (paramTypes.length == 1) {
- String name= Signature.toString(paramTypes[0]);
- return "String[]".equals(Signature.getSimpleName(name)); //$NON-NLS-1$
- }
- }
- }
- return false;
-}
-/**
- * Tests if a method equals to the given signature.
- * Parameter types are only compared by the simple name, no resolving for
- * the fully qualified type name is done. Constructors are only compared by
- * parameters, not the name.
- * @param Name of the method
- * @param The type signatures of the parameters e.g. <code>{"QString;","I"}</code>
- * @param Specifies if the method is a constructor
- * @return Returns <code>true</code> if the method has the given name and parameter types and constructor state.
- */
-public static boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod curr) throws JavaModelException {
- if (isConstructor || name.equals(curr.getElementName())) {
- if (isConstructor == curr.isConstructor()) {
- String[] currParamTypes= curr.getParameterTypes();
- if (paramTypes.length == currParamTypes.length) {
- for (int i= 0; i < paramTypes.length; i++) {
- String t1= Signature.getSimpleName(Signature.toString(paramTypes[i]));
- String t2= Signature.getSimpleName(Signature.toString(currParamTypes[i]));
- if (!t1.equals(t2)) {
- return false;
- }
- }
- return true;
- }
- }
- }
- return false;
-}
-}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
index bb11caf21e..a97c10e71f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryMethod.java
@@ -226,6 +226,24 @@ public boolean isConstructor() throws JavaModelException {
return info.isConstructor();
}
/**
+ * @see IMethod#isMainMethod()
+ */
+public boolean isMainMethod() throws JavaModelException {
+ return this.isMainMethod(this);
+}
+
+/**
+ * @see IMethod#isSimilar(IMethod)
+ */
+public boolean isSimilar(IMethod method) {
+ return
+ this.areSimilarMethods(
+ this.getElementName(), this.getParameterTypes(),
+ method.getElementName(), method.getParameterTypes(),
+ null);
+}
+
+/**
*/
public String readableName() {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
index df789777fc..f157c3a35f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
@@ -206,11 +206,17 @@ public int getFlags() throws JavaModelException {
* @see IType
*/
public String getFullyQualifiedName() {
+ return this.getFullyQualifiedName('$');
+}
+/**
+ * @see IType(char)
+ */
+public String getFullyQualifiedName(char enclosingTypeSeparator) {
String packageName = getPackageFragment().getElementName();
if (packageName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
- return getTypeQualifiedName();
+ return getTypeQualifiedName(enclosingTypeSeparator);
}
- return packageName + '.' + getTypeQualifiedName();
+ return packageName + '.' + getTypeQualifiedName(enclosingTypeSeparator);
}
/**
* @see IType
@@ -299,15 +305,21 @@ public IType getType(String name) {
* @see IType#getTypeQualifiedName
*/
public String getTypeQualifiedName() {
+ return this.getTypeQualifiedName('$');
+}
+/**
+ * @see IType#getTypeQualifiedName(char)
+ */
+public String getTypeQualifiedName(char enclosingTypeSeparator) {
if (fParent.getElementType() == IJavaElement.CLASS_FILE) {
String name= fParent.getElementName();
return name.substring(0,name.lastIndexOf('.'));
}
if (fParent.getElementType() == IJavaElement.TYPE) {
if (Character.isDigit(fName.charAt(0))) {
- return ((IType) fParent).getTypeQualifiedName();
+ return ((IType) fParent).getTypeQualifiedName(enclosingTypeSeparator);
} else {
- return ((IType) fParent).getTypeQualifiedName() + '$' + fName;
+ return ((IType) fParent).getTypeQualifiedName(enclosingTypeSeparator) + enclosingTypeSeparator + fName;
}
}
Assert.isTrue(false); // should not be reachable
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java
index 014df7614b..51260c9f5a 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Member.java
@@ -21,6 +21,29 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
protected Member(int type, IJavaElement parent, String name) {
super(type, parent, name);
}
+protected boolean areSimilarMethods(
+ String name1, String[] params1,
+ String name2, String[] params2,
+ String[] simpleNames1) {
+
+ if (name1.equals(name2)) {
+ int params1Length = params1.length;
+ if (params1Length == params2.length) {
+ for (int i = 0; i < params1Length; i++) {
+ String simpleName1 =
+ simpleNames1 == null ?
+ Signature.getSimpleName(Signature.toString(params1[i])) :
+ simpleNames1[i];
+ String simpleName2 = Signature.getSimpleName(Signature.toString(params2[i]));
+ if (!simpleName1.equals(simpleName2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
/**
* Converts a field constant from the compiler's representation
* to the Java Model constant representation (Number or String).
@@ -76,18 +99,13 @@ protected IMethod[] findMethods(IMethod method, IMethod[] methods) {
ArrayList list = new ArrayList();
next: for (int i = 0, length = methods.length; i < length; i++) {
IMethod existingMethod = methods[i];
- if (existingMethod.getElementName().equals(elementName)) {
- String[] existingParams = existingMethod.getParameterTypes();
- int existingParamLength = existingParams.length;
- if (existingParamLength == paramLength) {
- for (int j = 0; j < paramLength; j++) {
- String simpleName = Signature.getSimpleName(Signature.toString(existingParams[j]));
- if (!simpleNames[j].equals(simpleName)) {
- continue next;
- }
- }
- list.add(existingMethod);
- }
+ if (this.areSimilarMethods(
+ elementName,
+ parameters,
+ existingMethod.getElementName(),
+ existingMethod.getParameterTypes(),
+ simpleNames)) {
+ list.add(existingMethod);
}
}
int size = list.size();
@@ -141,6 +159,19 @@ public ISourceRange getNameRange() throws JavaModelException {
public boolean isBinary() {
return false;
}
+protected boolean isMainMethod(IMethod method) throws JavaModelException {
+ if ("main".equals(method.getElementName()) && Signature.SIG_VOID.equals(method.getReturnType())) { //$NON-NLS-1$
+ int flags= method.getFlags();
+ if (Flags.isStatic(flags) && Flags.isPublic(flags)) {
+ String[] paramTypes= method.getParameterTypes();
+ if (paramTypes.length == 1) {
+ String name= Signature.toString(paramTypes[0]);
+ return "String[]".equals(Signature.getSimpleName(name)); //$NON-NLS-1$
+ }
+ }
+ }
+ return false;
+}
/**
* @see IJavaElement
*/
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java
index 664b4dba2a..b0d27b867b 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMethod.java
@@ -134,6 +134,24 @@ public boolean isConstructor() throws JavaModelException {
return info.isConstructor();
}
/**
+ * @see IMethod#isMainMethod()
+ */
+public boolean isMainMethod() throws JavaModelException {
+ return this.isMainMethod(this);
+}
+
+/**
+ * @see IMethod#isSimilar(IMethod)
+ */
+public boolean isSimilar(IMethod method) {
+ return
+ this.areSimilarMethods(
+ this.getElementName(), this.getParameterTypes(),
+ method.getElementName(), method.getParameterTypes(),
+ null);
+}
+
+/**
*/
public String readableName() {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java
index 4cf84938ac..c002bc9709 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java
@@ -162,15 +162,22 @@ public IField[] getFields() throws JavaModelException {
return array;
}
/**
- * @see IType
+ * @see IType#getFullyQualifiedName
*/
public String getFullyQualifiedName() {
+ return this.getFullyQualifiedName('$');
+}
+/**
+ * @see IType#getFullyQualifiedName(char)
+ */
+public String getFullyQualifiedName(char enclosingTypeSeparator) {
String packageName = getPackageFragment().getElementName();
if (packageName.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
- return getTypeQualifiedName();
+ return getTypeQualifiedName(enclosingTypeSeparator);
}
- return packageName + '.' + getTypeQualifiedName();
+ return packageName + '.' + getTypeQualifiedName(enclosingTypeSeparator);
}
+
/**
* @see IType
*/
@@ -250,15 +257,22 @@ public IType getType(String name) {
return new SourceType(this, name);
}
/**
- * @see IType
+ * @see IType#getTypeQualifiedName
*/
public String getTypeQualifiedName() {
+ return this.getTypeQualifiedName('$');
+}
+/**
+ * @see IType#getTypeQualifiedName(char)
+ */
+public String getTypeQualifiedName(char enclosingTypeSeparator) {
if (fParent.getElementType() == IJavaElement.COMPILATION_UNIT) {
return fName;
} else {
- return ((IType) fParent).getTypeQualifiedName() + '$' + fName;
+ return ((IType) fParent).getTypeQualifiedName(enclosingTypeSeparator) + enclosingTypeSeparator + fName;
}
}
+
/**
* @see IType
*/

Back to the top