List of usage examples for org.eclipse.jdt.core Signature getSimpleName
public static String getSimpleName(String name)
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 {/* w w w. j a v a 2 s . 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.fxgraph.ui.quickfix.FXGraphQuickfixProvider.java
License:Open Source License
@Fix(FXGraphJavaValidator.UNKNOWN_CONTROLLER_FIELD) public void fixAddControllerField(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add controller field", "Add a field of '" + issue.getData()[0] + "' to the controller '" + issue.getData()[1] + "'", null, new IModification() { @Override//from w w w.ja va 2s . c o m public void apply(IModificationContext context) throws Exception { IJavaProject p = context.getXtextDocument() .readOnly(new IUnitOfWork<IJavaProject, XtextResource>() { @Override public IJavaProject exec(XtextResource state) throws Exception { return provider.getJavaProject(state.getResourceSet()); } }); IType type = p.findType(issue.getData()[1]); String[][] resolvedType = type.resolveType("FXML"); if (resolvedType == null) { type.getCompilationUnit().createImport("javafx.fxml.FXML", null, new NullProgressMonitor()); } resolvedType = type.resolveType(Signature.getSimpleName(issue.getData()[2])); if (resolvedType == null) { type.getCompilationUnit().createImport(issue.getData()[2], null, new NullProgressMonitor()); } type.createField("@FXML " + Signature.getSimpleName(issue.getData()[2]) + " " + issue.getData()[0] + ";", null, true, new NullProgressMonitor()); } }); acceptor.accept(issue, "Remove id field", "Remove the id field from the element", null, new IModification() { @Override public void apply(IModificationContext context) throws Exception { IXtextDocument xtextDocument = context.getXtextDocument(); StringBuilder b = new StringBuilder(); int start = issue.getOffset(); while (!b.toString().startsWith("id")) { b.insert(0, xtextDocument.getChar(--start)); } xtextDocument.replace(start, (b + issue.getData()[0]).length(), ""); } }); }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.quickfix.FXGraphQuickfixProvider.java
License:Open Source License
@Fix(FXGraphJavaValidator.UNKNOWN_CONTROLLER_METHOD) public void fixAddControllerMethod(final Issue issue, IssueResolutionAcceptor acceptor) { final String methodName = issue.getData()[0]; final String controllerClass = issue.getData()[1]; final String argType = issue.getData()[2]; final String simpleArgType = Signature.getSimpleName(argType); acceptor.accept(issue, "Add controller method " + methodName + "(" + simpleArgType + ")", "Add a controller method '" + methodName + "(" + simpleArgType + ")' to controller '" + controllerClass + "'", null, new IModification() { @Override/*from w w w. j a v a 2 s. c om*/ public void apply(IModificationContext context) throws Exception { IJavaProject p = context.getXtextDocument() .readOnly(new IUnitOfWork<IJavaProject, XtextResource>() { @Override public IJavaProject exec(XtextResource state) throws Exception { return provider.getJavaProject(state.getResourceSet()); } }); IType type = p.findType(controllerClass); String[][] resolvedType = type.resolveType("FXML"); if (resolvedType == null) { type.getCompilationUnit().createImport("javafx.fxml.FXML", null, new NullProgressMonitor()); } resolvedType = type.resolveType(simpleArgType); if (resolvedType == null) { type.getCompilationUnit().createImport(argType, null, new NullProgressMonitor()); } type.createMethod("@FXML public void " + methodName + "(" + simpleArgType + " event) {}", null, true, new NullProgressMonitor()); } }); acceptor.accept(issue, "Add controller method " + methodName + "()", "Add a controller method '" + methodName + "()' to controller '" + controllerClass + "'", null, new IModification() { @Override public void apply(IModificationContext context) throws Exception { IJavaProject p = context.getXtextDocument() .readOnly(new IUnitOfWork<IJavaProject, XtextResource>() { @Override public IJavaProject exec(XtextResource state) throws Exception { return provider.getJavaProject(state.getResourceSet()); } }); IType type = p.findType(controllerClass); String[][] resolvedType = type.resolveType("FXML"); if (resolvedType == null) { type.getCompilationUnit().createImport("javafx.fxml.FXML", null, new NullProgressMonitor()); } type.createMethod("@FXML public void " + methodName + "() {}", null, true, new NullProgressMonitor()); } }); }
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 . ja v a2 s . c o m 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.model.internal.FXCollectionProperty.java
License:Open Source License
public String getCollectionTypeAsString(boolean fqn) { return fqn ? collectionTypeAsString : Signature.getSimpleName(collectionTypeAsString); }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXCollectionProperty.java
License:Open Source License
@Override public String getCollectionAsString() { return Signature.getSimpleName(genericType); }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXEnumProperty.java
License:Open Source License
@Override public String getEnumTypeAsString(boolean fqn) { return fqn ? enumTypeAsString : Signature.getSimpleName(enumTypeAsString); }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXObjectPoperty.java
License:Open Source License
@Override public String getElementTypeAsString(boolean fqn) { return fqn ? erasedFQNType : Signature.getSimpleName(erasedFQNType); }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
private StringBuffer internalGetSubstitutedTypeName(String typeSig, IMember context, boolean erasure, StringBuffer buf) throws JavaModelException { int sigKind = Signature.getTypeSignatureKind(typeSig); switch (sigKind) { case Signature.BASE_TYPE_SIGNATURE: return buf.append(Signature.toString(typeSig)); case Signature.ARRAY_TYPE_SIGNATURE: internalGetSubstitutedTypeName(Signature.getElementType(typeSig), context, erasure, buf); for (int i = Signature.getArrayCount(typeSig); i > 0; i--) { buf.append('[').append(']'); }//from ww w.j av a 2 s. c o m return buf; case Signature.CLASS_TYPE_SIGNATURE: { String erasureSig = Signature.getTypeErasure(typeSig); String erasureName = Signature.getSimpleName(Signature.toString(erasureSig)); char ch = erasureSig.charAt(0); if (ch == Signature.C_RESOLVED) { buf.append(erasureName); } else if (ch == Signature.C_UNRESOLVED) { // could be a type variable if (erasure) { buf.append(getVariableErasure(context, erasureName)); } else { buf.append(getVariableSubstitution(context, erasureName)); } } else { Assert.isTrue(false, "Unknown class type signature"); //$NON-NLS-1$ } if (!erasure) { String[] typeArguments = Signature.getTypeArguments(typeSig); if (typeArguments.length > 0) { buf.append('<'); for (int i = 0; i < typeArguments.length; i++) { if (i > 0) { buf.append(','); } internalGetSubstitutedTypeName(typeArguments[i], context, erasure, buf); } buf.append('>'); } } return buf; } case Signature.TYPE_VARIABLE_SIGNATURE: String varName = Signature.toString(typeSig); if (erasure) { return buf.append(getVariableErasure(context, varName)); } else { return buf.append(getVariableSubstitution(context, varName)); } case Signature.WILDCARD_TYPE_SIGNATURE: { buf.append('?'); char ch = typeSig.charAt(0); if (ch == Signature.C_STAR) { return buf; } else if (ch == Signature.C_EXTENDS) { buf.append(" extends "); //$NON-NLS-1$ } else { buf.append(" super "); //$NON-NLS-1$ } return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); } case Signature.CAPTURE_TYPE_SIGNATURE: return internalGetSubstitutedTypeName(typeSig.substring(1), context, erasure, buf); default: Assert.isTrue(false, "Unhandled type signature kind"); //$NON-NLS-1$ return buf; } }
From source file:at.bestsolution.fxide.jdt.editor.internal.MethodUtil.java
License:Open Source License
/** * Returns the simple erased name for a given type signature, possibly replacing type variables. * * @param signature the type signature//from ww w . ja va2 s. c om * @param typeVariables the Map<SimpleName, VariableName> * @return the simple erased name for signature */ private String computeSimpleTypeName(String signature, Map<String, char[]> typeVariables) { // method equality uses erased types String erasure = Signature.getTypeErasure(signature); erasure = erasure.replaceAll("/", "."); //$NON-NLS-1$//$NON-NLS-2$ String simpleName = Signature.getSimpleName(Signature.toString(erasure)); char[] typeVar = typeVariables.get(simpleName); if (typeVar != null) simpleName = String.valueOf(Signature.getSignatureSimpleName(typeVar)); return simpleName; }