Java Code Examples for org.eclipse.jdt.core.IType#getSuperclassTypeSignature()

The following examples show how to use org.eclipse.jdt.core.IType#getSuperclassTypeSignature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeVariableUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a type variable mapping from a subclass to a superclass.
 *
 * @param subtype
 *        the type representing the subclass
 * @param supertype
 *        the type representing the superclass
 * @return a type variable mapping. The mapping entries consist of simple type variable names.
 * @throws JavaModelException
 *         if the signature of one of the types involved could not be retrieved
 */
public static TypeVariableMaplet[] subTypeToSuperType(final IType subtype, final IType supertype) throws JavaModelException {
	Assert.isNotNull(subtype);
	Assert.isNotNull(supertype);

	final TypeVariableMaplet[] mapping= subTypeToInheritedType(subtype);
	if (mapping.length > 0) {
		final ITypeParameter[] range= supertype.getTypeParameters();
		if (range.length > 0) {
			final String signature= subtype.getSuperclassTypeSignature();
			if (signature != null) {
				final String[] domain= getVariableSignatures(signature);
				if (domain.length > 0)
					return composeMappings(mapping, signaturesToParameters(domain, range));
			}
		}
	}
	return mapping;
}
 
Example 2
Source File: TypeVariableUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a type variable mapping from a superclass to a subclass.
 *
 * @param supertype
 *        the type representing the superclass
 * @param subtype
 *        the type representing the subclass
 * @return a type variable mapping. The mapping entries consist of simple type variable names.
 * @throws JavaModelException
 *         if the signature of one of the types involved could not be retrieved
 */
public static TypeVariableMaplet[] superTypeToInheritedType(final IType supertype, final IType subtype) throws JavaModelException {
	Assert.isNotNull(subtype);
	Assert.isNotNull(supertype);

	final ITypeParameter[] domain= supertype.getTypeParameters();
	if (domain.length > 0) {
		final String signature= subtype.getSuperclassTypeSignature();
		if (signature != null) {
			final String[] range= getVariableSignatures(signature);
			if (range.length > 0)
				return parametersToSignatures(domain, range, true);
		}
	}
	return new TypeVariableMaplet[0];
}
 
Example 3
Source File: TypeProposalUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
static String[] getSuperTypeSignatures(IType subType, IType superType) throws JavaModelException {
	if (superType.isInterface()) {
		return subType.getSuperInterfaceTypeSignatures();
	} else {
		return new String[] {subType.getSuperclassTypeSignature()};
	}
}
 
Example 4
Source File: TypeVariableUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a type variable mapping from a subclass to a superclass.
 *
 * @param type
 *        the type representing the subclass class
 * @return a type variable mapping. The mapping entries consist of simple type variable names.
 * @throws JavaModelException
 *         if the signature of one of the types involved could not be retrieved
 */
public static TypeVariableMaplet[] subTypeToInheritedType(final IType type) throws JavaModelException {
	Assert.isNotNull(type);

	final ITypeParameter[] domain= type.getTypeParameters();
	if (domain.length > 0) {
		final String signature= type.getSuperclassTypeSignature();
		if (signature != null) {
			final String[] range= getVariableSignatures(signature);
			if (range.length > 0)
				return parametersToSignatures(domain, range, false);
		}
	}
	return new TypeVariableMaplet[0];
}
 
Example 5
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public IType next() {
	final IType c = this.current;
	if (c == null) {
		throw new NoSuchElementException();
	}
	final String name = c.getFullyQualifiedName();
	this.encountered.add(name);
	try {
		final String[] superTypes;
		if (this.isInterface) {
			superTypes = c.getSuperInterfaceTypeSignatures();
		} else {
			superTypes = new String[] {c.getSuperclassTypeSignature()};
		}
		for (final String signature : superTypes) {
			if (!Strings.isNullOrEmpty(signature)) {
				final String resolvedSignature = resolveType(c, signature);
				if (!Strings.isNullOrEmpty(resolvedSignature)) {
					this.queue.add(resolvedSignature);
				}
			}
		}
	} catch (Exception exception) {
		//
	}
	updateCurrent();
	return c;
}
 
Example 6
Source File: StubCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void appendTypeDeclaration(final IType type, final IProgressMonitor monitor) throws JavaModelException {
	try {
		monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 1);
		if (type.isAnnotation()) {
			appendFlags(type);
			fBuffer.append(" @interface "); //$NON-NLS-1$
			fBuffer.append(type.getElementName());
			fBuffer.append("{\n"); //$NON-NLS-1$
			appendMembers(type, new SubProgressMonitor(monitor, 1));
			fBuffer.append("}"); //$NON-NLS-1$
		} else if (type.isInterface()) {
			appendFlags(type);
			fBuffer.append(" interface "); //$NON-NLS-1$
			fBuffer.append(type.getElementName());
			appendTypeParameters(type.getTypeParameters());
			appendSuperInterfaceTypes(type);
			fBuffer.append("{\n"); //$NON-NLS-1$
			appendMembers(type, new SubProgressMonitor(monitor, 1));
			fBuffer.append("}"); //$NON-NLS-1$
		} else if (type.isClass()) {
			appendFlags(type);
			fBuffer.append(" class "); //$NON-NLS-1$
			fBuffer.append(type.getElementName());
			appendTypeParameters(type.getTypeParameters());
			final String signature= type.getSuperclassTypeSignature();
			if (signature != null) {
				fBuffer.append(" extends "); //$NON-NLS-1$
				fBuffer.append(Signature.toString(signature));
			}
			appendSuperInterfaceTypes(type);
			fBuffer.append("{\n"); //$NON-NLS-1$
			appendMembers(type, new SubProgressMonitor(monitor, 1));
			fBuffer.append("}"); //$NON-NLS-1$
		} else if (type.isEnum()) {
			appendFlags(type);
			fBuffer.append(" enum "); //$NON-NLS-1$
			fBuffer.append(type.getElementName());
			appendSuperInterfaceTypes(type);
			fBuffer.append("{\n"); //$NON-NLS-1$
			appendEnumConstants(type);
			appendMembers(type, new SubProgressMonitor(monitor, 1));
			fBuffer.append("}"); //$NON-NLS-1$
		}
	} finally {
		monitor.done();
	}
}
 
Example 7
Source File: CompilationUnitCompletion.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns the super interface signatures of <code>subType</code> if
 * <code>superType</code> is an interface, otherwise returns the super
 * type signature.
 *
 * @param subType the sub type signature
 * @param superType the super type signature
 * @return the super type signatures of <code>subType</code>
 * @throws JavaModelException if any java model operation fails
 */
private String[] getSuperTypeSignatures(IType subType, IType superType) throws JavaModelException {
	if (superType.isInterface())
		return subType.getSuperInterfaceTypeSignatures();
	else
		return new String[] {subType.getSuperclassTypeSignature()};
}
 
Example 8
Source File: LazyGenericTypeProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns the super interface signatures of <code>subType</code> if
 * <code>superType</code> is an interface, otherwise returns the super
 * type signature.
 *
 * @param subType the sub type signature
 * @param superType the super type signature
 * @return the super type signatures of <code>subType</code>
 * @throws JavaModelException if any java model operation fails
 */
private String[] getSuperTypeSignatures(IType subType, IType superType) throws JavaModelException {
	if (superType.isInterface())
		return subType.getSuperInterfaceTypeSignatures();
	else
		return new String[] {subType.getSuperclassTypeSignature()};
}