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

The following examples show how to use org.eclipse.jdt.core.IType#getTypeQualifiedName() . 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: GenerateToStringHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static CheckToStringResponse checkToStringStatus(IType type) {
	CheckToStringResponse response = new CheckToStringResponse();
	if (type == null) {
		return response;
	}

	try {
		RefactoringASTParser astParser = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL);
		CompilationUnit astRoot = astParser.parse(type.getCompilationUnit(), true);
		ITypeBinding typeBinding = ASTNodes.getTypeBinding(astRoot, type);
		if (typeBinding != null) {
			response.type = type.getTypeQualifiedName();
			response.fields = JdtDomModels.getDeclaredFields(typeBinding, false);
			response.exists = Stream.of(typeBinding.getDeclaredMethods()).anyMatch(method -> method.getName().equals(METHODNAME_TOSTRING) && method.getParameterTypes().length == 0);
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Failed to check toString status", e);
	}

	return response;
}
 
Example 2
Source File: HashCodeEqualsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static CheckHashCodeEqualsResponse checkHashCodeEqualsStatus(IType type) {
	CheckHashCodeEqualsResponse response = new CheckHashCodeEqualsResponse();
	if (type == null) {
		return response;
	}
	try {
		RefactoringASTParser astParser = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL);
		CompilationUnit astRoot = astParser.parse(type.getCompilationUnit(), true);
		ITypeBinding typeBinding = ASTNodes.getTypeBinding(astRoot, type);
		if (typeBinding != null) {
			response.type = type.getTypeQualifiedName();
			response.fields = JdtDomModels.getDeclaredFields(typeBinding, false);
			response.existingMethods = findExistingMethods(typeBinding);
		}
	} catch (JavaModelException e) {
		JavaLanguageServerPlugin.logException("Check hashCode and equals status", e);
	}
	return response;
}
 
Example 3
Source File: MatchLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an IType from the given simple top level type name.
 */
protected IType createTypeHandle(String simpleTypeName) {
	Openable openable = this.currentPossibleMatch.openable;
	if (openable instanceof CompilationUnit)
		return ((CompilationUnit) openable).getType(simpleTypeName);

	IType binaryType = ((ClassFile) openable).getType();
	String binaryTypeQualifiedName = binaryType.getTypeQualifiedName();
	if (simpleTypeName.equals(binaryTypeQualifiedName))
		return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type

	// type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791)
	String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName;
	IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class);
	return classFile.getType();
}
 
Example 4
Source File: NamedMember.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected String getKey(IType type, boolean forceOpen) throws JavaModelException {
	StringBuffer key = new StringBuffer();
	key.append('L');
	String packageName = type.getPackageFragment().getElementName();
	key.append(packageName.replace('.', '/'));
	if (packageName.length() > 0)
		key.append('/');
	String typeQualifiedName = type.getTypeQualifiedName('$');
	ICompilationUnit cu = (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (cu != null) {
		String cuName = cu.getElementName();
		String mainTypeName = cuName.substring(0, cuName.lastIndexOf('.'));
		int end = typeQualifiedName.indexOf('$');
		if (end == -1)
			end = typeQualifiedName.length();
		String topLevelTypeName = typeQualifiedName.substring(0, end);
		if (!mainTypeName.equals(topLevelTypeName)) {
			key.append(mainTypeName);
			key.append('~');
		}
	}
	key.append(typeQualifiedName);
	key.append(';');
	return key.toString();
}
 
Example 5
Source File: JavaDocLocations.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void appendTypePath(IType type, StringBuffer buf) {
	IPackageFragment pack = type.getPackageFragment();
	String packPath = pack.getElementName().replace('.', '/');
	String typePath = type.getTypeQualifiedName('.');
	if (packPath.length() > 0) {
		buf.append(packPath);
		buf.append('/');
	}
	buf.append(typePath);
	buf.append(".html"); //$NON-NLS-1$
}
 
Example 6
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void appendTypePath(IType type, StringBuffer buf) {
	IPackageFragment pack= type.getPackageFragment();
	String packPath= pack.getElementName().replace('.', '/');
	String typePath= type.getTypeQualifiedName('.');
	if (packPath.length() > 0) {
		buf.append(packPath);
		buf.append('/');
	}
	buf.append(typePath);
	buf.append(".html"); //$NON-NLS-1$
}
 
Example 7
Source File: OverrideMethodsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static OverridableMethodsResponse listOverridableMethods(CodeActionParams params) {
	IType type = SourceAssistProcessor.getSelectionType(params);
	String typeName = type == null ? "" : type.getTypeQualifiedName();
	List<OverridableMethod> methods = OverrideMethodsOperation.listOverridableMethods(type);
	return new OverridableMethodsResponse(typeName, methods);
}
 
Example 8
Source File: LogicalType.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public LogicalType(IType type) {
  logicalPackage = new LogicalPackage(
      type.getPackageFragment().getElementName());
  typeName = type.getTypeQualifiedName('$');
}