Java Code Examples for org.eclipse.jdt.core.IType#getClassFile()
The following examples show how to use
org.eclipse.jdt.core.IType#getClassFile() .
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: JavaBrowsingContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object[] getChildren(IType type) throws JavaModelException{ IParent parent; if (type.isBinary()) parent= type.getClassFile(); else { parent= type.getCompilationUnit(); } if (type.getDeclaringType() != null) return type.getChildren(); // Add import declarations IJavaElement[] members= parent.getChildren(); ArrayList<IJavaElement> tempResult= new ArrayList<IJavaElement>(members.length); for (int i= 0; i < members.length; i++) if ((members[i] instanceof IImportContainer)) tempResult.add(members[i]); tempResult.addAll(Arrays.asList(type.getChildren())); return tempResult.toArray(); }
Example 2
Source File: MatchLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected BinaryTypeBinding cacheBinaryType(IType type, IBinaryType binaryType) throws JavaModelException { IType enclosingType = type.getDeclaringType(); if (enclosingType != null) cacheBinaryType(enclosingType, null); // cache enclosing types first, so that binary type can be found in lookup enviroment if (binaryType == null) { ClassFile classFile = (ClassFile) type.getClassFile(); try { binaryType = getBinaryInfo(classFile, classFile.resource()); } catch (CoreException e) { if (e instanceof JavaModelException) { throw (JavaModelException) e; } else { throw new JavaModelException(e); } } } BinaryTypeBinding binding = this.lookupEnvironment.cacheBinaryType(binaryType, null /*no access restriction*/); if (binding == null) { // it was already cached as a result of a previous query char[][] compoundName = CharOperation.splitOn('.', type.getFullyQualifiedName().toCharArray()); ReferenceBinding referenceBinding = this.lookupEnvironment.getCachedType(compoundName); if (referenceBinding != null && (referenceBinding instanceof BinaryTypeBinding)) binding = (BinaryTypeBinding) referenceBinding; // if the binding could be found and if it comes from a binary type } return binding; }
Example 3
Source File: TypeDeclarationFromSuperclassExtractor.java From SparkBuilderGenerator with MIT License | 5 votes |
private Optional<CompilationUnit> getCompilationUnit(IType superClassType) { Optional<CompilationUnit> result = empty(); if (superClassType.getCompilationUnit() != null) { result = ofNullable(compilationUnitParser.parse(superClassType.getCompilationUnit())); } else if (superClassType.getClassFile() != null) { result = ofNullable(compilationUnitParser.parse(superClassType.getClassFile())); } return result; }
Example 4
Source File: CompletionsProvider.java From java-debug with Eclipse Public License 1.0 | 4 votes |
@Override public List<CompletionItem> codeComplete(StackFrame frame, String snippet, int line, int column) { List<CompletionItem> res = new ArrayList<CompletionItem>(); try { IType type = resolveType(frame); if (type != null) { ITypeRoot r = type.getCompilationUnit() != null ? type.getCompilationUnit() : type.getClassFile(); final int offset = JsonRpcHelpers.toOffset(r.getBuffer(), frame.location().lineNumber(), 0); CompletionProposalRequestor collector = new CompletionProposalRequestor(r, offset); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true); type.codeComplete(snippet.toCharArray(), offset, snippet.length(), null, null, null, frame.location().method().isStatic(), collector); List<org.eclipse.lsp4j.CompletionItem> items = collector.getCompletionItems(); if (items != null) { for (org.eclipse.lsp4j.CompletionItem lspItem : items) { res.add(convertFromLsp(lspItem)); } } } } catch (DebugException | CoreException e) { logger.log(Level.SEVERE, String.format("Failed to code complete because of %s", e.toString()), e); } return res; }