List of usage examples for org.eclipse.jdt.core IJavaElement TYPE
int TYPE
To view the source code for org.eclipse.jdt.core IJavaElement TYPE.
Click Source Link
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.contentassist.FXGraphProposalProvider.java
License:Open Source License
@Override public void completeConstValueProperty_Field(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model instanceof ConstValueProperty) { ConstValueProperty constProp = (ConstValueProperty) model; IJavaProject javaProject = projectProvider.getJavaProject(constProp.eResource().getResourceSet()); try {//ww w . ja v a2s . c om IType type = javaProject.findType(constProp.getType().getQualifiedName()); List<IField> fields = new ArrayList<IField>(); collectStaticFields(fields, type); for (IField f : fields) { StyledString s = new StyledString(f.getElementName() + " : " + Signature.getSimpleName(Signature.toString(f.getTypeSignature()))); String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName(); s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER); ICompletionProposal prop = createCompletionProposal(f.getElementName(), s, IconKeys.getIcon(IconKeys.FIELD_KEY), context); acceptor.accept(prop); } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java
License:Open Source License
@Override protected void addAttributeValueProposals(final ContentAssistRequest contentAssistRequest, final CompletionProposalInvocationContext context) { IDOMNode n = (IDOMNode) contentAssistRequest.getNode(); if (Character.isUpperCase(n.getNodeName().charAt(0))) { NamedNodeMap m = n.getAttributes(); IDOMNode attribute = null;// w ww . ja v a 2s . c om for (int i = 0; i < m.getLength(); i++) { IDOMNode a = (IDOMNode) m.item(i); if (a.contains(contentAssistRequest.getStartOffset())) { attribute = a; } } if (attribute != null) { if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) { if ("constant".equals(attribute.getLocalName())) { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { try { List<IField> fields = new ArrayList<IField>(); collectStaticFields(fields, type); for (IField f : fields) { StyledString s = new StyledString(f.getElementName() + " : " + Signature.getSimpleName(Signature.toString(f.getTypeSignature()))); String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName(); s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + f.getElementName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if ("controller".equals(attribute.getLocalName())) { IJavaProject jproject = findProject(contentAssistRequest); char[] typeName = null; char[] packageName = null; if (!contentAssistRequest.getMatchString().isEmpty()) { if (contentAssistRequest.getMatchString().startsWith("\"")) { typeName = contentAssistRequest.getMatchString().substring(1).toCharArray(); } else { typeName = contentAssistRequest.getMatchString().toCharArray(); } } IJavaSearchScope searchScope = SearchEngine .createJavaSearchScope(new IJavaElement[] { jproject }); SearchEngine searchEngine = new SearchEngine(); try { searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName, SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH, IJavaSearchConstants.TYPE, searchScope, new TypeNameRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { String sPackageName = new String(packageName); int priority = PRIORITY_LOWER_1; if (sPackageName.startsWith("com.sun")) { priority -= 10; } StyledString s = new StyledString(new String(simpleTypeName)); s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER); FXMLCompletionProposal cp = createProposal(contentAssistRequest, context, "\"" + sPackageName + "." + new String(simpleTypeName), s, IconKeys.getIcon(IconKeys.CLASS_KEY), CLASS_ATTRIBUTE_MATCHER); if (cp != null) { contentAssistRequest.addProposal(cp); } } }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor()); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if (attribute.getNodeName().contains(".")) { String[] parts = attribute.getNodeName().split("\\."); IType type = findType(parts[0], contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getStaticProperty(parts[1]); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } } } } else { IType type = findType(n.getNodeName(), contentAssistRequest, context); if (type != null) { IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type); if (fxClass != null) { IFXProperty p = fxClass.getProperty(attribute.getNodeName()); if (p instanceof IFXPrimitiveProperty) { createAttributeValuePrimitiveProposals(contentAssistRequest, context, (IFXPrimitiveProperty) p); } else if (p instanceof IFXEnumProperty) { createAttributeValueEnumProposals(contentAssistRequest, context, (IFXEnumProperty) p); } else if (p instanceof IFXObjectProperty) { createAttributeValueObjectProposals(contentAssistRequest, context, (IFXObjectProperty) p); } else if (p instanceof IFXEventHandlerProperty) { createAttributeValueEventHandlerProposals(contentAssistRequest, context, (IFXEventHandlerProperty) p); } } } } } } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.FXBeanJavaCompletionProposalComputer.java
License:Open Source License
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {// w w w . j a v a 2 s . c om if (context instanceof JavaContentAssistInvocationContext && false) { JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context; CompletionContext completionContext = javaContext.getCoreContext(); IJavaElement enclosingElement = null; if (completionContext.isExtended()) { enclosingElement = completionContext.getEnclosingElement(); } else { try { enclosingElement = javaContext.getCompilationUnit() .getElementAt(context.getInvocationOffset() + 1); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } List<ICompletionProposal> l = new ArrayList<ICompletionProposal>(); if (enclosingElement != null) { IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE); if (type == null) { return l; } try { IField[] fields = type.getFields(); IMethod[] methods = type.getMethods(); int offset = context.getInvocationOffset() - 3; if (offset > 0) { String prefix = context.getDocument().get(offset, 3); IType propType = type.getJavaProject().findType("javafx.beans.property.Property"); IType writableType = type.getJavaProject().findType("javafx.beans.value.WritableValue"); // Primitives IType booleanType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyBooleanProperty"); IType doubleType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyDoubleProperty"); IType floatType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyFloatProperty"); IType intType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyIntegerProperty"); IType longType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyLongProperty"); IType stringType = type.getJavaProject() .findType("javafx.beans.property.ReadOnlyStringProperty"); for (int i = 0; i < fields.length; i++) { IField curr = fields[i]; if (!Flags.isEnum(curr.getFlags())) { IType fieldType = toType(type, curr.getTypeSignature()); if (fieldType != null) { if (assignable(fieldType, propType)) { if ("set".equals(prefix)) { if (assignable(fieldType, writableType)) { String setterName = NamingConventions.suggestSetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, setterName)) { StyledString s = new StyledString(setterName + "(" + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType) + ") : void"); s.append(" - Setter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(setterName, s)); } } } else if (Character.isWhitespace(prefix.charAt(0)) && prefix.endsWith("is")) { if (assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); getterName = "is" + getterName.substring(3); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : boolean"); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s)); } } } else if ("get".equals(prefix)) { if (!assignable(fieldType, booleanType)) { String getterName = NamingConventions.suggestGetterName( type.getJavaProject(), curr.getElementName(), curr.getFlags(), false, null); if (!hasMethod(methods, getterName)) { StyledString s = new StyledString(getterName + "() : " + toValue(fieldType, booleanType, doubleType, floatType, intType, longType, stringType)); s.append(" - Getter for '" + curr.getElementName() + "'", StyledString.QUALIFIER_STYLER); l.add(new CompletionProposalImpl(getterName, s)); } } } else if (Character.isWhitespace(prefix.charAt(2))) { String propertyName = curr.getElementName() + "Property"; if (!hasMethod(methods, propertyName)) { StyledString s = new StyledString(propertyName); l.add(new CompletionProposalImpl(propertyName, s)); } } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return l; } return Collections.emptyList(); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
private static boolean isEnumTypeFinal(IMember member) throws JavaModelException { if (!(isEnum(member) && member.getElementType() == IJavaElement.TYPE)) return false; // An enum type is implicitly final unless it contains at least one enum constant that has a class body. IJavaElement[] children = member.getChildren(); for (IJavaElement child : children) { if (isEnumConstant((IMember) child) && ((IField) child).getChildren().length != 0) { return false; }//from www . j av a 2 s . c om } return true; }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
private static boolean isNestedInterfaceOrAnnotation(IMember member) throws JavaModelException { return member.getElementType() == IJavaElement.TYPE && member.getDeclaringType() != null && JavaModelUtil.isInterfaceOrAnnotation((IType) member); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
private static boolean isAnonymousType(IMember member) throws JavaModelException { return member.getElementType() == IJavaElement.TYPE && ((IType) member).isAnonymous(); }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the label for a Java element with the flags as defined by this class. * * @param element the element to render//from www . ja va2 s. c om * @param flags the rendering flags. */ public void appendElementLabel(IJavaElement element, long flags) { int type = element.getElementType(); IPackageFragmentRoot root = null; if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) root = JavaModelUtil.getPackageFragmentRoot(element); if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) { appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); fBuffer.append(JavaElementLabels.CONCAT_STRING); } switch (type) { case IJavaElement.METHOD: appendMethodLabel((IMethod) element, flags); break; case IJavaElement.FIELD: appendFieldLabel((IField) element, flags); break; case IJavaElement.LOCAL_VARIABLE: appendLocalVariableLabel((ILocalVariable) element, flags); break; case IJavaElement.TYPE_PARAMETER: appendTypeParameterLabel((ITypeParameter) element, flags); break; case IJavaElement.INITIALIZER: appendInitializerLabel((IInitializer) element, flags); break; case IJavaElement.TYPE: appendTypeLabel((IType) element, flags); break; case IJavaElement.CLASS_FILE: appendClassFileLabel((IClassFile) element, flags); break; case IJavaElement.COMPILATION_UNIT: appendCompilationUnitLabel((ICompilationUnit) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT: appendPackageFragmentLabel((IPackageFragment) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags); break; case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.PACKAGE_DECLARATION: appendDeclarationLabel(element, flags); break; case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: fBuffer.append(element.getElementName()); break; default: fBuffer.append(element.getElementName()); } if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } }
From source file:bndtools.internal.testcaseselection.JavaSearchScopeTestCaseLister.java
License:Open Source License
@Override public String[] getTestCases(boolean includeNonSource, ITestCaseFilter filter) throws TestCaseListException { final List<IJavaElement> testCaseList = new LinkedList<IJavaElement>(); search(Arrays.asList("junit.framework.TestCase", "junit.framework.TestSuite"), testCaseList); //$NON-NLS-1$ //$NON-NLS-2$ // Remove non-source and excludes Set<String> testCaseNames = new LinkedHashSet<String>(); for (Iterator<IJavaElement> iter = testCaseList.iterator(); iter.hasNext();) { boolean omit = false; IJavaElement element = iter.next(); try {/*from ww w . ja v a 2 s .co m*/ IType type = (IType) element.getAncestor(IJavaElement.TYPE); if (Flags.isAbstract(type.getFlags())) { omit = true; } if (!includeNonSource) { IPackageFragment pkgFragment = (IPackageFragment) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pkgFragment.getCompilationUnits().length == 0) { omit = true; } } } catch (JavaModelException e) { throw new TestCaseListException(e); } String className = getClassName(element); if (filter != null && !filter.select(className)) { omit = true; } if (!omit) { testCaseNames.add(className); } } return testCaseNames.toArray(new String[0]); }
From source file:byke.DependencyAnalysis.java
License:Open Source License
private IJavaElement enclosingTypeOf(IMember element) { return element.getAncestor(IJavaElement.TYPE); }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
public void search(ISearchRequestor requestor, QuerySpecification query, IProgressMonitor monitor) throws CoreException { if (debug.isDebugging()) debug.trace(String.format("Query: %s", query)); //$NON-NLS-1$ // we only look for straight references switch (query.getLimitTo()) { case IJavaSearchConstants.REFERENCES: case IJavaSearchConstants.ALL_OCCURRENCES: break;// w w w . j a v a 2s . c o m default: return; } // we only look for types and methods if (query instanceof ElementQuerySpecification) { searchElement = ((ElementQuerySpecification) query).getElement(); switch (searchElement.getElementType()) { case IJavaElement.TYPE: case IJavaElement.METHOD: break; default: return; } } else { String pattern = ((PatternQuerySpecification) query).getPattern(); boolean ignoreMethodParams = false; searchFor = ((PatternQuerySpecification) query).getSearchFor(); switch (searchFor) { case IJavaSearchConstants.UNKNOWN: case IJavaSearchConstants.METHOD: int leftParen = pattern.lastIndexOf('('); int rightParen = pattern.indexOf(')'); ignoreMethodParams = leftParen == -1 || rightParen == -1 || leftParen >= rightParen; // no break case IJavaSearchConstants.TYPE: case IJavaSearchConstants.CLASS: case IJavaSearchConstants.CLASS_AND_INTERFACE: case IJavaSearchConstants.CLASS_AND_ENUM: case IJavaSearchConstants.INTERFACE: case IJavaSearchConstants.INTERFACE_AND_ANNOTATION: break; default: return; } // searchPattern = PatternConstructor.createPattern(pattern, ((PatternQuerySpecification) query).isCaseSensitive()); int matchMode = getMatchMode(pattern) | SearchPattern.R_ERASURE_MATCH; if (((PatternQuerySpecification) query).isCaseSensitive()) matchMode |= SearchPattern.R_CASE_SENSITIVE; searchPattern = new SearchPatternDescriptor(pattern, matchMode, ignoreMethodParams); } HashSet<IPath> scope = new HashSet<IPath>(); for (IPath path : query.getScope().enclosingProjectsAndJars()) { scope.add(path); } if (scope.isEmpty()) return; this.requestor = requestor; // look through all active bundles IPluginModelBase[] wsModels = PluginRegistry.getWorkspaceModels(); IPluginModelBase[] exModels = PluginRegistry.getExternalModels(); monitor.beginTask(Messages.DescriptorQueryParticipant_taskName, wsModels.length + exModels.length); try { // workspace models for (IPluginModelBase model : wsModels) { if (monitor.isCanceled()) throw new OperationCanceledException(); if (!model.isEnabled() || !(model instanceof IBundlePluginModelBase)) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$ continue; } IProject project = model.getUnderlyingResource().getProject(); if (!scope.contains(project.getFullPath())) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Project out of scope: %s", project.getName())); //$NON-NLS-1$ continue; } // we can only search in Java bundle projects (for now) if (!project.hasNature(JavaCore.NATURE_ID)) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-Java project: %s", project.getName())); //$NON-NLS-1$ continue; } PDEModelUtility.modifyModel(new ModelModification(project) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { if (model instanceof IBundlePluginModelBase) searchBundle((IBundlePluginModelBase) model, monitor); } }, new SubProgressMonitor(monitor, 1)); } // external models SearchablePluginsManager spm = PDECore.getDefault().getSearchablePluginsManager(); IJavaProject javaProject = spm.getProxyProject(); if (javaProject == null || !javaProject.exists() || !javaProject.isOpen()) { monitor.worked(exModels.length); if (debug.isDebugging()) debug.trace("External Plug-in Search project inaccessible!"); //$NON-NLS-1$ return; } for (IPluginModelBase model : exModels) { if (monitor.isCanceled()) throw new OperationCanceledException(); BundleDescription bd; if (!model.isEnabled() || (bd = model.getBundleDescription()) == null) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-bundle model: %s", model)); //$NON-NLS-1$ continue; } // check scope ArrayList<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(); ClasspathUtilCore.addLibraries(model, cpEntries); ArrayList<IPath> cpEntryPaths = new ArrayList<IPath>(cpEntries.size()); for (IClasspathEntry cpEntry : cpEntries) { cpEntryPaths.add(cpEntry.getPath()); } cpEntryPaths.retainAll(scope); if (cpEntryPaths.isEmpty()) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("External bundle out of scope: %s", model.getInstallLocation())); //$NON-NLS-1$ continue; } if (!spm.isInJavaSearch(bd.getSymbolicName())) { monitor.worked(1); if (debug.isDebugging()) debug.trace(String.format("Non-searchable external model: %s", bd.getSymbolicName())); //$NON-NLS-1$ continue; } searchBundle(model, javaProject, new SubProgressMonitor(monitor, 1)); } } finally { monitor.done(); } }