List of usage examples for org.eclipse.jdt.core.compiler CharOperation toString
final static public String toString(char[][] array)
From source file:com.codenvy.ide.ext.java.server.internal.core.SearchableEnvironment.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.env.INameEnvironment#findType(char[][]) *//* www. j ava 2 s . c o m*/ public NameEnvironmentAnswer findType(char[][] compoundTypeName) { if (compoundTypeName == null) return null; int length = compoundTypeName.length; if (length <= 1) { if (length == 0) return null; return find(new String(compoundTypeName[0]), null); } int lengthM1 = length - 1; char[][] packageName = new char[lengthM1][]; System.arraycopy(compoundTypeName, 0, packageName, 0, lengthM1); return find(new String(compoundTypeName[lengthM1]), CharOperation.toString(packageName)); }
From source file:com.codenvy.ide.ext.java.server.internal.core.SearchableEnvironment.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.env.INameEnvironment#findType(char[], char[][]) */// w w w. j ava 2 s . co m public NameEnvironmentAnswer findType(char[] name, char[][] packageName) { if (name == null) return null; return find(new String(name), packageName == null || packageName.length == 0 ? null : CharOperation.toString(packageName)); }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
static AnnotationBinding getAnnotation(AnnotationBinding[] annotations, String nameToFind) { if (annotations != null) { for (AnnotationBinding a : annotations) { ReferenceBinding annBinding = a.getAnnotationType(); String annName = CharOperation.toString(annBinding.compoundName); if (nameToFind.equals(annName)) { return a; }//from w ww . j a va 2s.co m } } return null; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
static AnnotationBinding getAnnotation(Annotation[] annotations, String nameToFind) { if (annotations != null) { for (Annotation a : annotations) { AnnotationBinding annBinding = a.getCompilerAnnotation(); if (annBinding != null) { String annName = CharOperation.toString(annBinding.getAnnotationType().compoundName); if (nameToFind.equals(annName)) { return annBinding; }//from w w w . ja va 2 s. c o m } } } return null; }
From source file:com.google.gwt.dev.javac.JsniChecker.java
License:Open Source License
static Set<String> getSuppressedWarnings(Annotation[] annotations) { if (annotations != null) { for (Annotation a : annotations) { if (SuppressWarnings.class.getName() .equals(CharOperation.toString(((ReferenceBinding) a.resolvedType).compoundName))) { for (MemberValuePair pair : a.memberValuePairs()) { if (String.valueOf(pair.name).equals("value")) { Expression valueExpr = pair.value; if (valueExpr instanceof StringLiteral) { // @SuppressWarnings("Foo") return Sets.create(((StringLiteral) valueExpr).constant.stringValue() .toLowerCase(Locale.ENGLISH)); } else if (valueExpr instanceof ArrayInitializer) { // @SuppressWarnings({ "Foo", "Bar"}) ArrayInitializer ai = (ArrayInitializer) valueExpr; String[] values = new String[ai.expressions.length]; for (int i = 0, j = values.length; i < j; i++) { values[i] = ((StringLiteral) ai.expressions[i]).constant.stringValue() .toLowerCase(Locale.ENGLISH); }/* ww w .j a v a2 s. c o m*/ return Sets.create(values); } else { throw new InternalCompilerException( "Unable to analyze SuppressWarnings annotation"); } } } } } } return Sets.create(); }
From source file:com.google.gwt.dev.javac.JsniReferenceResolver.java
License:Apache License
Set<String> getSuppressedWarnings(Annotation[] annotations) { if (annotations == null) { return ImmutableSet.of(); }//from w w w . j a v a2 s . c o m for (Annotation a : annotations) { if (!SuppressWarnings.class.getName() .equals(CharOperation.toString(((ReferenceBinding) a.resolvedType).compoundName))) { continue; } for (MemberValuePair pair : a.memberValuePairs()) { if (!String.valueOf(pair.name).equals("value")) { continue; } Expression valueExpr = pair.value; if (valueExpr instanceof StringLiteral) { // @SuppressWarnings("Foo") return ImmutableSet .of(((StringLiteral) valueExpr).constant.stringValue().toLowerCase(Locale.ROOT)); } else if (valueExpr instanceof ArrayInitializer) { // @SuppressWarnings({ "Foo", "Bar"}) ArrayInitializer ai = (ArrayInitializer) valueExpr; ImmutableSet.Builder valuesSetBuilder = ImmutableSet.builder(); for (int i = 0, j = ai.expressions.length; i < j; i++) { if ((ai.expressions[i]) instanceof StringLiteral) { StringLiteral expression = (StringLiteral) ai.expressions[i]; valuesSetBuilder.add(expression.constant.stringValue().toLowerCase(Locale.ROOT)); } else { suppressionAnnotationWarning(a, "Unable to analyze SuppressWarnings annotation, " + ai.expressions[i].toString() + " not a string constant."); } } return valuesSetBuilder.build(); } else { suppressionAnnotationWarning(a, "Unable to analyze SuppressWarnings annotation, " + valueExpr.toString() + " not a string constant."); } } } return ImmutableSet.of(); }
From source file:com.google.gwt.dev.jdt.FindDeferredBindingSitesVisitor.java
License:Open Source License
@Override public void endVisit(MessageSend messageSend, BlockScope scope) { if (messageSend.binding == null) { // Some sort of problem. return;/*w w w. j av a 2 s . c o m*/ } String methodName = String.valueOf(messageSend.selector); boolean rebindMagicMethod = methodName.equals(REBIND_MAGIC_METHOD); boolean asyncMagicMethod = methodName.equals(ASYNC_MAGIC_METHOD); if (!(rebindMagicMethod || asyncMagicMethod)) { // Not the create() method or the runAsync() method. return; } char[][] targetClass = messageSend.binding.declaringClass.compoundName; String targetClassName = CharOperation.toString(targetClass); if (!targetClassName.equals(MAGIC_CLASS)) { // Not being called on the Rebind class. return; } MessageSendSite site = new MessageSendSite(messageSend, scope); Expression[] args = messageSend.arguments; if (rebindMagicMethod) { if (args.length != 1) { reportRebindProblem(site, "GWT.create() should take exactly one argument"); return; } if (!(args[0] instanceof ClassLiteralAccess)) { reportRebindProblem(site, "Only class literals may be used as arguments to GWT.create()"); return; } } else { assert asyncMagicMethod; if (args.length != 1 && args.length != 2) { reportRebindProblem(site, "GWT.runAsync() should take one or two arguments"); return; } if (args.length == 2) { if (!(args[0] instanceof ClassLiteralAccess)) { reportRebindProblem(site, "Only class literals may be used to name a call to GWT.runAsync()"); return; } } } if (asyncMagicMethod) { runAsyncCalls.add(new MessageSendSite(messageSend, scope)); return; } ClassLiteralAccess cla = (ClassLiteralAccess) args[0]; String typeName = String.valueOf(cla.targetType.readableName()); if (!results.containsKey(typeName)) { results.put(typeName, site); } }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java
License:Open Source License
private JDTClass buildClassMirror(String name) { if (javaProject == null) { return null; }// w w w . j a va2 s .c o m try { LookupEnvironment theLookupEnvironment = getLookupEnvironment(); char[][] uncertainCompoundName = CharOperation.splitOn('.', name.toCharArray()); int numberOfParts = uncertainCompoundName.length; char[][] compoundName = null; IType type = null; for (int i = numberOfParts - 1; i > 0; i--) { char[][] triedPackageName = new char[0][]; for (int j = 0; j < i; j++) { triedPackageName = CharOperation.arrayConcat(triedPackageName, uncertainCompoundName[j]); } char[] triedClassName = new char[0]; for (int k = i; k < numberOfParts; k++) { triedClassName = CharOperation.concat(triedClassName, uncertainCompoundName[k], '$'); } ModelLoaderNameEnvironment nameEnvironment = getNameEnvironment(); type = nameEnvironment.findTypeInNameLookup(CharOperation.charToString(triedClassName), CharOperation.toString(triedPackageName)); if (type != null) { compoundName = CharOperation.arrayConcat(triedPackageName, triedClassName); break; } } if (type == null) { return null; } ReferenceBinding binding = toBinding(type, theLookupEnvironment, compoundName); if (binding != null) { return new JDTClass(binding, type); } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTMethod.java
License:Open Source License
private boolean ignoreMethodInAncestorSearch(MethodBinding methodBinding) { String name = CharOperation.charToString(methodBinding.selector); if (name.equals("finalize") || name.equals("clone")) { if (methodBinding.declaringClass != null && CharOperation .toString(methodBinding.declaringClass.compoundName).equals("java.lang.Object")) { return true; }// w ww . j a va2s .c om } // skip ignored methods too if (JDTUtils.hasAnnotation(methodBinding, AbstractModelLoader.CEYLON_IGNORE_ANNOTATION)) { return true; } return false; }
From source file:io.takari.maven.plugins.compile.jdt.CompilerJdt.java
License:Open Source License
private void writeClassFile(Resource<File> input, String relativeStringName, ClassFile classFile) throws IOException { final byte[] bytes = classFile.getBytes(); final File outputFile = new File(getOutputDirectory(), relativeStringName); final Output<File> output = context.associatedOutput(input, outputFile); boolean significantChange = digestClassFile(output, bytes); if (significantChange) { // find all sources that reference this type and put them into work queue strategy.addDependentsOf(CharOperation.toString(classFile.getCompoundName())); }/* w w w. j av a 2 s . c o m*/ final BufferedOutputStream os = new BufferedOutputStream(output.newOutputStream()); try { os.write(bytes); os.flush(); } finally { os.close(); } }