List of usage examples for org.eclipse.jdt.core IField getTypeSignature
String getTypeSignature() throws JavaModelException;
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 {/*from ww w . j a v a 2s . c o m*/ 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;/*from www .j a v a2 s . com*/ 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) {/*from w ww . j a va 2s .c o m*/ 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.efxclipse.tooling.model.internal.FXCtrlClass.java
License:Open Source License
private Map<String, IFXCtrlField> getLocalFields() { if (fields == null) { fields = new HashMap<String, IFXCtrlField>(); try {//from ww w. ja v a 2 s . c om for (IField f : type.getFields()) { boolean annotated = false; for (IAnnotation a : f.getAnnotations()) { if (a.getElementName().endsWith("FXML")) { annotated = true; break; } } if (annotated) { String erasedFQNType = Util.getFQNType((IType) f.getParent(), Signature.getTypeErasure(Signature.toString(f.getTypeSignature()))); FXCtrlField field = new FXCtrlField(this, f, erasedFQNType); fields.put(f.getElementName(), field); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return fields; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the style label for a field. Considers the F_* flags. * * @param field the element to render/* w ww. j a va 2s . c o m*/ * @param flags the rendering flags. Flags with names starting with 'F_' are considered. */ public void appendFieldLabel(IField field, long flags) { try { if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } fBuffer.append(' '); } // qualification if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) { appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } fBuffer.append(getElementName(field)); if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.DECL_STRING); if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); // } } // category if (getFlag(flags, JavaElementLabels.F_CATEGORY) && field.exists()) appendCategoryLabel(field, flags); // post qualification if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } } catch (JavaModelException e) { // TODO e.printStackTrace(); } }
From source file:cn.ieclipse.adt.ext.jdt.SourceAnalysis.java
License:Apache License
public static String getSQL(TypeMapping typeMapping, boolean format) { StringBuilder sb = new StringBuilder(); sb.append("create TABLE "); sb.append(typeMapping.getTable());//w ww. j a va2 s . c om sb.append(" ( "); if (format) { sb.append(LF); } try { IField[] fds = typeMapping.getType().getFields(); for (IField iField : fds) { String fieldType = iField.getTypeSignature(); IAnnotation nc = iField.getAnnotation("Column"); if (nc != null && nc.exists()) { ColumnMeta meta = new ColumnMeta(); meta.type = getColumnBySig(fieldType); IMemberValuePair[] mvps = nc.getMemberValuePairs(); for (IMemberValuePair imvp : mvps) { String mn = imvp.getMemberName(); Object mv = imvp.getValue(); if ("name".equals(mn)) { meta.name = (String) mv; } else if ("id".equals(mn)) { meta.id = (Boolean) mv; meta.haveId = true; } else if ("notNull".equals(mn)) { meta.notNull = (Boolean) mv; meta.haveNotNull = true; } else if ("defaultValue".equals(mn)) { meta.defaultValue = (String) mv; meta.haveDefaultValue = true; } } sb.append(meta.toSQL()); sb.append(", "); if (format) { sb.append(LF); } } // end if } // end for int len = sb.length() - 2; if (format) { len = len - LF.length(); } sb.delete(len, sb.length()); sb.append(")"); sb.append(LF); } catch (Exception e) { e.printStackTrace(); return ""; } return sb.toString(); }
From source file:com.aqua.wikiwizard.ObjectsJavaModel.java
License:Apache License
/** * Return a list of all object fields//from www . j a v a2s. c o m * @return * List of <code>Property</code> * @throws Exception */ public Property[] findAllObjectFields() throws Exception { ArrayList<Property> propertiesList = new ArrayList<Property>(); for (IJavaElement element : allChildrens) { if (element instanceof IField) { IField field = (IField) element; int flags = field.getFlags(); boolean addWiki = true; // We need: // 1. public fields that don't have @ignorewiki annotation // 2. private/protected fields that have @addwiki annotation if (Flags.isPublic(flags)) { if (isAnnotationFound(field, "ignorewiki")) { addWiki = false; } } else if (!isAnnotationFound(field, "addwiki")) { addWiki = false; } if (addWiki) { Property property = new Property(); property.name = field.getElementName(); property.documentation = JavaModelUtils.getJavaDoc(field); String rawCode = field.getSource(); property.defaultValue = "N/A"; // Try to get the initial value from the source code directly if (rawCode != null) { int equalsIndex = rawCode.lastIndexOf('='); if (equalsIndex != -1) { Matcher m = Pattern.compile("=\\s*(\\S+)[\\s|\\;]").matcher(rawCode); if (m.find(equalsIndex)) { property.defaultValue = m.group(1); } } } String fieldType = field.getTypeSignature(); property.type = Signature.toString(fieldType); propertiesList.add(property); } } } return propertiesList.toArray(new Property[propertiesList.size()]); }
From source file:com.codenvy.ide.ext.java.server.core.search.SearchPattern.java
License:Open Source License
/** * Returns a search pattern based on a given Java element. * The pattern is used to trigger the appropriate search, and can be parameterized as follows: * * @param element the Java element the search pattern is based on * @param limitTo determines the nature of the expected matches * <ul>/* w w w . j a va 2 s.co m*/ * <li>{@link IJavaSearchConstants#DECLARATIONS DECLARATIONS}: will search declarations matching * with the corresponding element. In case the element is a method, declarations of matching * methods in sub-types will also be found, allowing to find declarations of abstract methods, etc. * Some additional flags may be specified while searching declaration: * <ul> * <li>{@link IJavaSearchConstants#IGNORE_DECLARING_TYPE IGNORE_DECLARING_TYPE}: declaring type will be ignored * during the search.<br> * For example using following test case: * <pre> * class A { A method() { return null; } } * class B extends A { B method() { return null; } } * class C { A method() { return null; } } * </pre> * search for <code>method</code> declaration with this flag * will return 2 matches: in A and in C * </li> * <li>{@link IJavaSearchConstants#IGNORE_RETURN_TYPE IGNORE_RETURN_TYPE}: return type will be ignored * during the search.<br> * Using same example, search for <code>method</code> declaration with this flag * will return 2 matches: in A and in B. * </li> * </ul> * Note that these two flags may be combined and both declaring and return types can be ignored * during the search. Then, using same example, search for <code>method</code> declaration * with these 2 flags will return 3 matches: in A, in B and in C * </li> * <li>{@link IJavaSearchConstants#REFERENCES REFERENCES}: will search references to the given element.</li> * <li>{@link IJavaSearchConstants#ALL_OCCURRENCES ALL_OCCURRENCES}: will search for either declarations or * references as specified above. * </li> * <li>All other fine grain constants defined in the <b>limitTo</b> category * of the {@link IJavaSearchConstants} are also accepted nature: * <table border=0> * <tr> * <th align=left>Fine grain constant * <th align=left>Meaning * <tr> * <td>{@link IJavaSearchConstants#FIELD_DECLARATION_TYPE_REFERENCE FIELD_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a field declaration. * <tr> * <td>{@link IJavaSearchConstants#LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a local variable declaration. * <tr> * <td>{@link IJavaSearchConstants#PARAMETER_DECLARATION_TYPE_REFERENCE PARAMETER_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used as the type of a method parameter declaration. * <tr> * <td>{@link IJavaSearchConstants#SUPERTYPE_TYPE_REFERENCE SUPERTYPE_TYPE_REFERENCE} * <td>Return only type references used as a super type or as a super interface. * <tr> * <td>{@link IJavaSearchConstants#THROWS_CLAUSE_TYPE_REFERENCE THROWS_CLAUSE_TYPE_REFERENCE} * <td>Return only type references used in a throws clause. * <tr> * <td>{@link IJavaSearchConstants#CAST_TYPE_REFERENCE CAST_TYPE_REFERENCE} * <td>Return only type references used in a cast expression. * <tr> * <td>{@link IJavaSearchConstants#CATCH_TYPE_REFERENCE CATCH_TYPE_REFERENCE} * <td>Return only type references used in a catch header. * <tr> * <td>{@link IJavaSearchConstants#CLASS_INSTANCE_CREATION_TYPE_REFERENCE CLASS_INSTANCE_CREATION_TYPE_REFERENCE} * <td>Return only type references used in class instance creation. * <tr> * <td>{@link IJavaSearchConstants#RETURN_TYPE_REFERENCE RETURN_TYPE_REFERENCE} * <td>Return only type references used as a method return type. * <tr> * <td>{@link IJavaSearchConstants#IMPORT_DECLARATION_TYPE_REFERENCE IMPORT_DECLARATION_TYPE_REFERENCE} * <td>Return only type references used in an import declaration. * <tr> * <td>{@link IJavaSearchConstants#ANNOTATION_TYPE_REFERENCE ANNOTATION_TYPE_REFERENCE} * <td>Return only type references used as an annotation. * <tr> * <td>{@link IJavaSearchConstants#TYPE_ARGUMENT_TYPE_REFERENCE TYPE_ARGUMENT_TYPE_REFERENCE} * <td>Return only type references used as a type argument in a parameterized type or a parameterized method. * <tr> * <td>{@link IJavaSearchConstants#TYPE_VARIABLE_BOUND_TYPE_REFERENCE TYPE_VARIABLE_BOUND_TYPE_REFERENCE} * <td>Return only type references used as a type variable bound. * <tr> * <td>{@link IJavaSearchConstants#WILDCARD_BOUND_TYPE_REFERENCE WILDCARD_BOUND_TYPE_REFERENCE} * <td>Return only type references used as a wildcard bound. * <tr> * <td>{@link IJavaSearchConstants#INSTANCEOF_TYPE_REFERENCE INSTANCEOF_TYPE_REFERENCE} * <td>Return only type references used as a type of an <code>instanceof</code> expression. * <tr> * <td>{@link IJavaSearchConstants#SUPER_REFERENCE SUPER_REFERENCE} * <td>Return only super field accesses or super method invocations (e.g. using the <code>super</code> qualifier). * <tr> * <td>{@link IJavaSearchConstants#QUALIFIED_REFERENCE QUALIFIED_REFERENCE} * <td>Return only qualified field accesses or qualified method invocations. * <tr> * <td>{@link IJavaSearchConstants#THIS_REFERENCE THIS_REFERENCE} * <td>Return only primary field accesses or primary method invocations (e.g. using the <code>this</code> qualifier). * <tr> * <td>{@link IJavaSearchConstants#IMPLICIT_THIS_REFERENCE IMPLICIT_THIS_REFERENCE} * <td>Return only field accesses or method invocations without any qualification. * </table> * </li> * </ul> * @param matchRule one of the following match rules: * <ul> * <li>{@link #R_EXACT_MATCH}</li> * <li>{@link #R_PREFIX_MATCH}</li> * <li>{@link #R_PATTERN_MATCH}</li> * <li>{@link #R_CAMELCASE_MATCH}</li> * <li>{@link #R_CAMELCASE_SAME_PART_COUNT_MATCH}</li> * </ul> * , which may be also combined with one of the following flags: * <ul> * <li>{@link #R_CASE_SENSITIVE}</li> * <li>{@link #R_ERASURE_MATCH}</li> * <li>{@link #R_EQUIVALENT_MATCH}</li> * </ul> * For example, * <ul> * <li>{@link #R_EXACT_MATCH} | {@link #R_CASE_SENSITIVE}: if an exact * and case sensitive match is requested,</li> * <li>{@link #R_PREFIX_MATCH} if a case insensitive prefix match is requested</li> * <li>{@link #R_EXACT_MATCH} | {@link #R_ERASURE_MATCH}: if a case * insensitive and erasure match is requested.</li> * </ul> * Note that {@link #R_ERASURE_MATCH} or {@link #R_EQUIVALENT_MATCH} has no effect * on non-generic types/methods search. * <p> * Note also that default behavior for generic types/methods search is to find exact matches. * @return a search pattern for a Java element or <code>null</code> if the given element is ill-formed * @since 3.1 */ public static SearchPattern createPattern(IJavaElement element, int limitTo, int matchRule) { SearchPattern searchPattern = null; int lastDot; boolean ignoreDeclaringType = false; boolean ignoreReturnType = false; int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); if (maskedLimitTo == IJavaSearchConstants.DECLARATIONS || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) { ignoreDeclaringType = (limitTo & IJavaSearchConstants.IGNORE_DECLARING_TYPE) != 0; ignoreReturnType = (limitTo & IJavaSearchConstants.IGNORE_RETURN_TYPE) != 0; } if ((matchRule = validateMatchRule(null, matchRule)) == -1) { return null; } char[] declaringSimpleName = null; char[] declaringQualification = null; switch (element.getElementType()) { case IJavaElement.FIELD: IField field = (IField) element; if (!ignoreDeclaringType) { IType declaringClass = field.getDeclaringType(); declaringSimpleName = declaringClass.getElementName().toCharArray(); declaringQualification = declaringClass.getPackageFragment().getElementName().toCharArray(); char[][] enclosingNames = enclosingTypeNames(declaringClass); if (enclosingNames.length > 0) { declaringQualification = CharOperation.concat(declaringQualification, CharOperation.concatWith(enclosingNames, '.'), '.'); } } char[] name = field.getElementName().toCharArray(); char[] typeSimpleName = null; char[] typeQualification = null; String typeSignature = null; if (!ignoreReturnType) { try { typeSignature = field.getTypeSignature(); char[] signature = typeSignature.toCharArray(); char[] typeErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(typeErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', typeErasure)) == -1) { typeSimpleName = typeErasure; } else { typeSimpleName = CharOperation.subarray(typeErasure, lastDot + 1, typeErasure.length); typeQualification = CharOperation.subarray(typeErasure, 0, lastDot); if (!field.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) typeQualification = CharOperation.concat(IIndexConstants.ONE_STAR, typeQualification); } } } catch (JavaModelException e) { return null; } } // Create field pattern searchPattern = new FieldPattern(name, declaringQualification, declaringSimpleName, typeQualification, typeSimpleName, typeSignature, limitTo, matchRule); break; case IJavaElement.IMPORT_DECLARATION: String elementName = element.getElementName(); lastDot = elementName.lastIndexOf('.'); if (lastDot == -1) return null; // invalid import declaration IImportDeclaration importDecl = (IImportDeclaration) element; if (importDecl.isOnDemand()) { searchPattern = createPackagePattern(elementName.substring(0, lastDot), maskedLimitTo, matchRule); } else { searchPattern = createTypePattern(elementName.substring(lastDot + 1).toCharArray(), elementName.substring(0, lastDot).toCharArray(), null, null, null, maskedLimitTo, matchRule); } break; case IJavaElement.LOCAL_VARIABLE: LocalVariable localVar = (LocalVariable) element; searchPattern = new LocalVariablePattern(localVar, limitTo, matchRule); break; case IJavaElement.TYPE_PARAMETER: ITypeParameter typeParam = (ITypeParameter) element; boolean findParamDeclarations = true; boolean findParamReferences = true; switch (maskedLimitTo) { case IJavaSearchConstants.DECLARATIONS: findParamReferences = false; break; case IJavaSearchConstants.REFERENCES: findParamDeclarations = false; break; } searchPattern = new TypeParameterPattern(findParamDeclarations, findParamReferences, typeParam, matchRule); break; case IJavaElement.METHOD: IMethod method = (IMethod) element; boolean isConstructor; try { isConstructor = method.isConstructor(); } catch (JavaModelException e) { return null; } IType declaringClass = method.getDeclaringType(); if (ignoreDeclaringType) { if (isConstructor) declaringSimpleName = declaringClass.getElementName().toCharArray(); } else { declaringSimpleName = declaringClass.getElementName().toCharArray(); declaringQualification = declaringClass.getPackageFragment().getElementName().toCharArray(); char[][] enclosingNames = enclosingTypeNames(declaringClass); if (enclosingNames.length > 0) { declaringQualification = CharOperation.concat(declaringQualification, CharOperation.concatWith(enclosingNames, '.'), '.'); } } char[] selector = method.getElementName().toCharArray(); char[] returnSimpleName = null; char[] returnQualification = null; String returnSignature = null; if (!ignoreReturnType) { try { returnSignature = method.getReturnType(); char[] signature = returnSignature.toCharArray(); char[] returnErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(returnErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', returnErasure)) == -1) { returnSimpleName = returnErasure; } else { returnSimpleName = CharOperation.subarray(returnErasure, lastDot + 1, returnErasure.length); returnQualification = CharOperation.subarray(returnErasure, 0, lastDot); if (!method.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) CharOperation.concat(IIndexConstants.ONE_STAR, returnQualification); } } } catch (JavaModelException e) { return null; } } String[] parameterTypes = method.getParameterTypes(); int paramCount = parameterTypes.length; char[][] parameterSimpleNames = new char[paramCount][]; char[][] parameterQualifications = new char[paramCount][]; String[] parameterSignatures = new String[paramCount]; for (int i = 0; i < paramCount; i++) { parameterSignatures[i] = parameterTypes[i]; char[] signature = parameterSignatures[i].toCharArray(); char[] paramErasure = Signature.toCharArray(Signature.getTypeErasure(signature)); CharOperation.replace(paramErasure, '$', '.'); if ((lastDot = CharOperation.lastIndexOf('.', paramErasure)) == -1) { parameterSimpleNames[i] = paramErasure; parameterQualifications[i] = null; } else { parameterSimpleNames[i] = CharOperation.subarray(paramErasure, lastDot + 1, paramErasure.length); parameterQualifications[i] = CharOperation.subarray(paramErasure, 0, lastDot); if (!method.isBinary()) { // prefix with a '*' as the full qualification could be bigger (because of an import) CharOperation.concat(IIndexConstants.ONE_STAR, parameterQualifications[i]); } } } // Create method/constructor pattern if (isConstructor) { searchPattern = new ConstructorPattern(declaringSimpleName, declaringQualification, parameterQualifications, parameterSimpleNames, parameterSignatures, method, limitTo, matchRule); } else { searchPattern = new MethodPattern(selector, declaringQualification, declaringSimpleName, returnQualification, returnSimpleName, returnSignature, parameterQualifications, parameterSimpleNames, parameterSignatures, method, limitTo, matchRule); } break; case IJavaElement.TYPE: IType type = (IType) element; searchPattern = createTypePattern(type.getElementName().toCharArray(), type.getPackageFragment().getElementName().toCharArray(), ignoreDeclaringType ? null : enclosingTypeNames(type), null, type, maskedLimitTo, matchRule); break; case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.PACKAGE_FRAGMENT: searchPattern = createPackagePattern(element.getElementName(), maskedLimitTo, matchRule); break; } if (searchPattern != null) MatchLocator.setFocus(searchPattern, element); return searchPattern; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java
License:Open Source License
private FieldDeclaration convert(IField field, IType type) throws JavaModelException { TypeReference typeReference = createTypeReference(field.getTypeSignature()); if (typeReference == null) return null; FieldDeclaration fieldDeclaration = new FieldDeclaration(); fieldDeclaration.name = field.getElementName().toCharArray(); fieldDeclaration.type = typeReference; fieldDeclaration.modifiers = field.getFlags(); return fieldDeclaration; }
From source file:com.codenvy.ide.ext.java.server.javadoc.JavaElementLabelComposer.java
License:Open Source License
/** * Appends the style label for a field. Considers the F_* flags. * * @param field the element to render/* w w w .j av a2 s .c om*/ * @param flags the rendering flags. Flags with names starting with 'F_' are considered. */ public void appendFieldLabel(IField field, long flags) { try { if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } fBuffer.append(' '); } // qualification if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) { appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } fBuffer.append(getElementName(field)); if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.DECL_STRING); if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) { appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags); } else { appendTypeSignatureLabel(field, field.getTypeSignature(), flags); } if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); } } // category if (getFlag(flags, JavaElementLabels.F_CATEGORY) && field.exists()) appendCategoryLabel(field, flags); // post qualification if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendTypeLabel(field.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } } catch (JavaModelException e) { LOG.error(e.getMessage(), e); // NotExistsException will not reach this point } }